Skip to content

[FlyDSL] [AOT] Assign into FakeTensor slices without reaching HIP on torch 2.9.1 - #7805

Open
zhiding512 wants to merge 1 commit into
mainfrom
zhiding512/fix-aot-dry-run-setitem-torch291
Open

zhiding512 wants to merge 1 commit into
mainfrom
zhiding512/fix-aot-dry-run-setitem-torch291

Conversation

@zhiding512

@zhiding512 zhiding512 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The FlyDSL AOT dry run now answers tensor[index] = value on FakeTensors without reaching HIP on torch 2.9.1, the torch the Nightly wheel build runs. This fixes the MoE and MegaMoE parts of the Nightly's FlyDSL AOT failures; #7561 fixes the remaining GEMM part.

Motivation

The Nightly build has failed at setup.py's FlyDSL AOT step on every run since at least 2026-10-29 (for example run 42554492182):

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)

Every MoE failure (870 on gfx942, 7876 on gfx950) and every MegaMoE failure (192 of 192) is torch.AcceleratorError: HIP error: no ROCm-capable device is detected. On torch 2.9.1, which the Nightly's rocm/pytorch:…pytorch_release_2.9.1 images ship, 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. The replay reaches it in four places, all assignments through basic indexing:

Replay jobs Assignment
every a4w4 and MXFP8 row e8m0_shuffle → shuffle_scale: scale_padded[:m, :n] = src, unconditional
a16w4 / a8w4 rows whose K/32 is not a multiple of 8 (e.g. inter_dim=384) shuffle_scale_a16w4: scale_padded[:, :k_] = src
every int4 row pack_int8_to_packed_int4: out[:, 0] = u[:, 0] | (u[:, 4] << 4)
every MegaMoE rank build_p2p_table: table[peer] = ptr

torch 2.10 takes no guard there, which is why PR CI passes.

Changes

  • dry_run stands in for Tensor.__setitem__ on CUDA FakeTensors under basic indexing: a copy (or fill) into the view its getitem stand-in answers, through aten.copy_ / aten.fill_, since the Tensor.copy_ binding takes the guard too. Any other assignment still goes to the binding; the full replays below reach none.
  • Two tests. One pads a real MXFP4 scale in a process with the GPUs hidden, which fails only on torch 2.9.1. The other simulates the guarded binding, so the stand-in runs on CI's torch 2.10 as well and the test fails on any torch without it.

Testing

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

Host-only replay change, validated GPU-less the way the Nightly runs it (see below); no kernel or GPU behavior changes.

Documentation

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

Internal AOT build tooling; the new stand-in carries its own docstring.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

e2c82bf

Behavior and intent

Inside dry_run, tensor[index] = value on a CUDA FakeTensor under basic indexing (ints, slices, None, ...) no longer goes through the torch binding, whose device guard initializes HIP on torch 2.9.1 and fails with the GPUs hidden. It assigns into the same view getitem answers through the aten op instead. Outside dry_run, and for real or non-CUDA tensors, nothing changes.

Validation and unverified scope

Environment as the Nightly runs it: latest main (1350def) + this change, torch 2.9.1+rocm7.2.0.lw.git7e1940d4 (the AMD wheel of the Nightly images), flydsl 0.5.0 (main's pin), GPUs hidden (HIP_VISIBLE_DEVICES= ROCR_VISIBLE_DEVICES= CUDA_VISIBLE_DEVICES=), on a gfx950 host.

  • pytest tests/test_flydsl_aot_replay.py: 13 passed on torch 2.9.1 and on torch 2.10. Without the change, the simulated-binding test fails on both, and the GPU-hidden padding test fails on torch 2.9.1.
  • Full MoE replay as run_aot starts it, GPU_ARCHS="gfx942;gfx950": gfx942 1218 ok / 0 failed (Nightly: 348 / 870); gfx950 10832 ok / 0 failed, 1 runtime refusal (Nightly: 2850 / 7876); bisect 36 token counts, 0 failed.
  • MegaMoE: rank 0 of each of the 24 (profile, max tokens per rank) pairs of production_jobs(), through compile_one_config: 24 ok / 0 failed (Nightly: 0 / 192).
  • Unverified: the other MegaMoE ranks (rank is a compile-time integer on the same host path); the complete wheel build in the Nightly container (triton 3.8.0 there, 3.7.0 here); the GEMM failure, which [FlyDSL] [AOT] Fix mm out_dtype replay on torch 2.9.1 #7561 addresses.

PR-specific question

The boundary is which assignments the stand-in takes over: only tensor[index] = value on a CUDA FakeTensor whose index is basic (ints, slices, None, ...). Advanced or mixed indices, and real or non-CUDA tensors, still go to the torch binding, so on torch 2.9.1 an advanced-index assignment on a CUDA FakeTensor would still raise hipErrorNoDevice, as a replay [FAIL] rather than a silent miss. Evidence that the replays reach no such assignment: the full MoE replay (12,052 jobs on gfx942 + gfx950) and the MegaMoE rank-0 replays above finish with 0 failures on torch 2.9.1 with the GPUs hidden. Evidence for the basic forms: test_the_dry_run_answers_an_assignment_through_an_index makes the binding raise and passes on torch 2.9.1 and 2.10. The stand-in is patched only inside dry_run (mock.patch.object, restored on exit), so runtime code never sees it.

Changed op tests

None.

…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]>
@zhiding512
zhiding512 requested review from a team and a balanced review from Copilot November 11, 2026 06:26
@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 7805 --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.

@aiter-bot

aiter-bot commented Nov 11, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision e2c82bfd72b3 · 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

Inside `dry_run`, `tensor[index] = value` on a CUDA FakeTensor under basic indexing (ints, slices, `None`, `...`) no longer goes through the torch binding, whose device guard initializes HIP on torch 2.9.1 and fails with the GPUs hidden. It assigns into the same view `getitem` answers through the aten op instead. Outside `dry_run`, and for real or non-CUDA tensors, nothing changes.

Validation and unverified scope

Environment as the Nightly runs it: latest main (1350defcf) + this change, torch `2.9.1+rocm7.2.0.lw.git7e1940d4` (the AMD wheel of the Nightly images), flydsl 0.5.0 (main's pin), GPUs hidden (`HIP_VISIBLE_DEVICES= ROCR_VISIBLE_DEVICES= CUDA_VISIBLE_DEVICES=`), on a gfx950 host.

- `pytest tests/test_flydsl_aot_replay.py`: 13 passed on torch 2.9.1 and on torch 2.10. Without the change, the simulated-binding test fails on both, and the GPU-hidden padding test fails on torch 2.9.1.
- Full MoE replay as `run_aot` starts it, `GPU_ARCHS="gfx942;gfx950"`: gfx942 1218 ok / 0 failed (Nightly: 348 / 870); gfx950 10832 ok / 0 failed, 1 runtime refusal (Nightly: 2850 / 7876); bisect 36 token counts, 0 failed.
- MegaMoE: rank 0 of each of the 24 (profile, max tokens per rank) pairs of `production_jobs()`, through `compile_one_config`: 24 ok / 0 failed (Nightly: 0 / 192).
- Unverified: the other MegaMoE ranks (rank is a compile-time integer on the same host path); the complete wheel build in the Nightly container (triton 3.8.0 there, 3.7.0 here); the GEMM failure, which #7561 addresses.

PR-specific question

The boundary is which assignments the stand-in takes over: only `tensor[index] = value` on a CUDA FakeTensor whose index is basic (ints, slices, `None`, `...`). Advanced or mixed indices, and real or non-CUDA tensors, still go to the torch binding, so on torch 2.9.1 an advanced-index assignment on a CUDA FakeTensor would still raise hipErrorNoDevice, as a replay `[FAIL]` rather than a silent miss. Evidence that the replays reach no such assignment: the full MoE replay (12,052 jobs on gfx942 + gfx950) and the MegaMoE rank-0 replays above finish with 0 failures on torch 2.9.1 with the GPUs hidden. Evidence for the basic forms: `test_the_dry_run_answers_an_assignment_through_an_index` makes the binding raise and passes on torch 2.9.1 and 2.10. The stand-in is patched only inside `dry_run` (`mock.patch.object`, restored on exit), so runtime code never sees it.

Changed op tests

None.

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.

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 CUDA FakeTensor dry-run assignment changes.

No open issues 🎉

What changed in this PR

Fixes FlyDSL AOT dry-run assignments on CUDA FakeTensors so MoE and MegaMoE replay can run with GPUs hidden on PyTorch 2.9.1. The separate GEMM replay failure is addressed by #7561.

Changes:

  • Handles basic indexed assignments through aten.copy_ or aten.fill_, bypassing guarded tensor bindings during dry runs.
  • Preserves the original assignment binding for real tensors, non-CUDA tensors, and unsupported indexing.
  • Adds GPU-hidden scale-padding coverage and a simulated guarded-binding regression test.
File Description
tests/​test_flydsl_aot_replay.py Adds regression tests for indexed assignments without GPU access.
aiter/​aot/​flydsl/​dry_run.py Temporarily intercepts CUDA FakeTensor indexed assignments during replay.

Review effort: Balanced

zufayu 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]>
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]>
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 27, 2026

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

FlyDSL stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants