Overview
PyTorch 1.9, released on June 16, 2021, stabilizes the torch.linalg module for linear algebra and introduces the mobile interpreter for deployment on embedded devices.
Main Features
Stable torch.linalg
The torch.linalg module provides NumPy-compatible linear algebra functions: decomposition, inversion, linear system solving, all differentiable.
python
import torch
A = torch.randn(3, 3)
b = torch.randn(3)
# Solve linear system Ax = b
x = torch.linalg.solve(A, b)
print(f'Solution: {x}')
# Singular value decomposition
U, S, Vh = torch.linalg.svd(A)
print(f'Singular values: {S}')
Mobile interpreter
The mobile interpreter reduces the PyTorch runtime size for deployment on mobile devices. It loads only the operators used by the model, significantly reducing the footprint.
python
import torch
from torch.utils.mobile_optimizer import optimize_for_mobile
# Prepare model for mobile
model = torch.jit.script(my_model)
optimized = optimize_for_mobile(model)
# Save for the mobile interpreter
optimized._save_for_lite_interpreter('model_mobile.ptl')
print('Optimized mobile model saved')
