Pytorch v1.0.0 Release Notes

Release Date: 2018-12-07 // over 5 years ago
  • Table of Contents

    • Highlights
      • JIT
      • Brand New Distributed Package
      • C++ Frontend [API Unstable]
      • Torch Hub
    • ๐Ÿ’ฅ Breaking Changes
    • โž• Additional New Features
      • N-dimensional empty tensors
      • New Operators
      • New Distributions
      • Sparse API Improvements
      • Additions to existing Operators and Distributions
    • ๐Ÿ› Bug Fixes
      • Serious
      • Backwards Compatibility
      • Correctness
      • Error checking
      • Miscellaneous
    • Other Improvements
    • ๐Ÿ—„ Deprecations
      • CPP Extensions
    • ๐ŸŽ Performance
    • ๐Ÿ“š Documentation Improvements

    Highlights

    JIT

    The JIT is a set of compiler tools for bridging the gap between research in PyTorch
    โšก๏ธ and production. It allows for the creation of models that can run without a dependency on the Python interpreter and which can be optimized more aggressively. Using program annotations existing models can be transformed into Torch Script, a subset of Python that PyTorch can run directly. Model code is still valid Python code and can be debugged with the standard Python toolchain. PyTorch 1.0 provides two ways in which you can make your existing code compatible with the JIT, using torch.jit.trace or torch.jit.script. Once annotated, Torch Script code can be aggressively optimized and it can be serialized for later use in our new C++ API, which doesn't depend on Python at all.

    # Write in Python, run [email protected] RNN(x, h, W\_h, U\_h, b\_h): y = [] for t in range(x.size(0)): h = torch.tanh(x[t] @ W\_h + h @ U\_h + b\_h) y += [h] return torch.stack(y), h
    

    As an example, see a tutorial on deploying a seq2seq model,
    ๐Ÿ“„ loading an exported model from C++, or browse the docs.

    ๐Ÿ“ฆ Brand New Distributed Package

    ๐Ÿ“ฆ The torch.distributed package and torch.nn.parallel.DistributedDataParallel module are backed by a brand new re-designed distributed library. The main highlights of the new library are:

    • ๐Ÿ†• New torch.distributed is performance driven and operates entirely asynchronously for all backends: Gloo, NCCL, and MPI.
    • ๐ŸŽ Significant Distributed Data Parallel performance improvements especially for hosts with slower networks such as ethernet-based hosts
    • โž• Adds async support for all distributed collective operations in the torch.distributed package.
    • ๐Ÿ“„ Adds the following CPU ops in the Gloo backend: send, recv, reduce, all_gather, gather, scatter
    • โž• Adds barrier op in the NCCL backend
    • ๐Ÿ“„ Adds new_group support for the NCCL backend

    C++ Frontend [API Unstable].

    ๐ŸŽ The C++ frontend is a pure C++ interface to the PyTorch backend that follows the API and architecture of the established Python frontend. It is intended to enable research in high performance, low latency and bare metal C++ applications. It provides equivalents to torch.nn, torch.optim, torch.data and other components of the Python frontend. Here is a minimal side-by-side comparison of the two language frontends:

    Python C++
    import torch

    model = torch.nn.Linear(5, 1) โšก๏ธ optimizer = torch.optim.SGD(model.parameters(), lr=0.1) prediction = model.forward(torch.randn(3, 5)) loss = torch.nn.functional.mse_loss(prediction, torch.ones(3, 1)) loss.backward() โšก๏ธ optimizer.step() | #include <torch/torch.h>

    torch::nn::Linear model(5, 1); torch::optim::SGD optimizer(model->parameters(), /lr=/0.1); torch::Tensor prediction = model->forward(torch::randn({3, 5})); auto loss = torch::mse_loss(prediction, torch::ones({3, 1})); loss.backward(); โšก๏ธ optimizer.step(); |

    We are releasing the C++ frontend marked as "API Unstable" as part of PyTorch 1.0. This means it is ready to be used for your research application, but still has some open construction sites that will stabilize over the next couple of releases. Some parts of the API may undergo breaking changes during this time.

    ๐Ÿ“š See https://pytorch.org/cppdocs for detailed documentation on the greater PyTorch C++ API as well as the C++ frontend.

    Torch Hub

    Torch Hub is a pre-trained model repository designed to facilitate research reproducibility.

    ๐Ÿ‘€ Torch Hub supports publishing pre-trained models (model definitions and pre-trained weights) to a github repository using a simple hubconf.py file; see hubconf for resnet models in pytorch/vision as an example. Once published, users can load the pre-trained models using the torch.hub.load API.

    ๐Ÿ“š For more details, see the torch.hub documentation. Expect a more-detailed blog post introducing Torch Hub in the near future!

    ๐Ÿ’ฅ Breaking Changes

    • ๐Ÿ“„ Indexing a 0-dimensional tensor will now throw an error instead of warn. Use tensor.item() instead. (#11679).
    • ๐Ÿšš torch.legacy is removed. (#11823).
    • torch.masked_copy_ is removed, use torch.masked_scatter_ instead. (#9817).
    • Operations that result in 0 element tensors may return changed shapes.

      • Before: all 0 element tensors would collapse to shape (0,). For example, torch.nonzero is documented to return a tensor of shape (n,z), where n = number of nonzero elements and z = dimensions of the input, but would always return a Tensor of shape _(0,) when no nonzero elements existed.
      • Now: Operations return their documented shape.

      Previously: all 0-element tensors are collapsed to shape (0,)

      torch.nonzero(torch.zeros(2, 3)) tensor([], dtype=torch.int64)

      Now, proper shape is returned

      torch.nonzero(torch.zeros(2, 3)) tensor([], size=(0, 2), dtype=torch.int64)

    • Sparse tensor indices and values shape invariants are changed to be more consistent in the case of 0-element tensors. See link for more details. (#9279).

    • ๐Ÿšš torch.distributed: the TCP backend is removed, we recommend to use Gloo and MPI backends for CPU collectives and NCCL backend for GPU collectives.

    • Some inter-type operations (e.g. *) between torch.Tensors and NumPy arrays will now favor dispatching to the torch variant. This may result in different return types. (#9651).

    • ๐Ÿšš Implicit numpy conversion no longer implicitly moves a tensor to CPU. Therefore, you may have to explicitly move a CUDA tensor to CPU (tensor.to('cpu')) before an implicit conversion. (#10553).

    • torch.randint now defaults to using dtype torch.int64 rather than the default floating-point dtype. (#11040).

    • ๐Ÿ“„ torch.tensor function with a Tensor argument now returns a detached Tensor (i.e. a Tensor where grad_fn is None). This more closely aligns with the intent of the function, which is to return a Tensor with copied data and no history. (#11061,
      #11815).

    • torch.nn.functional.multilabel_soft_margin_loss now returns Tensors of shape (N,) instead of (N, C) to match the behavior of torch.nn.MultiMarginLoss. In addition, it is more numerically stable.
      (#9965).

    • The result type of a torch.float16 0-dimensional tensor and a integer is now torch.float16 (was torch.float32 or torch.float64 depending on the dtype of the integer). (#11941).

    • ๐Ÿ“„ Dirichlet and Categorical distributions no longer accept scalar parameters. (#11589).

    • ๐Ÿ“„ CPP Extensions: Deprecated factory functions that accept a type as the first argument and a size as a second argument argument have been removed. Instead, use the new-style factory functions that accept the size as the first argument and TensorOptions as the last argument. For example, replace your call to at::ones(torch::CPU(at::kFloat)), {2, 3}) with torch::ones({2, 3}, at::kCPU). This applies to the following functions:

      • arange, empty, eye, full, linspace, logspace, ones, rand, randint, randn, randperm, range, zeros.
    • 0๏ธโƒฃ torch.potrf renamed to torch.cholesky. It has a new default (upper=False) (#12699).

    • ๐Ÿ“‡ Renamed elementwise_mean to mean for loss reduction functions (#13419)

    โž• Additional New Features

    N-dimensional empty tensors

    • Tensors with 0 elements can now have an arbitrary number of dimensions and support indexing and other torch operations; previously, 0 element tensors were limited to shape (0,). (#9947). Example:

      torch.empty((0, 2, 4, 0), dtype=torch.float64) tensor([], size=(0, 2, 4, 0), dtype=torch.float64)

    ๐Ÿ†• New Operators

    ๐Ÿ†• New Distributions

    ๐Ÿ“œ Sparse API Improvements

    โž• Additions to existing Operators and Distributions

    ๐Ÿ› Bug Fixes

    Serious

    Backwards Compatibility

    • torch.nn.Module load_from_state_dict now correctly handles 1-dimensional vs 0-dimensional tensors saved from 0.3 versions. (#9781).
    • ๐Ÿ›  Fix RuntimeError: storages don't support slicing when loading models saved with PyTorch 0.3. (#11314).
    • ๐Ÿ›  BCEWithLogitsLoss: fixed an issue with legacy reduce parameter. (#12689).

    Correctness

    • ๐Ÿ“„ torch.nn.Dropout fused kernel could change parameters in eval mode. (#10621).
    • ๐Ÿ›  torch.unbind backwards has been fixed. (#9995).
    • ๐Ÿ›  Fix a bug in sparse matrix-matrix multiplication when a sparse matrix is coalesced then transposed. (#10496).
    • ๐Ÿ“„ torch.bernoulli now handles out= parameters correctly, handles expanded tensors correctly, and has corrected argument validity checks on CPU. (#10273).
    • ๐Ÿ“„ torch.Tensor.normal_ could give incorrect results on CPU. (#10846).
    • ๐Ÿ“„ torch.tanh could return incorrect results on non-contiguous tensors. (#11226).
    • ๐ŸŒฒ torch.log on an expanded Tensor gave incorrect results on CPU. (#10269).
    • ๐Ÿ”Š torch.logsumexp now correctly modifies the out parameter if it is given. (#9755).
    • ๐Ÿ“„ torch.multinomial with replacement=True could select 0 probability events on CUDA. (#9960).
    • ๐Ÿ“„ torch.nn.ReLU will now properly propagate NaN.
      (#10277).
    • ๐Ÿ“„ torch.max and torch.min could return incorrect values on input containing inf / -inf. (#11091).
    • ๐Ÿ›  Fixed an issue with calculated output sizes of torch.nn.Conv modules with stride and dilation. (#9640).
    • ๐Ÿ“„ torch.nn.EmbeddingBag now correctly returns vectors filled with zeros for empty bags on CUDA. (#11740).
    • ๐Ÿ‘‰ Use integer math to compute output size of pooling operations (#14405).
    • ๐Ÿ›  Fix sum() on fp16 (#13926).
    • Remove CUDNN_BATCHNORM_SPATIAL_PERSISTENT mode for accuracy (#13844).
    • ๐Ÿ›  fix stability in bce with pos_weight formula (#13863).
    • ๐Ÿ›  Fix torch.dist for infinity, zero and minus infinity norms (#13713).
    • Give broadcast_coalesced tensors different version counters (#13594).
    • ๐Ÿ›  Fix flip() shape bug in CPU (#13344).
    • ๐Ÿ›  Fix more spectral norm bugs (#13350).
    • ๐Ÿ›  Fix handling of single input in gradcheck (#13543).
    • ๐Ÿ‘€ torch.cuda.manual_seed now also sets the philox seed and offset. (#12677).
    • ๐Ÿ“„ utils.bottleneck fix ZeroDivisionError(#11987).
    • ๐Ÿ“„ Disable hook serialization (#11705).
    • ๐Ÿ“„ torch.norm: fix negative infinity norm (#12722).
    • ๐Ÿ›  Fix torch.isfinite for integer input (#12750).
    • ๐Ÿ“„ ConvTranspose3d fix output_size calculation (#12952).
    • ๐Ÿ“„ torch.randperm: properly use RNG mutex on CPU (#13832)

    Error checking

    Miscellaneous

    • ๐Ÿ“„ torch.utils.data.DataLoader could hang if it was not completely iterated. (#10366).
    • ๐Ÿ›  Fixed a segfault when grad to a hook function is None. (#12028).
    • ๐Ÿ›  Fixed a segfault in backwards with torch.nn.PReLU when the input does not require grad. (#11758).
    • ๐Ÿ›  dir(torch) has been fixed with Python 3.7. (#10271).
    • ๐Ÿ›  Fixed a device-side assert in torch.multinomial when replacement=False and the input has fewer nonzero elements than num_samples. (#11933).
    • Can now properly assign a torch.float16 dtype tensor to .grad. (#11781).
    • ๐Ÿ›  Fixed can only join a started process error with torch.utils.data.DataLoader. (#11432).
    • ๐Ÿ“„ Prevent unexpected exit in torch.utils.data.DataLoader on KeyboardInterrupt. (#11718).
    • ๐Ÿ“„ torch.einsum now handles spaces consistently. (#9994).
    • ๐Ÿ›  Fixed a broadcasting bug in torch.distributions.studentT.StudentT. (#12148).
    • ๐Ÿ›  fix a printing error with large non-contiguous tensors. (#10405).
    • allow empty index for scatter_* methods (#14077)
    • ๐Ÿ“„ torch.nn.ModuleList now handles negative indices. (#13102).
    • Minor fix to reenable nvtx sequence numbers for the forward methods of custom (Python) autograd functions (#13876)
    • ๐Ÿ›  Fix handling all empty bags in CUDA embedding bag (#13483)
    • Fix half_tensor.bernoulli_(double) (#13474)
    • ๐Ÿ›  Fix cuda out of memory test (#13864)
    • Implement NaN-propagating max/min on Vec256. (#13399).
    • ๐Ÿ›  Fix refcounting in anomaly metadata (#13249)
    • ๐Ÿ›  Fix pointwise loss broadcast (#12996)
    • ๐Ÿ›  Fix copying a nn.Parameter (#12886)

    Other Improvements

    ๐Ÿ—„ Deprecations

    CPP Extensions

    • ๐Ÿ—„ The torch/torch.h header is deprecated in favor of torch/extension.h, which should be used in all C++ extensions going forward. Including torch/torch.h from a C++ extension will produce a warning. It is safe to batch replace torch/torch.h with torch/extension.h.
    • ๐Ÿ—„ Usage of the following functions in C++ extensions is also deprecated:
      • torch::set_requires_grad. Replacement: at::Tensor now has a set_requires_grad method.
      • torch::requires_grad. Replacement: at::Tensor now has a requires_grad method.
      • torch::getVariableType. Replacement: None.
    • ๐Ÿ›  Fix version.groups() (#14505)
    • ๐Ÿ‘ Allow building libraries with setuptools that dont have abi suffix (#14130)
    • Missing .decode() after check_output in cpp_extensions (#13935)

    torch.distributed

    ๐ŸŽ Performance

    ๐Ÿ“š Documentation Improvements