Repository navigation
Conversation
MXFP8 backward GEMMs that re-quantize saved forward tensors and gradients need unbiased rounding (the end-to-end 4-bit MoE recipe, radixark/miles#4952). The MXFP8 cast only rounded to nearest. - MXFP8Quantizer(stochastic_rounding=False): the generic MXFP8 kernel rounds each element with cvt.rs.satfinite.e4m3x4 / e5m2x4 on Philox bits (one 32-bit draw per four elements, seeded like NVFP4). Block scales are unchanged; the round-to-nearest cast-only kernel is skipped when the option is on. - The single-tensor quantize dispatch accepts stochastic rounding for MXFP8. - Fused activation, dbias, dact-dbias and cuDNN norm paths fall back to their unfused paths for a stochastic-rounding quantizer; grouped quantize, bgrad_group_quantize and MXFP8 attention reject it instead of silently rounding to nearest. Tested on B200: tests/pytorch/mxfp8/test_mxfp8_stochastic_rounding.py (45 passed), existing MXFP8 swizzle-fusion and group-quantize tests (306 passed), MXFP8 cases of test_quantized_tensor.py (31 passed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Hejian Sang <sanghj0923@gmail.com>
HJSang
marked this pull request as ready for review
November 19, 2026 19:45
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.
Why
The end-to-end 4-bit MoE recipe (radixark/miles#4952) runs the backward GEMMs in MXFP8: saved NVFP4 forward tensors are dequantized, transposed and re-quantized to MXFP8, and incoming gradients are cast to MXFP8, both with stochastic rounding so the re-quantization stays unbiased. The MXFP8 cast only rounds to nearest. This PR adds the stochastic-rounding cast; the
backward_overridemode that consumes it is a follow-up.What
MXFP8Quantizer(stochastic_rounding=False). When on, the generic MXFP8 kernel rounds each element withcvt.rs.satfinite.e4m3x4.f32/e5m2x4(sm_100a / sm_103a) on Philox bits: one 32-bit draw per four elements, with the seed/offset/subsequence scheme NVFP4 already uses.MXFP8Quantizer::quantize) for a stochastic-rounding quantizer;bgrad_group_quantizeand MXFP8 attention raise instead._LOOSE_PRECISIONcvt.rsFP8 helpers inptx.cuhfeed a constant random operand, so this PR adds a separate helper,cvt_fp32_to_fp8_4x_with_stochastic_rounding.Tests (B200, CUDA 13.0, torch 2.14.1)
tests/pytorch/mxfp8/test_mxfp8_stochastic_rounding.py: scales equal round-to-nearest; round-to-nearest equals a PyTorch cast bit for bit; every SR value is one of its two FP8 grid neighbours; unbiased over 512 draws; same seed gives the same bits. Covers row / column / both directions, bf16 / fp32 input, E4M3 / E5M2 output, and a ragged 192×160 shapemxfp8/test_mxfp8_quantize_swizzle_fusion.py,mxfp8/test_mxfp8_group_quantize_graph_safe.pytest_quantized_tensor.py -k mxfp8tex.geluandtex.bgrad_quantizewith a stochastic-rounding quantizer round stochastically onto valid neighboursNot covered
GroupedLinearsplit path) still rejects stochastic rounding. It is the next PR, beforebackward_override="mxfp8".🤖 Generated with Claude Code