Skip to content

Fix MoE FP8 Triton autotune key - #4880

Merged
vkuzo merged 1 commit into
pytorch:mainfrom
warrendeng:fix-moe-triton-autotune-key
Sep 11, 2026
Merged

vkuzo merged 1 commit into
pytorch:mainfrom
warrendeng:fix-moe-triton-autotune-key

Conversation

@warrendeng

@warrendeng warrendeng commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • replace the stale num_elements autotune key with the kernel K and N shape arguments. num_elements is not actually an argument in the kernel
  • this is functionally a no-op with the current single atomic_kernel_configs_2D configuration. it only makes the metadata valid so newer Triton does not reject the kernel during import

Context

Triton PR triton-lang/triton#11602 validates that every autotune key names a kernel argument. The MoE FP8 transpose cast kernel does not have a num_elements argument, which causes TorchAO import to fail in pytorch/pytorch#190440.

Test plan

  • imported torchao.prototype.moe_training.kernels.float8_rowwise using PyTorch 831416dd0, Triton 4e15616d25, and an NVIDIA H100
  • git diff --check

Authored with assistance from Codex.

@pytorch-bot

pytorch-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4880

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 1bfbab6 with merge base ee0d7ce (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 10, 2026
@warrendeng

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "module: training"

@pytorch-bot pytorch-bot Bot added the module: training quantize_ api training flow label Sep 11, 2026
@warrendeng
warrendeng marked this pull request as ready for review September 11, 2026 00:08
@vkuzo

vkuzo commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Claude finished @vkuzo's task in 39s —— View job


Code Review

  • Read the changed file and diff
  • Verify the new autotune key names valid kernel arguments
  • Check consistency with sibling kernels

LGTM. This is a correct, minimal fix.

The change swaps the stale autotune key on _triton_fp8_rowwise_3d_transpose_cast_rhs_kernel:

-    @triton.autotune(configs=atomic_kernel_configs_2D, key=["num_elements"])
+    @triton.autotune(configs=atomic_kernel_configs_2D, key=["K", "N"])

Verified against torchao/prototype/moe_training/kernels/float8_rowwise.py:211-234:

  • num_elements was never a kernel argument — the parameter list only has E, N, K (float8_rowwise.py:225-227), so the old key was invalid and would be rejected by the Triton validation added in triton-lang/triton#11602.
  • K and N are valid arguments and are the natural shape params to key on for a shape-driven autotuner.
  • Consistent with the sibling kernel — the companion _triton_fp8_rowwise_3d_transpose_scales_rhs_kernel (float8_rowwise.py:136) already uses key=["K", "N"], so the two kernels sharing atomic_kernel_configs_2D now match. All other autotuned kernels in this file also key on shape args (["K", "N"], ["K"]).
  • Functionally a no-op today, as the PR notes: atomic_kernel_configs_2D contains a single config (float8_rowwise.py:34-40), so autotune never actually selects between configs — the key only affects cache metadata. This just makes the metadata valid so import doesn't fail.

Nothing blocking. A couple of optional observations, neither requiring action:

  1. The one CI failure (test-rocm — "Could not load credentials from any providers") is infra/credentials, unrelated to this change.
  2. Since this file has several single-config autotune decorators used purely for metadata, a follow-up could consider dropping @triton.autotune where there's only one config, but that's out of scope here.
    · branch fix-moe-triton-autotune-key

@vkuzo
vkuzo merged commit 9e5ea7f into pytorch:main Sep 11, 2026
22 of 25 checks passed
warrendeng added a commit to pytorch/pytorch that referenced this pull request Sep 12, 2026
Advance the torchao pin through pytorch/ao#4880 so PyTorch CI picks up the corrected MoE FP8 Triton autotune key.

Test Plan:
```
git diff --check
```

Lint was skipped because lintrunner is unavailable in this checkout, as approved.

Generated with assistance from Codex.
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this pull request Sep 12, 2026
Update the torchao pin to include pytorch/ao#4880, fixing the MoE FP8 autotune failure blocking Triton pin update #190440
Pull Request resolved: #196813
Approved by: https://github.com/Skylion007
akoumpa added a commit to NVIDIA-NeMo/Automodel that referenced this pull request Nov 18, 2026
… 3.9

torchao v0.17.0, which the image builds for its MXFP8 kernels, names
"num_elements" in the triton.autotune key of
_triton_fp8_rowwise_3d_transpose_cast_rhs_kernel, but the kernel has no
such argument. Triton 3.9 in the 26.11 base rejects that when
torchao.prototype.moe_training is imported, so the MXFP8 grouped GEMM
resolver failed (tests/unit_tests/moe/test_mxfp8.py). Apply upstream's
fix, pytorch/ao#4880, to the v0.17.0 checkout before building the wheel.
The step accepts the original or the already-patched source only.

Signed-off-by: Alexandros Koumparoulis <[email protected]>
akoumpa added a commit to NVIDIA-NeMo/Automodel that referenced this pull request Nov 19, 2026
* build: bump container to 26.11

Move the PyTorch base to nvcr.io/nvidia/pytorch:26.11-py3 (CUDA 13.5,
PyTorch 2.15.0a0+fd23299, cuDNN 9.28, cuBLAS 13.10, NCCL 2.32.6) and the
CUDA base to cuda-dl-base:26.11-cuda13.5-devel-ubuntu24.04.

Align the PyTorch-container overrides with the 26.11 base: platformdirs
4.12.4 -> 4.14.5 (the base registers its pytest plugin). cuDNN Frontend
stays at 1.30.0: the base's 1.32.0 requires nvidia-cutlass-dsl>=4.8 while
FA4, quack-kernels and ffpa pin 4.6.2. uv-pytorch.lock is regenerated
with uv 0.8.22; only platformdirs changes.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* build(docker): drop the NVGEMM backport now that the base includes it

The 26.11 PyTorch base already contains PyTorch #198292: the backport
patch reverse-applies cleanly to its torch/_inductor/utils.py. Remove the
patch and its apply step, as its header asked once PYTORCH_IMAGE includes
the fix, and keep the import check that the NVGEMM probe tolerates the
FA4/FFPA-compatible CuTe DSL.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* build: build Transformer Engine 2.21.0 in the container

Match the 26.11 base, which ships Transformer Engine 2.21.0. Build TE
from v2.21.0, reuse a base TE only from 2.21.0 on, and require 2.21.0 in
the PyTorch image's native-runtime check.

TE 2.21.0 keeps 2.20.2's runtime requirements (nvidia-cudnn-frontend
>=1.29.0), its FusedAdam implementation that te_patches.py caches is
unchanged, and its EP module exports the same NCCL-EP API.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* build(docker): patch fla's autotune keys for Triton 3.9

