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
class MixedPrecisionPolicy:
"""
This configures FSDP's mixed precision. Unlike autocast, this applies mixed
precision at the module level, not op level, which means low-precision
activations are saved for backward and high-to-low-precision casts are
incurred only at module boundaries.
FSDP works well with module-level mixed precision since it keeps the
high-precision sharded parameters in memory anyway. In other words, FSDP
does not require any extra memory to keep a high-precision copy of the
parameters for the optimizer step.
I assume that FSDP2 will choose to cast a layer in a Transformer, for example, to BF16. How would this affect specific operations in the layer, such as the SoftMax, which typically run in FP32? Will any explicit casting (such as .to(float32)) be affected by this MP Policy?
With FSDP2's mixed precision, the forward (and backward) run with bf16 tensors. More specifically, FSDP2 can cast the module forward inputs for the user to bf16, and FSDP2 will all-gather the parameters in bf16. That is all -- there is no further implicit behavior or anything.
In other words, it is like running a forward and backward on a single GPU but when model.to(torch.bfloat16) and passing input in torch.bfloat16 (if floating-point). Note however that for FSDP, the sharded parameters used for optimizer can still be fp32.
Specific kernel implementations can still accumulate internally in fp32, but since the operator will output in bf16, there will be that rounding that happens at the end of the operator.
Activity
awgu commentedon Oct 6, 2024
With FSDP2's mixed precision, the forward (and backward) run with bf16 tensors. More specifically, FSDP2 can cast the module forward inputs for the user to bf16, and FSDP2 will all-gather the parameters in bf16. That is all -- there is no further implicit behavior or anything.
In other words, it is like running a forward and backward on a single GPU but when
model.to(torch.bfloat16)and passing input intorch.bfloat16(if floating-point). Note however that for FSDP, the sharded parameters used for optimizer can still be fp32.Specific kernel implementations can still accumulate internally in fp32, but since the operator will output in bf16, there will be that rounding that happens at the end of the operator.
karan-dalal commentedon Oct 6, 2024
Makes sense. Thank you!