Skip to content

[MXFP8] Consume directly blocked activation scales - #5334

Open
sanketpurandare wants to merge 1 commit into
dsv3-mtp-loss-metricsfrom
dsv3-mxfp8-blocked-activation-scales
Open

sanketpurandare wants to merge 1 commit into
dsv3-mtp-loss-metricsfrom
dsv3-mxfp8-blocked-activation-scales

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Performnace of this fused cute-dsl quantizer is better than cuda, a single API for dense and grouped mxfp8 linears, no need for scale rearrangements since swizzled layouts are directly output.

Consume TorchAO's landed fused dense rowwise/columnwise cast and single-axis
CuTeDSL casts directly, with blocked E8M0 scales and offs=None. Activation casts
live with weight quantization in tensor.py and use a shared RCEIL constant;
the existing square weight kernel's fixed RCEIL contract is explicitly enforced.
Select CuTeDSL automatically for 128-aligned BF16 operands, with no Linear/
converter backend option or saved autograd backend state. Use CUDA MXFP8 plus
blocked-scale rearrangement only for unsupported operand geometry, not missing
dependencies. Report missing AO/CuTeDSL dependencies with installation guidance
before that linear's parameter allocation. Preserve input-save formats,
32x32 RCEIL weight-scale policy, FSDP lifecycle, gradient destinations and
non-owned output behavior. Reject
unsupported required providers instead of padding or silently falling back.
Credit Protonu's #4895 kernel and Aleksandar's single-axis metadata work; only
landed AO #4995 is the runtime dependency.

Add complete PP2/VPP8/DP128 and PP4/VPP4/DP64, EP64 671B/MTP1 MLPerf recipes
using indexed aligned input sources, global strided ordering, GBS 15360/T4096
and fixed GBS 1024 validation. Reuse the earlier validation, MTP and dense-SDPA
interfaces. Include MXFP8 on the shared head, opt into its existing coalesced
training projection. Choose casts per actual operand: KV-A's aligned forward
input uses CuTeDSL, while its unsupported 576-wide output gradient uses CUDA.
The redundant recipe-level module-backend selector is removed.
Storage adapters and warmed checkpoint binding stay outside core TorchTitan.
Preserve current main's nested MLA KV-B projection selector, with an explicit
check that all 62 main/MTP projections retain MXFP8 rather than BF16 inputs.

Match NVIDIA's BF16 router GEMMs/logits/backward boundary, FP32 sigmoid and
selection, BF16 selected weights, unbiased top-8 sequence auxiliary coefficient
0.01, scale 2.5 and uncentered expert-bias update 0.001. Generic defaults remain
unchanged. Preserve FP32 persistent/final updates, BF16 gather/accumulation/
reduction/Adam moments, selective decay 0.033, clipping 1 and the zero-start
LR multipliers 0/.25/.5/.75/1 with a 11996-update cosine horizon.

Both optimizer/training and landed validation CUDA graphs are enabled.
Expose the existing graph wrapper's eager warmup count through TrainingConfig
(default2, production1) for both training and optimizer capture. Keep the
shared pool's landed eval-first readiness gate. Persisted map-dataset sharding
uses the explicit map_dataset_dp_sharding policy from the data PR. Forced
recipes select CF1; learned recipe defaults retain their conservative CF32 scratch
and minimum saved-activation policy. A run-specific wrapper may set measured
scratch/slot limits on the returned config. VMM and GraphTrainer are excluded.
Future router/sequence/CE fusion overrides are intentionally not imported at
this boundary; their integration belongs to the next three separate PRs.

Verification

Owning-commit CPU checks: 152 passed, 19 warnings in 34.43s.

Strict relevant Sphinx builds and all non-type repository hooks passed.
Three unchanged main type findings remain attributed, not reported as a clean
full type run. External reviewer and CI acceptance are separate, still pending.

Complete-stack integration (not this PR in isolation): real four-GPU PP2/DP2/
EP2 and PP4/DP1/EP1 ran ten updates with exact model/optimizer tensor parity,
optimizer graphs and sequential validation. A fresh native PP2/PP4 checkpoint
matrix matched resumed state exactly. These are debug-model contract checks,
not 671B throughput or convergence results.

The final 207-case GPU matrix covers in-place gradients, dense attention, PP/FSDP train/eval graphs, shared-stream backward/capture and fused numerical contracts.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 12, 2026
@sanketpurandare
sanketpurandare force-pushed the dsv3-mxfp8-blocked-activation-scales branch 2 times, most recently from 389cd35 to 1a1ba79 Compare October 13, 2026 01:58
@@ -0,0 +1,126 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this to torchtitan/quantization/mxfp8/tensor.py where we already have a quantize method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the helpers into tensor.py, alongside weight quantization, and removed activation.py.

"MXFP8Linear",
]

# Activation and gradient quantization takes a scaling mode; the 32x32 weight

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not delete this. And lets make sure both weight and activation uses this singleton.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored a shared RCEIL constant for activation casts and the weight-cast contract. AO's weight kernel is RCEIL-only, so the wrapper checks that invariant.

If empty, all Linear modules are converted.
"""
activation_quantization_backend: Literal["cuda", "cutedsl"] = "cuda"
"""Activation cast backend; CuTeDSL requires 128-aligned BF16 matrices."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why even give an option? Why not always choose "cutedsl" - if its only import related issue, we can give a good error message to guide the user/agent to install the right packages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the backend knob. CuTe is now automatic for supported shapes; CUDA is only for unsupported ones, such as KV-A's 576-wide gradient. Its forward input uses CuTe. Missing dependencies raise an installation error, not a fallback. Forward/backward and FSDP capture/replay checks passed.

@anijain2305 anijain2305 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider just making cutedsl the default and not give an option for cuda. Users will not know when to choose which.

@sanketpurandare
sanketpurandare force-pushed the dsv3-mxfp8-blocked-activation-scales branch from 1a1ba79 to b14b77b Compare October 14, 2026 22:02
@sanketpurandare
sanketpurandare force-pushed the dsv3-mxfp8-blocked-activation-scales branch from b14b77b to fc932b4 Compare October 19, 2026 23:44
@sanketpurandare
sanketpurandare removed this pull request from stack #5331 October 20, 2026 15:21
@sanketpurandare
sanketpurandare force-pushed the dsv3-mxfp8-blocked-activation-scales branch from fc932b4 to 2efe864 Compare October 20, 2026 15:22
@sanketpurandare
sanketpurandare removed this pull request from stack #5567 October 23, 2026 21:49
@sanketpurandare
sanketpurandare force-pushed the dsv3-mxfp8-blocked-activation-scales branch from 2efe864 to 7544cfa Compare October 23, 2026 21:49
@sanketpurandare
sanketpurandare marked this pull request as ready for review October 23, 2026 21:51
@pytorch-bot pytorch-bot Bot added ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests labels Oct 23, 2026
@tianyu-l

tianyu-l commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 4m 13s —— View job


Verdict: changes requested. The MXFP8 part addresses @anijain2305's three comments. The main issue is that the PR also bundles about six independent core behavior changes under an MXFP8 title, and one new config field only partly takes effect in GraphTrainer.

