Skip to content

[FlyDSL] [AOT] Fix the Nightly's FlyDSL AOT replay on torch 2.9.1 (#7805 + #7561) - #7892

Merged
zufayu merged 7 commits into
mainfrom
aot-fix-combined
Nov 13, 2026
Merged

zufayu merged 7 commits into
mainfrom
aot-fix-combined

Conversation

@zhiding512

Copy link
Copy Markdown
Contributor

Summary

The Nightly wheel build has failed in setup.py's FlyDSL AOT step on every run since 2026-10-30. It fails in two different ways, both only on torch 2.9.1: #7805 fixes one and #7561 the other, and either one alone leaves the Nightly red. This PR carries both unchanged on top of current main, so a single squash merge restores the AOT step.

Supersedes #7805 and #7561: their commits are included as they are, and both can be closed once this merges.

Motivation

Nightly runs 42950352070 (02a757f) and 43145799317 (6a80ddd) end with:

AssertionError: [aiter] FlyDSL AOT failures: FlyDSL MOE replay failed for 2 arch(es); FlyDSL MEGA_MOE replay failed; FlyDSL GEMM replay failed for 1 arch(es)

PR CI builds its wheels with torch 2.10 (rocm7.2.4 … pytorch_release_2.10.0), where neither failure occurs, so both show up only in the Nightly.

Changes

No other file changes. The diff against main is exactly the union of the two PRs; the branch holds their commits plus conflict-free merges.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

This is a host-only change to the replay, validated without a GPU the way the Nightly runs it (see below).

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Internal AOT build tooling; both stand-ins carry their own docstrings.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

3b2c798

Behavior and intent

Only inside dry_run: tensor[index] = value on a CUDA FakeTensor with basic indexing (ints, slices, None, ...) no longer goes through torch's binding, whose device guard reaches HIP on torch 2.9.1. And torch.mm(..., out_dtype=) on FakeTensors gets a correct meta rule on torches whose meta_mm lacks out_dtype. Outside dry_run, and for real or non-CUDA tensors, nothing changes. On torch 2.10 the mm backport is a no-op.

Validation and unverified scope

The environment matches how the Nightly runs the AOT step, without docker: torch 2.9.1+rocm7.2.0.lw.git7e1940d4 (the Nightly image's wheel, from repo.radeon.com), triton 3.8.0 (what install_triton.sh installs), flydsl 0.5.0, a clean environment, and the GPUs hidden as replay_env hides them, on a gfx1250 host.

  • Faithfulness: on main d6bda77fe alone, the full MoE and MegaMoE replays reproduce the Nightly's counts exactly: gfx942 348 ok / 870 failed, gfx950 2890 ok / 7944 failed, MegaMoE 0 ok / 192 failed.
  • Full AOT step on d6bda77fe plus both PRs: run_aot as setup.py calls it (GPU_ARCHS="gfx942;gfx950" AITER_AOT_IMPORT=1) exits 0 in 19.5 min with 0 failed in every module:
    • MoE: gfx942 1218 ok, gfx950 10832 ok, bisect 36 sizes with 0 failed;
    • MegaMoE: 192 ok;
    • GEMM: 24024 ok, bisect 26810 sizes with 0 failed;
    • CONV 152, CHUNK_GDN_H 1344, GDN_FUSED_PREFILL 48 and PA_DECODE_PLAN 96 + 96, all ok;
    • FMHA_FP8: 3112 ok and 760 refused by the runtime, as on main.
  • This head (3b2c798 = main d817aeb46 plus both PRs): targeted replays covering one row per failure site all pass: MoE 26/26, MegaMoE 8/8, GEMM bisect 0 failed. The rows are MXFP4 a4w4, a16w4 with inter_dim=384, int4, MXFP8, a MegaMoE profile with mtpr 8192 and epr 48 (8 ranks), and the kimik3 BF16 to FP32 GEMM row. On main the same set fails 26/26, 8/8 and 1.
  • Unit tests: pytest tests/test_flydsl_aot_replay.py gives 22 passed on torch 2.9.1, and 20 passed with 2 skipped on torch 2.10. Against main's dry_run.py, the new tests fail: 11 on torch 2.9.1, and on torch 2.10 the 3 that simulate torch 2.9.1's binding and meta.
  • Full wheel build in the Nightly images (py3.10 and py3.12, on build-only-aiter): aiter-release.yaml run 43252572709 on this branch with release_type=none. It was still queued when this was written.

Unverified here: the Nightly's test job (five op tests on MI300X and MI355, which has not run since 2026-06-22) and promote. Some other torch 2.9.1 bindings with a device guard still reach HIP inside dry_run: Tensor.copy_, ~, and advanced or boolean-mask __setitem__. No current replay reaches them (the full run above has 0 failures), so they are left for a follow-up.

PR-specific question

The boundary is which calls the stand-ins take over. __setitem__ is taken over only for basic-index assignment on CUDA FakeTensors; the mm backport covers only the two dtype overloads, and only on torches whose meta_mm lacks out_dtype; both apply only inside dry_run. The failure mode to guard against is a replay that silently compiles a different kernel set because a stand-in changed semantics. Three pieces of evidence cover it:

  • The full run_aot on torch 2.9.1 replays the same job sets as the Nightly (MoE 1754 rows / 12052 jobs, GEMM 24024 jobs) with 0 failures.
  • test_mm_fallback_still_checks_shape_and_output_dtype shows the backport still rejects invalid shapes and dtypes.
  • test_legacy_mm_meta_is_restored_after_dry_run shows torch's own rules are back after the dry run, including after an exception.

Any call outside the boundary still goes to torch's binding and fails loudly as a replay [FAIL], rather than being silently mis-replayed.

Changed op tests

None. The new tests are in tests/test_flydsl_aot_replay.py, not under op_tests/.

zhiding512 and others added 7 commits November 6, 2026 08:08
On a torch whose meta_mm takes out_dtype, as CI's 2.10 does, the backport
returns before patching anything, so no test entered it and a regression
inside it would stay green until a torch 2.9.1 AOT build hit it. The new
test replaces meta_mm with torch 2.9.1's two-argument signature and makes
the fake rules of mm.dtype and mm.dtype_out fail as they do there, then
checks that the dry run answers an FP32 output, with and without out=,
and that the failure is back once the dry run exits.
…torch 2.9.1

On torch 2.9.1, Tensor.__setitem__ (like __getitem__, contiguous and copy_)
takes a device guard in its own Python binding, before the call reaches the
dispatcher and FakeTensorMode. With the GPUs hidden, as replay_env hides them,
that guard initializes HIP and raises hipErrorNoDevice. The weights the MoE
replay prepares as callers do are assigned through an index: e8m0_shuffle pads
every MXFP4 scale with `padded[:m, :n] = src`, shuffle_scale_a16w4 pads a scale
whose K/32 is not a multiple of 8 with `padded[:, :k] = src`, and the int4
packing writes `out[:, 0] = ...`. MegaMoEV2 fills its peer pointer table with
`table[peer] = ptr`. So the Nightly wheel builds, whose images ship torch
2.9.1, failed 8.7k MoE and all 192 MegaMoE replay jobs. torch 2.10 takes no
guard there, which is why CI passes.

dry_run now stands in for __setitem__ on FakeTensors under basic indexing: a
copy (or fill) into the view getitem answers, through the aten op, since the
Tensor.copy_ binding takes the guard too.

The test that pads a scale in a process with the GPUs hidden fails only on
torch 2.9.1, so a second one simulates the guarded binding and runs the
stand-in on CI's torch as well.

Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	tests/test_flydsl_aot_replay.py
@zhiding512
zhiding512 requested review from a team and a balanced review from Copilot November 12, 2026 16:09
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7892 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the host-side PyTorch 2.9.1 dry-run compatibility changes and accompanying regression tests.

No open issues 🎉

What changed in this PR

Combines #7805 and #7561 to address both PyTorch 2.9.1 compatibility failures in FlyDSL’s nightly ahead-of-time replay. The changes are confined to host-side dry-run tooling and its regression tests.

Changes:

  • Handles basic-index assignment on CUDA FakeTensors without entering PyTorch bindings that initialize HIP.
  • Temporarily supplies missing torch.mm output-dtype metadata support on affected PyTorch versions, restoring the original rules afterward.
  • Adds regression tests for GPU-hidden assignment, FP32 GEMM outputs, validation errors, and rule restoration.
File Description
tests/​test_flydsl_aot_replay.py Adds assignment and GEMM compatibility tests, including simulated legacy behavior.
aiter/​aot/​flydsl/​dry_run.py Adds scoped FakeTensor assignment handling and a conditional mm metadata backport.

Review effort: Balanced

@aiter-bot

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 3b2c79816b35 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Only inside `dry_run`: `tensor[index] = value` on a CUDA FakeTensor with basic indexing (ints, slices, `None`, `...`) no longer goes through torch's binding, whose device guard reaches HIP on torch 2.9.1. And `torch.mm(..., out_dtype=)` on FakeTensors gets a correct meta rule on torches whose `meta_mm` lacks `out_dtype`. Outside `dry_run`, and for real or non-CUDA tensors, nothing changes. On torch 2.10 the `mm` backport is a no-op.

Validation and unverified scope

The environment matches how the Nightly runs the AOT step, without docker: torch `2.9.1+rocm7.2.0.lw.git7e1940d4` (the Nightly image's wheel, from repo.radeon.com), triton 3.8.0 (what `install_triton.sh` installs), flydsl 0.5.0, a clean environment, and the GPUs hidden as `replay_env` hides them, on a gfx1250 host.

- **Faithfulness:** on main `d6bda77fe` alone, the full MoE and MegaMoE replays reproduce the Nightly's counts exactly: gfx942 348 ok / 870 failed, gfx950 2890 ok / 7944 failed, MegaMoE 0 ok / 192 failed.
- **Full AOT step on `d6bda77fe` plus both PRs:** `run_aot` as `setup.py` calls it (`GPU_ARCHS="gfx942;gfx950" AITER_AOT_IMPORT=1`) exits 0 in 19.5 min with 0 failed in every module:
  - MoE: gfx942 1218 ok, gfx950 10832 ok, bisect 36 sizes with 0 failed;
  - MegaMoE: 192 ok;
  - GEMM: 24024 ok, bisect 26810 sizes with 0 failed;
  - CONV 152, CHUNK_GDN_H 1344, GDN_FUSED_PREFILL 48 and PA_DECODE_PLAN 96 + 96, all ok;
  - FMHA_FP8: 3112 ok and 760 refused by the runtime, as on main.
- **This head (`3b2c798` = main `d817aeb46` plus both PRs):** targeted replays covering one row per failure site all pass: MoE 26/26, MegaMoE 8/8, GEMM bisect 0 failed. The rows are MXFP4 a4w4, a16w4 with `inter_dim=384`, int4, MXFP8, a MegaMoE profile with mtpr 8192 and epr 48 (8 ranks), and the kimik3 BF16 to FP32 GEMM row. On main the same set fails 26/26, 8/8 and 1.
- **Unit tests:** `pytest tests/test_flydsl_aot_replay.py` gives 22 passed on torch 2.9.1, and 20 passed with 2 skipped on torch 2.10. Against main's `dry_run.py`, the new tests fail: 11 on torch 2.9.1, and on torch 2.10 the 3 that simulate torch 2.9.1's binding and meta.
- **Full wheel build in the Nightly images** (py3.10 and py3.12, on `build-only-aiter`): [aiter-release.yaml run 43252572709](https://github.com/ROCm/aiter/actions/runs/43252572709) on this branch with `release_type=none`. It was still queued when this was written.

Unverified here: the Nightly's `test` job (five op tests on MI300X and MI355, which has not run since 2026-06-22) and `promote`. Some other torch 2.9.1 bindings with a device guard still reach HIP inside `dry_run`: `Tensor.copy_`, `~`, and advanced or boolean-mask `__setitem__`. No current replay reaches them (the full run above has 0 failures), so they are left for a follow-up.

PR-specific question

The boundary is which calls the stand-ins take over. `__setitem__` is taken over only for basic-index assignment on CUDA FakeTensors; the `mm` backport covers only the two dtype overloads, and only on torches whose `meta_mm` lacks `out_dtype`; both apply only inside `dry_run`. The failure mode to guard against is a replay that silently compiles a different kernel set because a stand-in changed semantics. Three pieces of evidence cover it:

- The full `run_aot` on torch 2.9.1 replays the same job sets as the Nightly (MoE 1754 rows / 12052 jobs, GEMM 24024 jobs) with 0 failures.
- `test_mm_fallback_still_checks_shape_and_output_dtype` shows the backport still rejects invalid shapes and dtypes.
- `test_legacy_mm_meta_is_restored_after_dry_run` shows torch's own rules are back after the dry run, including after an exception.

Any call outside the boundary still goes to torch's binding and fails loudly as a replay `[FAIL]`, rather than being silently mis-replayed.

Changed op tests

None. The new tests are in `tests/test_flydsl_aot_replay.py`, not under `op_tests/`.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@zufayu
zufayu merged commit 9e34d2f into main Nov 13, 2026
@zufayu
zufayu deleted the aot-fix-combined branch November 13, 2026 01:11
@zufayu
zufayu requested a review from coderfeli November 13, 2026 01:29
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
 + #7561) (#7892)

* [FlyDSL] [AOT] Fix mm out_dtype replay on torch 2.9.1

* Test the mm out_dtype backport against a simulated torch 2.9.1 meta

On a torch whose meta_mm takes out_dtype, as CI's 2.10 does, the backport
returns before patching anything, so no test entered it and a regression
inside it would stay green until a torch 2.9.1 AOT build hit it. The new
test replaces meta_mm with torch 2.9.1's two-argument signature and makes
the fake rules of mm.dtype and mm.dtype_out fail as they do there, then
checks that the dry run answers an FP32 output, with and without out=,
and that the failure is back once the dry run exits.

* [FlyDSL] [AOT] Assign into FakeTensor slices without reaching HIP on torch 2.9.1

On torch 2.9.1, Tensor.__setitem__ (like __getitem__, contiguous and copy_)
takes a device guard in its own Python binding, before the call reaches the
dispatcher and FakeTensorMode. With the GPUs hidden, as replay_env hides them,
that guard initializes HIP and raises hipErrorNoDevice. The weights the MoE
replay prepares as callers do are assigned through an index: e8m0_shuffle pads
every MXFP4 scale with `padded[:m, :n] = src`, shuffle_scale_a16w4 pads a scale
whose K/32 is not a multiple of 8 with `padded[:, :k] = src`, and the int4
packing writes `out[:, 0] = ...`. MegaMoEV2 fills its peer pointer table with
`table[peer] = ptr`. So the Nightly wheel builds, whose images ship torch
2.9.1, failed 8.7k MoE and all 192 MegaMoE replay jobs. torch 2.10 takes no
guard there, which is why CI passes.

dry_run now stands in for __setitem__ on FakeTensors under basic indexing: a
copy (or fill) into the view getitem answers, through the aten op, since the
Tensor.copy_ binding takes the guard too.

The test that pads a scale in a process with the GPUs hidden fails only on
torch 2.9.1, so a second one simulates the guarded binding and runs the
stand-in on CI's torch as well.

Co-authored-by: Cursor <[email protected]>

---------

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants