Repository navigation
Guard blockwise FP8 backward (E5M2) wgrad against all-zero gradient blocks #7523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -797,8 +797,17 @@ def get_fp8_recipe(config: TransformerConfig): | |
| fp8_format=fp8_format, fp8_dpa=config.fp8_dot_product_attention | ||
| ) | ||
| elif config.fp8_recipe == Fp8Recipe.blockwise and is_te_min_version("2.3.0.dev0"): | ||
| fp8_recipe = transformer_engine.common.recipe.Float8BlockScaling( | ||
| fp8_format=fp8_format | ||
| # Guard backward (E5M2) wgrad against all-zero gradient blocks: | ||
| # amax=0 → scale=inf → NaN. | ||
| block_scaling_recipe_cls = transformer_engine.common.recipe.Float8BlockScaling | ||
| fp8_recipe = block_scaling_recipe_cls(fp8_format=fp8_format) | ||
| bwd_qparams = block_scaling_recipe_cls.fp8_quant_bwd_grad | ||
| fp8_recipe.fp8_quant_bwd_grad = transformer_engine.common.recipe.QParams( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This monkey patching TE? Shouldn't this just be fixed in TE?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the current code updates only the recipe instance to make the guard effective Bbut it's only related to the default recipe choice so I think eventually we should be flexible to customize the recipe. To avoid the monkey patch, TE ideally need to accept additional
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for delay. So why not fix this in TE and avoid the monkey patch? If it's just the default recipe then fix the default recipe in TE? Adding the flexibility can come later if needed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I opened NVIDIA/TransformerEngine#3651 on the TE, I prefer keeping this PR opened until that one is discussed/merged/released for other's reference. Thanks again. |
||
| power_2_scale=bwd_qparams.power_2_scale, | ||
| amax_epsilon=1e-12, | ||
| random_hadamard_transform=bwd_qparams.random_hadamard_transform, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's confusing code, because there is no hadamard transform to fp8 block scaling at all, so it's supposed to be False unless we are talking about nvfp4 |
||
| stochastic_rounding=bwd_qparams.stochastic_rounding, | ||
| fp4_2d_quantization=bwd_qparams.fp4_2d_quantization, | ||
| ) | ||
| elif config.fp8_recipe == Fp8Recipe.mxfp8: | ||
| fp8_recipe = transformer_engine.common.recipe.MXFP8BlockScaling( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use E5M2 for backward pass whenever we are using block scaling recipe, E5M2 is not gonna be useful for this recipe, so what was the motivation for using E5M2 in the first place?