[PyTorch] Decline fused grouped MLP when the backward format is not E4M3 - #3352
Open
wilyan09007 wants to merge 1 commit into
Open
[PyTorch] Decline fused grouped MLP when the backward format is not E4M3#3352wilyan09007 wants to merge 1 commit into
wilyan09007 wants to merge 1 commit into
Conversation
The fused grouped MLP packs the incoming activation gradient by reinterpreting its storage as E4M3, conditioned only on NVFP4 and never on the FP8 format. Under MXFP8BlockScaling(fp8_format=Format.HYBRID) the backward quantizers emit E5M2, so those bytes are read as the wrong format rather than converted, and every gradient out of the fusion is wrong. The forward pass is unaffected, so this shows up as a model that trains too slowly instead of one that fails. Fall back to the unfused ops when the recipe's backward format is not E4M3, and raise instead of reinterpreting if such a gradient reaches the kernel path. Signed-off-by: William <wilyan090@gmail.com>
Contributor
Greptile SummaryThe PR prevents fused grouped-MLP backward execution when gradients use a format that its packing path would reinterpret incorrectly.
Confidence Score: 5/5The PR appears safe to merge, with no actionable correctness, security, or test-infrastructure issues identified. The fusion gate rejects the incompatible HYBRID backward format before rewriting operations, while the runtime check safely catches any non-E4M3 MXFP8 gradient that nevertheless reaches the packing path; supported E4M3 and NVFP4 paths remain enabled. Important Files Changed
Reviews (1): Last reviewed commit: "[PyTorch] Decline fused grouped MLP when..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GroupedMLP_CuTeGEMMGLUpacks the incoming activation gradient by reinterpreting its storage as E4M3, conditioned only on NVFP4 and never on the FP8 format. UnderMXFP8BlockScaling(fp8_format=Format.HYBRID)the backward quantizers emit E5M2, so those bytes are read as the wrong format rather than converted and every gradient out of the fusion is wrong. The forward pass is unaffected.This declines the fusion when the recipe's backward format is not E4M3, next to the existing RHT check, and raises rather than reinterpreting if such a gradient still reaches the kernel path. NVFP4 pins
fp8_formatto E4M3, so it is unaffected.Fixes #3342
Type of change
Changes
fuse_grouped_mlp_ops()whenget_fp8_torch_dtype(recipe, fprop_tensor=False)is not E4M3.test_fusion_declined_for_e5m2_grad_output.Checklist: