Facebook Launches PyTorch 1.4, Supporting Custom Script Building and Java Binding

2020-01-17

PyTorch is one of the most popular machine learning frameworks today. Facebook has released PyTorch 1.4, which includes upgrades to the audio, vision, and text libraries.



PYTORCH 1.4


PyTorch 1.4 introduces new features, including fine-grained build-level customization for PyTorch Mobile and experimental support for model parallel training and Java language bindings.



PyTorch Mobile - Fine-Grained Build-Level Customization


Following the open-sourcing of PyTorch Mobile in version 1.3, PyTorch 1.4 adds more mobile support, including the ability to customize build scripts at a fine-grained level. This allows mobile developers to optimize the size of the library by including only the operators used by their models, significantly reducing the space occupied by their devices. Preliminary results show that a customized MobileNetV2 is 40% to 50% smaller than the pre-built PyTorch Mobile library.


Example code snippet for selectively compiling the operators required by MobileNetV2:



# Dump list of operators used by MobileNetV2:
import torch, yaml
model = torch.jit.load('MobileNetV2.pt')
ops = torch.jit.export_opnames(model)
with open('MobileNetV2.yaml', 'w') as output:

    yaml.dump(ops, output)
# Build PyTorch Android library customized for MobileNetV2:
SELECTED_OP_LIST=MobileNetV2.yaml scripts/build_pytorch_android.sh arm64-v8a

# Build PyTorch iOS library customized for MobileNetV2:
SELECTED_OP_LIST=MobileNetV2.yaml BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 scripts/build_ios.sh

Distributed Model Parallel Training (Experimental)


As models scale up to billions of parameters, such as RoBERTa, model parallel training becomes increasingly important for researchers to push the limits. This release provides a distributed RPC framework to support distributed model parallel training. It allows remote execution of functions and referencing remote objects without the need to copy actual data, and provides autograd and Optimizer API to transparently run backward and update parameters across RPC boundaries.



Java Bindings (Experimental)


In addition to supporting Python and C++, this release also adds experimental support for Java bindings. Building on the interface developed for Android in PyTorch Mobile, the new bindings allow you to call TorchScript models from any Java program. Please note that Java bindings are only available for Linux in this release and are intended for inference only. See the code snippet below for information on how to use PyTorch in Java:



Module mod = Module.load("demo-model.pt1");
Tensor data =
Tensor.fromBlob(
new int[] {1, 2, 3, 4, 5, 6}, // data
new long[] {2, 3} // shape
);
IValue result = mod.forward(IValue.from(data), IValue.from(3.0));
Tensor output = result.toTensor();
System.out.println("shape: " + Arrays.toString(output.shape()));
System.out.println("data: " + Arrays.toString(output.getDataAsFloatArray()));

Domain Libraries


The PyTorch domain libraries (such as torchvision, torchtext, and torchaudio) complement PyTorch with common datasets, models, and transformations. We are excited to share new versions of all three domain libraries alongside the PyTorch 1.4 core release.



torchvision 0.5


The improvements in torchvision 0.5 mainly focus on increasing support for production deployment, including quantization, TorchScript, and ONNX. Some highlights include:




  • All models in torchvision can now be written in TorchScript, making it easier to port them to non-Python production environments.

  • ResNets, MobileNet, ShuffleNet, GoogleNet, and InceptionV3 now have quantized objects for pre-trained models, including scripts for quantization-aware training.

  • In collaboration with the Microsoft team, we have added ONNX support for all models, including Mask R-CNN.


torchaudio 0.4


The improvements in torchaudio 0.4 focus on enhancing the available transformations, datasets, and backend support. Key highlights include:




  • SoX is now optional, and a new extensible backend dispatch mechanism exposes SoundFile as an alternative to SoX.

  • The interfaces for datasets have been unified. This allows the addition of two large datasets: LibriSpeech and Common Voice.

  • New filters (e.g., biquad), data augmentation (e.g., time and frequency masking), transforms (e.g., MFCC), gain and jitter, and new feature computations (e.g., delta) are now available.

  • Transforms now support batching and are jitable.

  • An interactive speech recognition demo with speech activity detection capability is available for experimentation.


torchtext 0.5


torchtext 0.5 primarily focuses on improvements to the dataset loaders API, including compatibility with the core PyTorch API, but also adds support for unsupervised text tokenization. Key highlights include:




  • Bindings for SentencePiece have been added to enable unsupervised text tokenization.

  • A new unsupervised learning dataset, enwik9, has been added.

  • Revisions have been made to PennTreebank, WikiText103, WikiText2, and IMDb to make them compatible with torch.utils.data.

RECENT AI NEWS

RECENT AI TOOLS