Below are functions and classes relative to the underlying FP8 implementation
( backend: typing.Literal['MSAMP', 'TE'] = None use_autocast_during_eval: bool = None opt_level: typing.Literal['O1', 'O2'] = None margin: int = None interval: int = None fp8_format: typing.Literal['E4M3', 'HYBRID'] = None amax_history_len: int = None amax_compute_algo: typing.Literal['max', 'most_recent'] = None override_linear_precision: typing.Tuple[bool, bool, bool] = None )
Parameters
str
, optional) —
Which FP8 engine to use. Must be one of "msamp"
(MS-AMP) or "te"
(TransformerEngine). If not passed,
will use whichever is available in the environment, prioritizing MS-AMP. bool
, optional, default to False
) —
Whether to use FP8 autocast during eval mode. Generally better metrics are found when this is False
. int
, optional, default to 0) —
The margin to use for the gradient scaling. int
, optional, default to 1) —
The interval to use for how often the scaling factor is recomputed. str
, optional, default to “HYBRID”) —
The format to use for the FP8 recipe. Must be one of HYBRID
or E4M3
. (Generally HYBRID
for training,
E4M3
for evaluation) int
, optional, default to 1024) —
The length of the history to use for the scaling factor computation str
, optional, default to “most_recent”) —
The algorithm to use for the scaling factor computation. Must be one of max
or most_recent
. tuple
of three bool
, optional, default to (False, False, False)
) —
Whether or not to execute fprop
, dgrad
, and wgrad
GEMMS in higher precision. str
), one of O1
, O2
. (default is O2
) —
What level of 8-bit collective communication should be used with MS-AMP. In general:all_reduce
communications are done in fp8, reducing GPU
memory usage and communication bandwidthfp8
is selected and deepspeed is enabled, will be used by default. (Not
available currently).Use this object in your Accelerator to customize the initialization of the recipe for FP8 mixed precision
training with transformer-engine
or ms-amp
.
For more information on transformer-engine
args, please refer to the API
documentation.
For more information on the ms-amp
args, please refer to the Optimization Level
documentation.
( model to_transformer_engine = True _convert_linear = True _convert_ln = True )
Recursively converts the linear and layernorm layers of a model to their transformers_engine
counterpart.
Returns whether a given model has some transformer_engine
layer or not.
( model_forward fp8_recipe use_during_eval = False )
Wrapper for a model’s forward method to apply FP8 autocast. Is context aware, meaning that by default it will disable FP8 autocast during eval mode, which is generally better for more accurate metrics.
Applies FP8 context manager to the model’s forward method