You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source-pytorch/common/precision_intermediate.rst
+1-40Lines changed: 1 addition & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,7 @@ FP16 Mixed Precision
58
58
********************
59
59
60
60
In most cases, mixed precision uses FP16. Supported `PyTorch operations <https://pytorch.org/docs/stable/amp.html#op-specific-behavior>`__ automatically run in FP16, saving memory and improving throughput on the supported accelerators.
61
+
Since computation happens in FP16, there is a chance of numerical instability during training. This is handled internally by a dynamic grad scaler which skips invalid steps and adjusts the scaler to ensure subsequent steps fall within a finite range. For more information `see the autocast docs <https://pytorch.org/docs/stable/amp.html#gradient-scaling>`__.
61
62
62
63
63
64
.. note::
@@ -69,46 +70,6 @@ In most cases, mixed precision uses FP16. Supported `PyTorch operations <https:/
PyTorch 1.6 release introduced mixed precision functionality into their core as the AMP package, `torch.cuda.amp <https://pytorch.org/docs/stable/amp.html>`__. It is more flexible and intuitive compared to `NVIDIA APEX <https://github.com/NVIDIA/apex>`__.
77
-
Since computation happens in FP16, there is a chance of numerical instability during training. This is handled internally by a dynamic grad scaler which skips invalid steps and adjusts the scaler to ensure subsequent steps fall within a finite range. For more information `see the autocast docs <https://pytorch.org/docs/stable/amp.html#gradient-scaling>`__.
78
-
Lightning uses native amp by default with ``precision=16|"bf16"``. You can also set it using:
79
-
80
-
.. testcode::
81
-
82
-
Trainer(precision=16, amp_backend="native")
83
-
84
-
85
-
NVIDIA APEX
86
-
-----------
87
-
88
-
.. warning::
89
-
90
-
We strongly recommend using the above native mixed precision rather than NVIDIA APEX unless you require more refined control.
91
-
92
-
`NVIDIA APEX <https://github.com/NVIDIA/apex>`__ offers additional flexibility in setting mixed precision. This can be useful when trying out different precision configurations, such as keeping most of your weights in FP16 and running computation in FP16.
93
-
94
-
.. testcode::
95
-
:skipif: not _APEX_AVAILABLE or not torch.cuda.is_available()
2. Set the ``precision`` trainer flag to 16. You can customize the `Apex optimization level <https://nvidia.github.io/apex/amp.html#opt-levels>`_ by setting the ``amp_level`` flag
1168
-
in the precision plugin.
1169
-
1170
-
.. testcode::
1171
-
:skipif: not _APEX_AVAILABLE or not torch.cuda.is_available()
1172
-
1173
-
from pytorch_lightning.plugins import ApexMixedPrecisionPlugin
0 commit comments