[nvfp4 training][rl] Add the four-over-six grouped GEMM and dispatcher wiring - #14
Closed
wolfcomos wants to merge 1 commit into
Closed
[nvfp4 training][rl] Add the four-over-six grouped GEMM and dispatcher wiring#14wolfcomos wants to merge 1 commit into
wolfcomos wants to merge 1 commit into
Conversation
This was referenced Aug 30, 2026
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 02:01
e712a0e to
cd50f68
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 02:01
b6d440f to
e576049
Compare
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 03:09
cd50f68 to
dcc166e
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 03:09
e576049 to
3621d9e
Compare
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 04:14
dcc166e to
5113820
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 04:14
3621d9e to
ed08374
Compare
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 04:37
5113820 to
7f1e7d4
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 04:37
ed08374 to
3f5fa5d
Compare
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 04:44
7f1e7d4 to
ff415d7
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 04:44
3f5fa5d to
5c3fe59
Compare
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 06:35
ff415d7 to
1e847a8
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 06:35
5c3fe59 to
9f57abe
Compare
…atcher Integrate the four-over-six recipe with MoE training: routed-expert layers get four_over_six_grouped_mm, built by reusing the existing pieces rather than adding kernels — the quantizer from the dense PRs (the CuTe DSL fast path dispatches automatically) and the existing F.scaled_grouped_mm for the GEMMs. - Per-tensor activations: each token group's amax expands to a per-row vector so the whole packed tensor quantizes in one call, bitwise identical to quantizing each group separately; one scaled_grouped_mm with per-group second-level scales runs the forward. - Expert weights quantize in one flattened call for both block shapes (the quantizer accepts a per-row amax with 16x16 blocks under a tile-uniform contract), one kernel launch regardless of expert count. - Row-scaled activations: one scaled_grouped_mm carrying the constant per-tensor factor, its bf16 output upcast and scaled by the raw per-row amaxes (the grouped GEMM emits bf16 only, one output rounding vs a dense per-group loop; tests pin it against a rounding-emulated loop oracle). - Backward is high-precision or dequantized grouped GEMMs (no quantized backward); dequantized differentiates the quantized forward itself from the saved 4-bit codes and scales. Wiring mirrors the Float8/MXFP8 recipes exactly: NVFP4FourOverSixTrainingOpConfig(TrainingOpBaseConfig) — a pytree-constant dataclass with explicit __eq__/__hash__ — plus an isinstance branch in _quantize_then_scaled_grouped_mm. The dispatcher branch owns the offs[-1] tail slice / zero-extend for padded token dispatchers that over-allocate A past the logical rows. Also adds an NVFP4 four-over-six section to the moe_training README. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
wolfcomos
force-pushed
the
4over6/ao2-cutedsl
branch
from
August 31, 2026 07:02
1e847a8 to
2c69dbc
Compare
wolfcomos
force-pushed
the
4over6/ao3-grouped-dispatcher
branch
from
August 31, 2026 07:02
9f57abe to
8a7dadc
Compare
Owner
Author
|
Opened upstream as pytorch#4853 (same head). This fork draft stays as the staging copy. |
Owner
Author
|
Live upstream as pytorch#4853 — closing the staging draft. The branch stays: it is the upstream PR's head. |
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.
Stacked on #12/#13. Integrates the four-over-six recipe with MoE training for routed-expert layers, reusing existing pieces rather than adding kernels: the #13 quantizer (its CuTe DSL fast path dispatches automatically) and the existing
F.scaled_grouped_mmfor the GEMMs.scaled_grouped_mmwith per-group second-level scales runs the forward.scaled_grouped_mmcarrying the constant per-tensor factor in every group's slot, its bf16 output upcast and scaled by the raw per-row amaxes. The grouped GEMM emits bf16 only, which costs one output rounding vs per-group dense GEMMs; tests emulate that rounding in a loop oracle and compare bitwise (with a reduction-order SQNR fallback), and separately bound the rounding cost.high_precisionordequantizedgrouped GEMMs (four-over-six has no quantized backward);dequantizeddifferentiates the quantized forward itself from the saved 4-bit codes and scales.Wiring mirrors the Float8/MXFP8 recipes exactly:
NVFP4FourOverSixTrainingOpConfig(TrainingOpBaseConfig)— a pytree-constant dataclass with explicit__eq__/__hash__— plus anisinstancebranch in_quantize_then_scaled_grouped_mm. The dispatcher branch owns theoffs[-1]tail slice / zero-extend for padded token dispatchers that over-allocateApast the logical rows.quantize_()model conversion for the grouped config is future work; framework integrations drive the grouped GEMM dispatcher (see the torchtitan converters). Adds an NVFP4 four-over-six section to the moe_training README.Tests: 40 grouped tests (grouped-vs-dense forward parity, row-scaled fused-vs-oracle, backward bitwise references including empty groups and ragged padding, dispatcher round-trip with over-allocated tails, fullgraph compile in both scale granularities) plus the dense suite with the relaxed quantizer combinations, all green on GB200.
Stack: #12 ← #13 ← this PR.