File size: 441 Bytes
7e3773e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import torch
from contextlib import suppress
# amp_bfloat16 is more stable than amp float16 for clip training
def get_autocast(precision):
if precision == 'amp':
return torch.cuda.amp.autocast
elif precision == 'amp_bfloat16':
return lambda: torch.cuda.amp.autocast(dtype=torch.bfloat16)
elif precision == 'fp32':
return lambda: torch.cuda.amp.autocast(enabled=False)
else:
return suppress
|