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
PyTorch 2 · Performance
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
Was this page helpful?