PyTorch 2 · Performance

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)

Official PyTorch 2 documentation

More performance commands

All performance commands · PyTorch 2 cheatsheet

Was this page helpful?