Repository navigation
[FlyDSL] [AOT] Assign into FakeTensor slices without reaching HIP on torch 2.9.1 - #7805
zhiding512 wants to merge 1 commit into
Conversation
…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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟢 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_oraten.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
+ #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]>
+ #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]>
|
No activity for 15 days, so this is now labelled |
Summary
The FlyDSL AOT dry run now answers
tensor[index] = valueon 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'sFlyDSL 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):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'srocm/pytorch:…pytorch_release_2.9.1images ship,Tensor.__setitem__(like__getitem__,contiguousandcopy_) takes a device guard in its own Python binding, before the call reaches the dispatcher and FakeTensorMode. With the GPUs hidden, asreplay_envhides them, that guard initializes HIP and raises. The replay reaches it in four places, all assignments through basic indexing:e8m0_shuffle→shuffle_scale:scale_padded[:m, :n] = src, unconditionalinter_dim=384)shuffle_scale_a16w4:scale_padded[:, :k_] = srcpack_int8_to_packed_int4:out[:, 0] = u[:, 0] | (u[:, 4] << 4)build_p2p_table:table[peer] = ptrtorch 2.10 takes no guard there, which is why PR CI passes.
Changes
dry_runstands in forTensor.__setitem__on CUDA FakeTensors under basic indexing: a copy (or fill) into the view itsgetitemstand-in answers, throughaten.copy_/aten.fill_, since theTensor.copy_binding takes the guard too. Any other assignment still goes to the binding; the full replays below reach none.Testing
Host-only replay change, validated GPU-less the way the Nightly runs it (see below); no kernel or GPU behavior changes.
Documentation
Internal AOT build tooling; the new stand-in carries its own docstring.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
e2c82bf
Behavior and intent
Inside
dry_run,tensor[index] = valueon 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 viewgetitemanswers through the aten op instead. Outsidedry_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.run_aotstarts 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.production_jobs(), throughcompile_one_config: 24 ok / 0 failed (Nightly: 0 / 192).PR-specific question
The boundary is which assignments the stand-in takes over: only
tensor[index] = valueon 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_indexmakes the binding raise and passes on torch 2.9.1 and 2.10. The stand-in is patched only insidedry_run(mock.patch.object, restored on exit), so runtime code never sees it.Changed op tests
None.