(The /pr-review skill isn't installed in this environment, so this review is posted as this comment rather than as a GitHub review with inline comments.)

Blocking

1. Split this PR. The title and scope don't match. Besides the activation-cast change, it changes shared core code that every model uses:

  • LRSchedulersContainer.Config.warmup_start_factor (components/optim/lr_scheduler.py:82)
  • TrainingConfig.cuda_graph_warmup_steps, threaded through Optim and TrainingEngine
  • Sigmoid.Config.compute_dtype (models/common/activation.py)
  • TokenChoiceTopKRouter.Config.routing_weight_dtype, and the router gate type widened from HiMidLoLinear.Config to Linear.Config (models/common/moe/moe.py:184)
  • MoE.Config.center_expert_bias_update, plus a new _MoELike protocol member (moe.py:757)
  • a new MicrobatchWiseLoadBalanceLoss._compute_local_stats override hook (moe.py:572)
  • four 671B MLPerf recipes, overrides/dsv3_mlperf.py, and about 100 lines of MTP docs

Each of these needs its own justification and numerics evidence under the root CLAUDE.md rules ("Protect battle-tested code paths", "Show numerical proof"). A reviewer can't approve the MXFP8 kernel switch without also signing off on router precision and LR-schedule semantics. Suggested split:

  • (a) MXFP8 CuTeDSL activation casts: tensor.py, linear.py, the README and the MXFP8 tests
  • (b) the scheduler and CUDA-graph warmup knobs
  • (c) the router and MoE precision and bias-update knobs
  • (d) the MLPerf recipes, stacked on (a)–(c)

2. cuda_graph_warmup_steps only partly applies in GraphTrainer. GraphTrainingEngine inherits the optimizer construction, so the optimizer graph uses the new config value. Its fwd/bwd wrapper still hard-codes the constant at torchtitan/experiments/graph_trainer/trainer.py:204 (num_warmup_iterations=NUM_CUDA_GRAPH_WARMUP_STEPS). With cuda_graph_warmup_steps=1, the optimizer would capture after one call and fwd/bwd after two, with no warning.

  • Either read the config value there too, or reject or warn for values other than 2 under GraphTrainer.
  • Also, Optim.__init__ still defaults to NUM_CUDA_GRAPH_WARMUP_STEPS while TrainingConfig hard-codes 2. That is two sources of truth for the same default. Consider making the Optim parameter required, since TrainingEngine always passes it.

3. CPU tests may now fail when constructing MXFP8Linear. MXFP8Linear.__init__ now calls _require_cutedsl_activation_quantizers() (quantization/mxfp8/linear.py:362). That raises unless quant._mxfp8_cutedsl_kernels_available is true, and its error message ties that to SM10.x plus the CuTeDSL runtime.

  • The existing CPU test test_mxfp8_linear_loads_stock_checkpoint (tests/unit_tests/cpu/quantization/test_quantization.py:949) builds an MXFP8Linear on CPU. On a runner without the CuTe runtime it will now hit the ImportError.
  • CPU Unit Test was skipped in CI because this is a stacked PR, and the "152 passed" in the description doesn't say what hardware it ran on. Please confirm it passes on a GPU-less runner.
  • The new CPU tests import torchao.prototype.moe_training... without an importorskip guard.

Non-blocking

MXFP8 cast path (tensor.py)
  • Scale shape differs by path. The CuTe path returns 1-D flatten()ed scales, while the CUDA fallback returns the 2-D output of triton_mx_block_rearrange. scaled_mm apparently accepts both, and your end-to-end backward test covers it. Please say in the docstring that scale shape is path-dependent, or flatten both, so a later consumer doesn't rely on one shape.
  • Repeated dependency check. _require_cutedsl_activation_quantizers() runs inspect.signature and the import probes once per MXFP8Linear instance, which is hundreds of times for 671B. It's cheap, but functools.cache makes it run once.
  • Axis naming. tensor.py line 130 transposes the fused kernel's columnwise output (col.t()), but the single-axis 32x1 path at line 149 returns col as is. Presumably AO returns different layouts for the two. A one-line comment would make clear this is intended. The bitwise tests compare .contiguous().flatten(), which checks values, not strides.
  • Old TODO concerns. The removed TODO's concerns are now addressed: 32-row vs 128-row alignment through the per-operand CUDA fallback, and dependency gating at construction. Good.
Router, MoE and LR scheduler
  • Why disable inplace_wgrad_accum on the MLPerf gate? _mlperf_dsv3_model_policy (torchtitan_recipes/models/deepseek_v3.py:86) sets it to False for the rebuilt gate without explaining why. Please add a one-line reason.
  • Redundant normalization. _unbiased_routing_map (overrides/dsv3_mlperf.py:20) divides by a positive per-row constant before topk. That doesn't change the selection, so the division can be dropped. _compute_local_stats then recomputes the same normalization.
  • warmup_start_factor semantics. With 0.0, the first optimizer step runs at lr=0 but still updates the AdamW moments. That is intended for MLPerf; the docstring could say so explicitly.
Recipe questions
  • steps=60 (deepseek_v3.py:235) against total_steps=11996: is the 60 a placeholder for local runs? A recipe named _mlperf that stops at step 60 is surprising.
  • Validator.Config(freq=1, steps=1) (deepseek_v3.py:202) runs validation after every training step. Is that the intended MLPerf cadence?
  • Typos with missing spaces in MTP.md: "explicit16-stage", "sequence4096", "trainGBS15360", "uses256", "top-k8", "scale2.5", "emits576", "its576-wide".
CI

The latest B200 Integration run (10-23) failed 2 tests: kimi_k3_fsdp2_tp2_ep2_pp2_vpp4 and dist_moe_eager_fsdp_ep_pp_cudagraph. Both fail with ValueError: Unexpected keyword arguments with pre-split inputs: loss_results. That is a PP schedule kwarg problem, most likely from the base PR (dsv3-mtp-loss-metrics) rather than this change. The mxfp8_linear_fsdp integration test passed.

Performnace of this fused cute-dsl quantizer is better than cuda, a single API for dense and grouped mxfp8 linears, no need for scale rearrangements since swizzled layouts are directly output.

Consume TorchAO's landed fused dense rowwise/columnwise cast and single-axis
CuTeDSL casts directly, with blocked E8M0 scales and offs=None. Activation casts
live with weight quantization in tensor.py and use a shared RCEIL constant;
the existing square weight kernel's fixed RCEIL contract is explicitly enforced.
Select CuTeDSL automatically for 128-aligned BF16 operands, with no Linear/
converter backend option or saved autograd backend state. Use CUDA MXFP8 plus
blocked-scale rearrangement only for unsupported operand geometry, not missing
dependencies. Report missing AO/CuTeDSL dependencies with installation guidance
before that linear's parameter allocation. Preserve input-save formats,
32x32 RCEIL weight-scale policy, FSDP lifecycle, gradient destinations and
non-owned output behavior. Reject
unsupported required providers instead of padding or silently falling back.
Credit Protonu's #4895 kernel and Aleksandar's single-axis metadata work; only
landed AO #4995 is the runtime dependency.

Add complete PP2/VPP8/DP128 and PP4/VPP4/DP64, EP64 671B/MTP1 MLPerf recipes
using indexed aligned input sources, global strided ordering, GBS 15360/T4096
and fixed GBS 1024 validation. Reuse the earlier validation, MTP and dense-SDPA
interfaces. Include MXFP8 on the shared head, opt into its existing coalesced
training projection. Choose casts per actual operand: KV-A's aligned forward
input uses CuTeDSL, while its unsupported 576-wide output gradient uses CUDA.
The redundant recipe-level module-backend selector is removed.
Storage adapters and warmed checkpoint binding stay outside core TorchTitan.
Preserve current main's nested MLA KV-B projection selector, with an explicit
check that all 62 main/MTP projections retain MXFP8 rather than BF16 inputs.

Match NVIDIA's BF16 router GEMMs/logits/backward boundary, FP32 sigmoid and
selection, BF16 selected weights, unbiased top-8 sequence auxiliary coefficient
0.01, scale 2.5 and uncentered expert-bias update 0.001. Generic defaults remain
unchanged. Preserve FP32 persistent/final updates, BF16 gather/accumulation/
reduction/Adam moments, selective decay 0.033, clipping 1 and the zero-start
LR multipliers 0/.25/.5/.75/1 with a 11996-update cosine horizon.

Both optimizer/training and landed validation CUDA graphs are enabled.
Expose the existing graph wrapper's eager warmup count through TrainingConfig
(default2, production1) for both training and optimizer capture. Keep the
shared pool's landed eval-first readiness gate. Persisted map-dataset sharding
uses the explicit map_dataset_dp_sharding policy from the data PR. Forced
recipes select CF1; learned recipe defaults retain their conservative CF32 scratch
and minimum saved-activation policy. A run-specific wrapper may set measured
scratch/slot limits on the returned config. VMM and GraphTrainer are excluded.
Future router/sequence/CE fusion overrides are intentionally not imported at
this boundary; their integration belongs to the next three separate PRs.

python -m pytest tests/unit_tests/cpu/test_trainer.py tests/unit_tests/cpu/components/test_validator.py tests/unit_tests/cpu/config/test_config_validation.py tests/unit_tests/cpu/models/common/test_dist_moe.py -q -k 'not graph_training'
python -m pytest tests/unit_tests/gpu/quantization/test_mxfp8_linear.py tests/unit_tests/gpu/quantization/test_mxfp8_fsdp.py -q
pre-commit run --all-files

Current owning checks passed169 CPU/config/recipe tests and51 actual GPU
consumer/FSDP tests, including CuTe/CUDA operand parity, FakeTensor metadata,
head in-place accumulation, compiled/captured FSDP lifecycle and exact
backward accumulation. Strict current warmup/MXFP8/MTP/API Sphinx rendering
passed. All non-type lint hooks passed; only unchanged baseline type findings
remained. The complete updated real-PP2/PP4 provider matrix is still pending;
no current throughput or full-cluster convergence claim follows from these
owning correctness checks.
@sanketpurandare
sanketpurandare force-pushed the dsv3-mxfp8-blocked-activation-scales branch from 9a50e7e to ccec948 Compare November 17, 2026 23:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants