According to https://pytorch.org/blog/accelerating-training-on-nvidia-gpus-with-pytorch-automatic-mixed-precision/
We can use:
with torch.cuda.amp.autocast():
loss = model(data)
In order to casts operations to mixed precision.
Another thing is that we can use model.half()
to convert all the model weights to half precision.
- What is the difference between these 2 commands ?
- If I want to take advantage of
FP16
(in order to create larger models and shorter training time), what do I need ? Do I need to usemodel.half()
or usingtorch.cuda.amp
(according the link above) ?