Repository navigation
Conversation
…s at 1e-30 The per-token and per-channel Triton casts took their amax with tl.max and floored it with tl.maximum, both of which drop NaN, and clamped with tl.clamp, which turns NaN into -448. A NaN in the input then left the cast as finite garbage. The amax, its floor and the clamp now propagate NaN, so the group's scale and values are NaN. Finite inputs cast to the same bytes as before. The casts of gradients in the FP8 grouped GEMM and FP8 linear backwards now floor their amax at 1e-30 instead of 1e-10, so gradients far below the loss's scale keep exact scales instead of flushing toward zero. Activation casts, in the forward and backward, keep the 1e-10 floor that matches vLLM's per-token-group quant.
MarioSieg
marked this pull request as ready for review
December 2, 2026 18:40
This branch has not been deployed
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.
Summary
fp8_utils.pytook their amax withtl.maxandtl.maximum(both drop NaN) and clamped withtl.clamp(which turns NaN into -448). A NaN in the input was cast to finite garbage, so a NaN in activations or gradients could go unnoticed in the FP8 paths. The amax reduction, its floor and the clamp now usepropagate_nan=tl.PropagateNan.ALL: the NaN's group gets a NaN scale and NaN values, and the other groups are unchanged. Finite inputs cast to the same bytes as before. The 128x128 weight cast has no clamp and is unchanged.amax_floor(defaultACTIVATION_AMAX_FLOOR = 1e-10). The FP8 grouped GEMM backward (deepgemm_fp8experts: the dgrad per-token cast and the wgrad per-channel cast of the output gradient) and the FP8 blockwise linear/bmm backwards cast the output gradient withGRAD_AMAX_FLOOR = 1e-30. Gradients far below the loss's scale then keep exact scales instead of flushing toward zero. Activation casts, in both the forward and the backward, keep 1e-10, so the forward still matches vLLM's per-token-group quant bit for bit.nvfp4_to_mxfp8and the Mega MoE MX casts take padded or per-rank token counts. So nodo_not_specializeis needed.test_token_and_channel_casts_propagate_nantotests/unit/train/models/test_fp8_utils.py.GPU validation is still pending: this was written without access to a GPU.
Test plan
ruff checkandruff formaton the changed filesTRITON_INTERPRET=1, CPU) comparing the old and new casts on the same inputs: for every cast, with and without UE8M0, only the groups that contain a NaN change, and their scales are now NaN. With the 1e-30 floor, only a group with amax below 1e-10 changes. The interpreter does not emulate e4m3 rounding or NaN encoding faithfully, so it could not check the exact fp8 bytes.tests/unit/train/models/test_fp8_utils.py(including the vLLM bit-match tests) andtests/unit/train/models/test_fp8_grouped_gemm.pyNote
Medium Risk
Changes FP8 quantization numerics and NaN semantics on training backward paths (MoE grouped GEMM and blockwise linear), though forward activation quantization stays vLLM-aligned at 1e-10.
Overview
NaN propagation in FP8 casts: Per-token and grouped per-token/channel Triton kernels no longer turn NaNs into finite FP8 values. Amax reduction and clamp now use NaN-propagating reductions (
_amax,_nan_max) andpropagate_nan=tl.PropagateNan.ALLon clamp, so a NaN in a quantization group yields NaN scales and values for that group only; other groups stay bit-identical to before on finite inputs.Configurable amax floors: Casts accept
amax_floor(defaultACTIVATION_AMAX_FLOOR = 1e-10for vLLM-aligned activations). FP8 linear and grouped-GEMM backward paths cast output gradients withGRAD_AMAX_FLOOR = 1e-30so tiny gradients keep exact scales instead of being floored at1e-10. Forward activation casts are unchanged at1e-10.Adds GPU test
test_token_and_channel_casts_propagate_nanfor the three affected cast variants.Reviewed by Cursor Bugbot for commit d61984a. Bugbot is set up for automated code reviews on this repo. Configure here.