Repository navigation
[FlyDSL] [AOT] Fix mm out_dtype replay on torch 2.9.1 - #7561
zhiding512 wants to merge 3 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
@aiter-bot review |
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the FlyDSL AOT replay compatibility change.
No open issues 🎉
What changed in this PR
Fixes FlyDSL AOT replay on affected PyTorch 2.9.1 ROCm wheels when untuned GEMMs fall back to torch.mm with out_dtype.
Changes:
- Adds temporary FakeTensor rules for
mm.dtypeandmm.dtype_outwhen the installed meta implementation lacksout_dtypesupport. - Restores the original rules and clears cached fake outputs on normal and exceptional exit, leaving real GEMM execution unchanged.
- Adds regression tests for FP32 outputs, output identity, validation errors, and restoration after replay.
| File | Description |
|---|---|
| tests/test_flydsl_aot_replay.py | Adds dtype fallback and restoration regression tests. |
| aiter/aot/flydsl/dry_run.py | Adds the compatibility context and enables it during dry-run replay. |
Review effort: Balanced
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #7561 — [FlyDSL] [AOT] Fix mm out_dtype replay on torch 2.9.1
Review (advisory):
Validation (deterministic): NOT RUN — the PR changes runtime code but ships no test target; the changed path is executed AOT-replay-time code, not a data-only diff, and its regression tests ship in tests/test_flydsl_aot_replay.py, which CI collects via pytest -q tests but the validator does not sample, so no target existed to run
Perf (advisory): NOT RUN — no perf target for the same reason there is no test target: the PR changes runtime code but ships no test target; the patch is scoped to dry_run's context and inactive in the serving path, so no serving-path latency exists to measure
1 finding(s) posted inline, on the lines they are about:
aiter/aot/flydsl/dry_run.py:145-150— On the torch CI runs (2.10.0, where meta_mm already carries out_dtype) the guard at…
| if ( | ||
| not hasattr(torch.ops.aten.mm, "dtype") | ||
| or "out_dtype" in inspect.signature(meta_mm).parameters | ||
| ): | ||
| yield | ||
| return |
There was a problem hiding this comment.
📝 [verified] On the torch CI runs (2.10.0, where meta_mm already carries out_dtype) the guard at aiter/aot/flydsl/dry_run.py:145-150 makes _mm_dtype_meta a no-op, so the patch branch this PR adds is never entered by the new tests — test_mm_fallback_with_fp32_output_under_dry_run passes through torch's own meta and test_legacy_mm_meta_is_restored_after_dry_run skips — and a later regression inside the patch code would stay green in CI until a torch 2.9.1 AOT image run hits it. Reviewer should ask for one test that simulates the legacy 2-arg meta_mm (the same signature the guard probes) so the patch branch is exercised on every torch.
There was a problem hiding this comment.
Added test_mm_dtype_backport_runs_against_a_simulated_legacy_meta in df6de62. It replaces meta_mm with torch 2.9.1's two-argument signature and makes the mm.dtype / mm.dtype_out fake rules fail as they do there, so the backport runs, and its restoration is checked, on torch 2.10 as well. On torch 2.10 it fails when the backport registers no fake rule.
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.
NOT 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.
🔵 Needs a closer look
The shim modifies PyTorch’s private FakeTensor registry and cache, requiring runtime validation across affected 2.9.1 wheels and newer versions that this dependency-free review environment cannot independently perform.
No open issues 🎉
Review effort: Balanced
|
ci failed |
1 similar comment
|
ci failed |
Co-authored-by: Cursor <[email protected]> # Conflicts: # tests/test_flydsl_aot_replay.py
+ #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]>
|
Superseded by #7892, which merged the mm out_dtype replay fix and regression tests from this PR into main. Closing this duplicate PR. The Nightly wheel packaging failure (Git dubious ownership at /workspace) is a separate CI issue and remains under follow-up; this closure does not mark Nightly healthy. |
Summary
Fix FlyDSL GEMM AOT replay on the Nightly ROCm 7.2 / PyTorch 2.9.1 images. An untuned BF16 GEMM that falls back to
torch.mm(..., out_dtype=torch.float32, out=out)now produces the correct FakeTensor output instead of failing withTypeError: meta_mm() takes 2 positional arguments but 3 were given.Motivation
These torch wheels expose
aten.mm.dtypeandaten.mm.dtype_out, but their registeredmeta_mm(a, b)does not accept the output-dtype argument. The single tuned M=56 row below succeeds at its tuned size; probing the M=1 it covers finds no tuned config and reaches this broken torch meta implementation:Before this fix the CLI reports one successful tuned replay, then
[BISECT] 1 sizes inside rows' ranges, 1 failed, and exits 1. With this fix both sizes succeed and the CLI exits 0.Changes
out_dtypeparameter by inspecting the torch meta function's signature.dry_run, temporarily supply FakeTensor rules for the two dtype overloads, using PyTorch 2.10's shape and output-dtype validation and preservingoutidentity throughout_wrapper(exact_dtype=True).out, invalid shapes/dtypes, and restoration after replay.meta_mmand its failure, so the backport and its restoration are exercised on every torch, including CI's 2.10, where the guard otherwise skips the backport.Testing
Documentation
The helper's docstring explains the wheel incompatibility and the scope of the temporary rule. The public GEMM API and the documented AOT command remain the same.
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
08f247123cb7e2d51f12834992580e1b657bfc2dBehavior and intent
The M=1 probe continues through GEMM's original torch fallback. Only its FakeTensor metadata implementation is supplied during AOT replay; real CPU/CUDA GEMM dispatch and arithmetic keep their original implementation. Dimension and dtype errors still fail the replay.
Validation and unverified scope
Validated on a MI355X node, with GPUs hidden during replay:
rocm/pytorch:rocm7.2_ubuntu22.04_py3.10_pytorch_release_2.9.1rocm/pytorch:rocm7.2_ubuntu24.04_py3.12_pytorch_release_2.9.1Both contain
torch 2.9.1+rocm7.2.0.git7e1940d4. On failure SHA0be9de16plus this fix,pytest tests/test_flydsl_aot_replay.py -qpasses 14 tests in each image. The one-row original AITER replay also passes in both images, with a fresh cache:Result: tuned M=56 succeeds, the M=1 probe succeeds,
[BISECT] ... 0 failed, exit 0. The single-row CLI was repeated at0bd238e5in the Py3.10 image, with the same results. On this PR head (df6de622, which only adds a test),pytest tests/test_flydsl_aot_replay.py -qpasses 16 tests in each image.On this PR head with torch 2.10 (CI's),
pytest tests/test_flydsl_aot_replay.py tests/test_aot_drivers.py -qpasses 20 tests and 2 subtests, with the two legacy-only restoration cases skipped. There,test_mm_dtype_backport_runs_against_a_simulated_legacy_metaruns the backport, and it fails when the backport registers no fake rule. Ruff, Black andgit diff --checkpass.After merging main (
1350defcf) into this branch (08f24712; the only conflict was both sides appending tests at the end oftests/test_flydsl_aot_replay.py, resolved by keeping both),pytest tests/test_flydsl_aot_replay.py -qpasses 20 tests on torch2.9.1+rocm7.2.0.git7e1940d4with main's flydsl 0.5.0, and 18 with the 2 legacy-only cases skipped on torch 2.10, GPUs hidden. Replaying all seven gfx950 N=896 K=7168 FP32-output rows ofkimik3_bf16_tuned_gemm.csvwith the CLI above gives 7 ok and[BISECT] 7 sizes inside rows' ranges, 0 failed; on main without this PR the same replay fails the M=1 probe withTypeError: meta_mm. The earlier red Standard Tests shard (NameError: name 'DROPPED_ROUTE_ROW' is not definedinmoe_contiguous_psum.py) came from the old base, which had #7494 but not its fix #7583; the merge picks that fix up.Full AOT and wheel builds were not run. Performance benchmarks and other GPU models are outside this metadata compatibility change; the targeted replay executes no GPU kernels.
PR-specific question
How is behavior outside replay restored? The fake implementation dictionary is restored by the context manager, and cached fake outputs are cleared when entering and leaving it. The regression tests confirm that the original torch 2.9.1 TypeError returns outside
dry_run, including after an exception in its body. A test that simulates torch 2.9.1's meta checks the same on every torch.Changed op tests
None.