Skip to content

Add NVFP4 four-over-six converter - #8

Draft
wolfcomos wants to merge 1 commit into
mainfrom
nvfp4-four-over-six-converter
Draft

Add NVFP4 four-over-six converter#8
wolfcomos wants to merge 1 commit into
mainfrom
nvfp4-four-over-six-converter

Conversation

@wolfcomos

Copy link
Copy Markdown
Owner

What

Wires TorchAO's NVFP4 four-over-six training prototype into torchtitan via
the model-converter pattern, opt-in through converter config.

Depends on the TorchAO PR wolfcomos/ao#7
(torchao.prototype.moe_training.nvfp4_training.four_over_six, branch
nvfp4-four-over-six-rowwise). This PR's NVFP4FourOverSixLinear is None
(and the converter raises ImportError) on torchao builds without it.

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: pure Linear leaf swap (like MXFP8Linear),
    forward through four_over_six_linear. TP is not wired up.
  • NVFP4FourOverSixLinearConverter: config knobs fqns, err_mode
    (mae/mse), e4m3_scale_bound (256/448), row_scaled_activation.
  • llama3_debugmodel_nvfp4_four_over_six recipe (fqns=["layers"]; the
    lm_head stays bf16 since the vocab dim is not divisible by 128).

Evidence (2x GB200, FSDP=2, llama3 debugmodel, 50 steps)

step bf16 four-over-six four-over-six row-scaled
1 8.21253 8.15202 8.06924
10 3.71664 3.67363 3.59410
30 2.86240 2.87019 2.86336
50 2.87953 2.88080 2.87267

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant