Add NVFP4 four-over-six converter - #8
Draft
wolfcomos wants to merge 1 commit into
Draft
Conversation
Wires TorchAO's NVFP4 four-over-six training prototype (torchao.prototype.moe_training.nvfp4_training.four_over_six, the adaptive map-to-4/map-to-6 block-scaling recipe with optional row-scaled activations) into the model-converter pattern: - NVFP4FourOverSixLinear: pure Linear leaf swap, forward through four_over_six_linear. No RHT and no stochastic rounding (the recipe targets RL and post-training); gradients use standard NVFP4, or bf16 GEMMs in row-scaled mode (a row-scaled four-over-six tensor has no columnwise form for the wgrad operand). - NVFP4FourOverSixLinearConverter: opt-in via converter config with fqns / err_mode / e4m3_scale_bound / row_scaled_activation knobs. - llama3_debugmodel_nvfp4_four_over_six recipe (fqns=['layers'], the lm_head stays bf16 since the vocab dim is not divisible by 128). Verified on 2x GB200 (FSDP=2, 50 steps, llama3 debugmodel): loss 8.15->2.881 vs the bf16 baseline's 8.21->2.880. Depends on the TorchAO branch nvfp4-four-over-six-rowwise (wolfcomos/ao#7). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Wires TorchAO's NVFP4 four-over-six training prototype into torchtitan via
the model-converter pattern, opt-in through converter config.
Four-over-six is an adaptive NVFP4 block-scaling recipe: every FP4 block is
encoded twice — the standard map-to-6 scale and a 1.5x-expanded map-to-4 scale
— and the candidate with the lower MAE/MSE dequantization error is stored.
Forward GEMM operands are four-over-six (activations 1x16, optionally
row-scaled with one FP32 global scale per row; weights 16x16). Gradients use
standard NVFP4, or bf16 GEMMs in row-scaled mode (a row-scaled four-over-six
tensor has no columnwise form for the wgrad operand). No RHT and no stochastic
rounding: the recipe targets RL and post-training.
NVFP4FourOverSixLinear: pureLinearleaf swap (likeMXFP8Linear),forward through
four_over_six_linear. TP is not wired up.NVFP4FourOverSixLinearConverter: config knobsfqns,err_mode(
mae/mse),e4m3_scale_bound(256/448),row_scaled_activation.llama3_debugmodel_nvfp4_four_over_sixrecipe (fqns=["layers"]; thelm_head stays bf16 since the vocab dim is not divisible by 128).
Evidence (2x GB200, FSDP=2, llama3 debugmodel, 50 steps)
The underlying torchao quantizer is verified bitwise (384/384 comparisons)
against the reference CUDA kernels for this recipe; see the TorchAO PR for the
full parity evidence.
🤖 Generated with Claude Code