Triton 3.9 in the 26.11 base rejects a triton.autotune key that names a
value which is not a kernel argument. fla-core 0.4.2 has two such keys in
fla/ops/cp/chunk_delta_h.py ("STAGE"; "BT" and "USE_EXP2"), so importing
fla failed with "key contains names that are not kernel arguments". The
import runs from nemo_automodel._transformers.infrastructure through the
Kimi K3 model, so every recipe failed at startup in the 26.11 nightly.

Earlier Triton dropped the unknown names, so the patch removes them and
keeps the same tuning keys. The image build applies it to the installed
fla or confirms it is already applied, and rejects any other source. A
scan of all 212 autotune name lists in fla-core 0.4.2 finds no others,
and Automodel's own kernels have none.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* build: move flash-linear-attention to 0.5.2 for Triton 3.9

Triton 3.9 in the 26.11 base removed block pointers: tl.make_block_ptr
and tl.advance now raise NotImplementedError when a kernel compiles.
fla 0.4.2 uses them in 77 files, so its kernels fail at the first launch
(qwen3_5_4b, qwen3_5_35b and nemotron_flash_1b_squad in the 26.11
nightly, on H100 and VR200). fla 0.5.2 is the first release that no
longer uses them (fla-org/flash-linear-attention#1062).

- pyproject.toml: flash-linear-attention>=0.5.2,<0.6. The upper bound
  keeps the lock on the release that the container patch and the CP
  prewarm launches below were written against.
- docker/common/fla-autotune-keys.patch: retarget to fla-core 0.5.2.
  Its merge_fwd_bwd_kernel autotune key still names "BT", which is not
  a kernel argument and which Triton 3.9 rejects at import. The 0.4.2
  keys are gone.
- prewarm.py: fla 0.5.2 renamed the head arguments of the private CP
  kernels (H -> HV in merge_fwd_bwd_kernel; HV added to
  pre_process_bwd_kernel_merged) and replaced USE_EXP2 with USE_BG.
  Without this the prewarm logs a signature drift and skips.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* Update uv lock

Signed-off-by: NeMo Bot <[email protected]>

* fix(moe): skip FSDP's root callback once the backward is finalized

PyTorch 2.15 in the 26.11 base (pytorch/pytorch#196640 and its stack)
records the backward finalization mode when FSDP sees a backward start,
clears it when the root post-backward final callback ends the iteration,
and asserts in that callback that the mode is set.

The pipeline-parallel backward patch calls that private callback by hand.
The MoE path calls it once per FSDP unit, but the units of a stage share
the root's state context, so the second call failed with "Expected
manual backward finalization mode to be set" (step_3.5_flash_hellaswag_pp
in the 26.11 nightly). The same assertion fires when FSDP's own callback
already finalized a last backward under defer_fsdp_grad_sync: false.

Skip the manual callback when the mode is cleared: the iteration is
already finalized, or no backward reached the root. Earlier PyTorch has
no such field, so its behavior is unchanged.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* fix(pipelining): keep stock recv buffers when PyTorch allocates them JIT

PyTorch 2.15 in the 26.11 base (pytorch/pytorch#196463) allocates each
pipeline receive buffer just before its receive and hands it to the stage
computation, instead of preallocating one buffer set per microbatch. The
opt-in recv-buffer pools then have nothing to save: the ordinary 1F1B ring
aliases receive descriptors that no longer own long-lived buffers, and the
interleaved pool's owned copies only add memory. Both installers now keep
the stock buffers when torch.distributed.pipelining._recv_buffers exists.

The pool unit tests pin the probe for the fake stage layouts, skip the
real-PyTorch parity and negative-control runs under just-in-time buffers
(the negative control can no longer corrupt a reused buffer), and the
interleaved schedule harness sets the PyTorch 2.15 runtime defaults it
skips by bypassing __init__ (_unshard_lookahead, _defer_reduce_grad_wait,
_max_outstanding_sends).

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* build(docker): backport torchao's MoE FP8 autotune key fix for Triton 3.9

torchao v0.17.0, which the image builds for its MXFP8 kernels, names
"num_elements" in the triton.autotune key of
_triton_fp8_rowwise_3d_transpose_cast_rhs_kernel, but the kernel has no
such argument. Triton 3.9 in the 26.11 base rejects that when
torchao.prototype.moe_training is imported, so the MXFP8 grouped GEMM
resolver failed (tests/unit_tests/moe/test_mxfp8.py). Apply upstream's
fix, pytorch/ao#4880, to the v0.17.0 checkout before building the wheel.
The step accepts the original or the already-patched source only.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* ci(recipes): give nemotron_nano_v3_hellaswag 50 minutes in CI

Its nightly checkpoint-robustness job finished in 39.6 of its 40 minutes
on the 26.10 image. On 26.11 it trains with the same loss trajectory but
about 3% slower (93K vs 96K tokens/s), so it hit the Slurm time limit in
the automodel_reload phase in both 26.11 nightlies.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* test(ci): list the torchao patch among the container dependency inputs

The wheel-builder stage now copies docker/common/torchao-autotune-key.patch. prepare-container-dependencies.sh already fingerprints all of docker/, so only the test's explicit input list was missing it.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* test(optim): name the leaked types when the cyclic-garbage check fails

test_backward_leaves_no_cyclic_garbage failed in the 26.11 L0 CPU job
(1423 and 1420 unreachable objects in two runs) but passes alone in the
26.11 image, with and without a GPU, with coverage, and with the whole
tests/unit_tests/optim directory in one process. Some test that shares
its xdist worker leaves state behind. Report the collected object types
in the assertion so the next failure identifies the source.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* test(pipelining): skip interleaved pool parity when receives are JIT

The functional parity test asserts that installing the interleaved recv
pool leaves fewer receive descriptors than microbatches, and the 4-GPU
negative control expects corruption once the owned input copies are
removed. With PyTorch 2.15 (26.11), which allocates receive buffers just
in time, the installer keeps the stock buffers, so neither assertion
applies (L2_Distributed on H100 and GB200). Gate the module on the same
probe the unit tests use.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* test(optim): drain earlier tests' garbage before the cyclic-garbage check

On PyTorch 2.15 (26.11), the Dynamo tracing state of an earlier
torch.compile test in the same process (test_tp_linear, test_dsv4_layers,
test_experts or test_swiglu_triton) is released in two stages: the first
gc.collect() runs a finalizer that drops the last reference to another
cycle, which only the next collection finds. The single baseline collect
left those 168 to 1420 objects (FakeTensor, SymNode and fx.Node graphs,
traceback.FrameSummary) to the measured window, so the check failed
whenever such a test ran first in the xdist worker. Collect until nothing
is left before measuring; the check still covers every cycle the sketch
backward creates.

Signed-off-by: Alexandros Koumparoulis <[email protected]>

* test(pipelining): check interleaved parity with native JIT receives

Signed-off-by: Alexandros Koumparoulis <[email protected]>

---------

Signed-off-by: Alexandros Koumparoulis <[email protected]>
Signed-off-by: NeMo Bot <[email protected]>
Co-authored-by: NeMo Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: training quantize_ api training flow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants