Vue d'ensemble
PyTorch 1.10, publie le 22 octobre 2021, ajoute le support des CUDA Graphs et ameliore la promotion de types pour des calculs plus fiables.
Fonctionnalites principales
CUDA Graphs
Les CUDA Graphs capturent une sequence d'operations GPU et la rejouent sans surcharge CPU, reduisant significativement la latence pour les modeles d'inference.
python
import torch
# Capture d'un CUDA Graph
# x = torch.randn(1000, device='cuda')
# graph = torch.cuda.CUDAGraph()
# Warmup
# with torch.cuda.graph(graph):
# y = x * 2 + 1
# Replay sans surcharge CPU
# graph.replay()
# Exemple CPU equivalent
x = torch.randn(1000)
y = x * 2 + 1
print(f'Forme : {y.shape}, Moyenne : {y.mean():.2f}')
Promotion de types
Les regles de promotion de types sont alignees avec NumPy pour des resultats plus previsibles lors du melange de types (int, float, complex) dans les operations tensorielles.
python
import torch
# Promotion de types amelioree
a = torch.tensor([1, 2, 3], dtype=torch.int32)
b = torch.tensor([1.5, 2.5, 3.5], dtype=torch.float32)
# Le resultat est promu en float32
c = a + b
print(f'Type : {c.dtype}') # torch.float32
print(f'Valeurs : {c}') # [2.5, 4.5, 6.5]
# Promotion avec scalaire
d = a * 2.0
print(f'Type : {d.dtype}') # torch.float32
