PyTorch 2 cheatsheet
PyTorch 2: Performance
5 common PyTorch 2 tasks.
Speed up a model
Compile the model with torch.compile for faster training and inference.
model = torch.compile(model)
Use mixed precision
Run operations in lower precision on the GPU to save memory and time.
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
loss = loss_fn(model(x), y)