Repository navigation
MxFP8 gradient cross entropy option - #3758
sraman-rgb wants to merge 12 commits into
Conversation
… launch Add a grad_quantizer argument to parallel_cross_entropy. With an MXFP8Quantizer (E4M3 or E5M2, compact scales), a BF16 input on a single rank, and row count and vocabulary that are multiples of 128, one Triton kernel writes the derivative as an MXFP8 tensor with row-wise and column-wise data, bit-identical to quantizing the BF16 derivative with the quantizer. A following MXFP8 linear layer (an LM head) then skips its own grad-output quantization pass. Other cases compute the derivative as before and quantize it. Launch the single-rank forward with 4096-element blocks and 4 warps and the backward with 4096-element blocks and 8 warps instead of one 32-warp program with up to 32K elements per row, and find the argmax with a min-reduction over the block maximum instead of tl.max(return_indices=True). Only the accumulation order of the softmax statistics changes. Signed-off-by: Siddhartha Raman S <sraman@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… scale The NaN/Inf selects in the E8M0 exponent and reciprocal helpers slowed the fused MXFP8 backward from about 340 us to 420 us at 4096 x 129280 on a Rubin GPU. Finite gradients, the only ones a training step uses, still get the bytes of TE's MXFP8 cast; this is now stated in the docstring. Signed-off-by: Siddhartha Raman S <sraman@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The changes reach cross-entropy execution and its connection to quantized linear layers. Fix the missing-direction check before merging; a supported MXFP8 quantizer setting can stop training during backward. Findings
SummaryAdds optional quantized gradients to
Reviews (9) · Last reviewed commit: "Merge branch 'main' into sraman/te-ce-mx..." · Reviewed by Greptile |
…sum into NaN When every logit seen so far in a row is -inf, the online softmax shifted the exponentials by a running maximum of -inf, so exp(-inf - (-inf)) made the sum of exponentials NaN for the rest of the row. With 4096-wide forward blocks this happens for any row whose first block is masked. Shift by 0 until a finite maximum is seen, in the single-rank and tensor-parallel forward kernels and in the cross-rank merge. Rows with a finite maximum compute exactly as before; rows whose logits are all -inf still give NaN, as in PyTorch. Add tests with masked logits against PyTorch, including the MXFP8 gradient, CUDA graph replay and tensor parallelism. Signed-off-by: Siddhartha Raman S <sraman@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve conflicts with the upstream NaN fix (e41b2be): keep its _safe_shift kernels and masked-logits tests, which supersede the equivalent changes on ksivamani/nan_fix. Keep from ksivamani/nan_fix the tensor-parallel fused MXFP8 backward, the removal of the dead contiguity check, the fused-kernel launch checks, the 128-column tile coverage and the tensor-parallel MXFP8 test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
|
/te-ci pytorch |
Resolve conflicts with NVIDIA#3891, which landed the same -inf shift fix as this branch: keep main's _softmax_shift and drop the branch's duplicate _safe_shift. Keep the tests from both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
|
/te-ci pytorch |
| fp8_dtype = getattr(grad_output, "_fp8_dtype", None) | ||
| return fp8_dtype is None or fp8_dtype == quantizer.dtype |
There was a problem hiding this comment.
Missing gradient data breaks backward
_quantized_grad_output_matches accepts MXFP8 gradients without checking which directions they contain. A CustomRecipe factory can return a rowwise-only MXFP8Quantizer, which get_cross_entropy_grad_quantizer passes through unchanged. The loss then returns a gradient without columnwise data.
A trainable Linear accepts that gradient here, but later calls update_usage(columnwise_usage=True). That raises because MXFP8 cannot rebuild the missing data, stopping training during backward. Check the required directions before accepting the gradient, and dequantize and quantize it again when a direction is missing.
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: