Skip to content

[JIT] [fix] Treat runtime GPU architecture as a compile-time constant under torch.compile - #7741

Open
lauri9 wants to merge 5 commits into
ROCm:mainfrom
lauri9:fix/jit-runtime-arch-fullgraph
Open

lauri9 wants to merge 5 commits into
ROCm:mainfrom
lauri9:fix/jit-runtime-arch-fullgraph

Conversation

@lauri9

@lauri9 lauri9 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Mark get_gfx_runtime() with torch.compiler.assume_constant_result, so TorchDynamo evaluates the live GPU architecture once at trace time and treats the result as a constant instead of tracing into the rocminfo probe. This removes the runtime architecture probe as a blocker for torch.compile(fullgraph=True). The bf16/fp16 public attention cases listed below compile through the existing non-FlyDSL fallback backends. FlyDSL FP8 attention remains outside this claim: on FlyDSL 0.5.0 with PyTorch 2.13 and MI350X, tracing still fails in FlyDSL's own architecture probe.

Motivation

With FlyDSL installed, torch.compile(fullgraph=True) over aiter.flash_attn_varlen_func fails on the first call:

torch._dynamo.exc.Unsupported: Attempted to call function marked as skipped
  Explanation: Dynamo does not know how to trace the builtin `posix.stat.`

The call chain is flash_attn_varlen_func -> flydsl_flash_attn_varlen_fwd (aiter/ops/flydsl/fmha_kernels.py) -> get_gfx_runtime() -> _detect_native() -> _gpu_info_output() -> executable_path("rocminfo") -> shutil.which -> posix.stat. Dynamo ignores functools.lru_cache wrappers and traces the wrapped function, so warming the cache in eager mode does not help. The probe runs before the FlyDSL eligibility checks, so it also blocks requests that would otherwise fall through to CK, such as fp16.

Changes

  • aiter/jit/utils/chip_info.py: decorate get_gfx_runtime() with torch.compiler.assume_constant_result beneath the existing functools.lru_cache. The function already returns one process-wide cached value, so baking it into the graph does not change behavior. Build tooling imports chip_info where PyTorch can be absent, so the import falls back to an identity decorator. This mirrors the ImportError fallback in torch_guard.torch_compile_guard.
  • op_tests/test_build_targets_architecture.py: add a fullgraph=True regression test that runs with cold and warm probe caches.

The pattern already exists in AITER. torch.compiler.assume_constant_result marks device- and config-derived values as compile-time constants in aiter/ops/gemm_op_a6w6.py (_compiled_is_gfx950_device, _compiled_gemm_a6w6_configs), aiter/ops/gemm_op_a6w4.py, aiter/ops/gemm_op_a4w6.py, aiter/ops/triton/attention/sol_attn_pool.py, and aiter/ops/triton/attention/sol_tilt.py.

Eager behavior, GPU_ARCHS handling (runtime detection still ignores it), the AITER_AOT_REPLAY path, exact identities such as gfx1250-strict, and get_gfx_runtime_for_device() are unchanged.

Testing

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

Tested on MI350X (gfx950). Performance is not applicable: no kernel or dispatch change, and the eager path returns the same cached value.

Documentation

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

get_gfx_runtime() keeps its documented contract; only its behavior under tracing changes.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

e2ce134

Behavior and intent

Before this change, Dynamo traces the runtime architecture probe through shutil.which and subprocess.run. With torch.compile(fullgraph=True), this fails on posix.stat, even after an eager warm-up, because Dynamo ignores the lru_cache wrapper. The constant-result marker makes Dynamo evaluate get_gfx_runtime() at trace time and insert the architecture without an architecture guard. This removes that probe as a tracing blocker; the validated public attention cases use the existing non-FlyDSL fallback backends. It does not establish fullgraph support for FlyDSL FP8 attention.

The compiled graph assumes that the architecture remains fixed. Eager caching is unchanged, but cache_clear() does not invalidate existing compiled code; a changed architecture requires a fresh trace. The docstring now states this contract and explains the expected Dynamo warning about the lru_cache wrapper. Since the previous reviewed revision, 90d2c308, the only source changes are this documentation and test cleanup: each probe cleanup is registered once, and Dynamo is reset after the test, including on failure. Each cold/warm subtest still resets Dynamo and clears the probe caches before tracing. No kernel or dispatch logic changed in these two follow-up commits.

Validation and unverified scope

Local environment: amdsiloai/pytorch-xdit-staging:b69c7a4-temp, PyTorch 2.13.0+git3369fa2, HIP 7.18.26443, FlyDSL 0.5.0, Triton 3.8.0, one AMD Instinct MI350X (gfx950). GPU runs used /opt/brr/brr run --gpus 1 inside Docker.

  • Test cleanup validation: python -m pytest -q op_tests/test_build_targets_architecture.py passed with 31 tests, 52 subtests, and one expected Dynamo lru_cache warning. This run used the final test implementation before the docstring-only addition; no executable helper code changed afterward.
  • Final file contents: python -m black --check aiter/jit/utils/chip_info.py op_tests/test_build_targets_architecture.py (26.3.0) and python -m ruff check --no-cache aiter/jit/utils/chip_info.py op_tests/test_build_targets_architecture.py (0.15.7) both passed in Docker.
  • Earlier regression evidence at 90d2c308: the architecture test file passed with 31 tests. At the test-only parent, 33e6ca847, the new regression failed in both warm=False and warm=True subtests because Dynamo could not trace posix.stat.
  • Earlier public API validation at 90d2c308: torch.compile(fullgraph=True) with Inductor, triton.cudagraphs=False, three fresh inputs per case, and exact (rtol=0, atol=0) eager comparisons passed all 8 cases: flash_attn_varlen_func for (bf16, 128, 128), (fp16, 128, 128), and (bf16, 192, 128), each with return_lse True and False, plus flash_attn_func bf16 128 with both return_lse values. These cases fall through to non-FlyDSL backends. The first case failed on the baseline with posix.stat. These public API checks were not rerun for the documentation and cleanup commits.
  • Earlier no-PyTorch validation at 90d2c308: chip_info imported with PyTorch unavailable, strict AOT replay returned gfx1250-strict, the offline build target was [("gfx1250-strict", 256)], and no torch module loaded. This check was not rerun for the documentation and cleanup commits.
  • Remaining FP8 failure reproduced at 90d2c308: public causal varlen attention with FP8 e4m3, head dimension 128, fullgraph=True, and backend="eager" fails in FlyDSL's own architecture probe at _thread.allocate_lock inside subprocess.check_output. Removing the constant-result marker restores the earlier posix.stat failure. This confirms the separate blocker on FlyDSL 0.5.0 and PyTorch 2.13.
  • GitHub checks at this update: Black, Ruff, Check Repository Dependency, Aiter Test Gate, and OPUS Tests (MI350X DPX) passed. The latest Aiter wheel-build job was still queued; CI was not yet complete.

Unverified locally: gfx942/MI300X, gfx1250 hardware, the Windows hipinfo/Torch fallback, PyTorch versions other than 2.13, and compiled runs with CUDA graphs enabled. Other compiled callers of get_gfx_runtime() were not exercised individually. FlyDSL FP8 fullgraph execution has the known failure above.

PR-specific question

What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?

Dependency: none added. The torch.compiler import falls back to an identity decorator when PyTorch is unavailable; the earlier no-PyTorch check covers that path. JIT build behavior and cache keys are unchanged: build paths use get_gfx() and GPU_ARCHS, which this PR does not modify.

Compilation: Dynamo evaluates get_gfx_runtime() at trace time and inserts the result without an architecture guard. Python cache clearing does not update an existing graph. The test clears the get_gfx_runtime, _detect_native, and _gpu_info_output caches before each subtest, then compiles once with cold caches and once after an eager warm-up. Both cases fail before the marker and pass with it; the cleanup revision also passed both cases. Final cleanup clears all three probe caches and resets Dynamo.

Build-cache evidence comes from the earlier public API validation at 90d2c308: the first run used a fresh worktree with an empty aiter/jit/build and built the required modules, then a rerun passed with those artifacts cached. The two follow-up commits change only documentation and test cleanup, so the build-cache checks were not repeated.

Changed op tests

op_tests/test_build_targets_architecture.py adds TestRuntimeArchitecture.test_runtime_arch_fullgraph_with_cold_and_warm_caches. It compiles an architecture-dependent branch with torch.compile(backend="eager", fullgraph=True), checks the exact architecture string and tensor result against eager, and covers both cold and warm probe caches. The CPU tensor and eager compiler backend isolate Dynamo tracing from kernel compilation. The test still needs a live GPU for real architecture detection and skips without one.

The existing tests exercise eager detection and mocks; they do not trace the real probe and cannot detect this graph break. The added cleanup registers each probe once and resets Dynamo after the test, while retaining the per-subtest resets needed for independent cold/warm cases. The final test implementation passed in the full architecture test file: 31 tests and 52 subtests.

@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 7741 --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.

@lauri9
lauri9 force-pushed the fix/jit-runtime-arch-fullgraph branch from e443633 to 90d2c30 Compare November 25, 2026 07:48
@lauri9 lauri9 changed the title Fix/jit runtime arch fullgraph [fix] Treat runtime GPU architecture as a compile-time constant under torch.compile Nov 25, 2026
@lauri9
lauri9 requested a review from amd-bartgips November 25, 2026 08:19
@SamiAario-AMD SamiAario-AMD self-assigned this Dec 2, 2026
Comment thread aiter/jit/utils/chip_info.py Resolved
Comment thread aiter/jit/utils/chip_info.py Resolved
@lauri9
lauri9 marked this pull request as ready for review December 2, 2026 15:02
@lauri9
lauri9 requested a review from a team December 2, 2026 15:02
@github-actions github-actions Bot changed the title [fix] Treat runtime GPU architecture as a compile-time constant under torch.compile [JIT] [fix] Treat runtime GPU architecture as a compile-time constant under torch.compile Dec 2, 2026
@github-actions github-actions Bot added the JIT label Dec 2, 2026
@aiter-bot

aiter-bot commented Dec 2, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

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

Before this change, Dynamo traces the runtime architecture probe through `shutil.which` and `subprocess.run`. With `torch.compile(fullgraph=True)`, this fails on `posix.stat`, even after an eager warm-up, because Dynamo ignores the `lru_cache` wrapper. The constant-result marker makes Dynamo evaluate `get_gfx_runtime()` at trace time and insert the architecture without an architecture guard. This removes that probe as a tracing blocker; the validated public attention cases use the existing non-FlyDSL fallback backends. It does not establish fullgraph support for FlyDSL FP8 attention.

The compiled graph assumes that the architecture remains fixed. Eager caching is unchanged, but `cache_clear()` does not invalidate existing compiled code; a changed architecture requires a fresh trace. The docstring now states this contract and explains the expected Dynamo warning about the `lru_cache` wrapper. Since the previous reviewed revision, `90d2c308`, the only source changes are this documentation and test cleanup: each probe cleanup is registered once, and Dynamo is reset after the test, including on failure. Each cold/warm subtest still resets Dynamo and clears the probe caches before tracing. No kernel or dispatch logic changed in these two follow-up commits.

Validation and unverified scope

Local environment: `amdsiloai/pytorch-xdit-staging:b69c7a4-temp`, PyTorch `2.13.0+git3369fa2`, HIP `7.18.26443`, FlyDSL 0.5.0, Triton 3.8.0, one AMD Instinct MI350X (gfx950). GPU runs used `/opt/brr/brr run --gpus 1` inside Docker.

- Test cleanup validation: `python -m pytest -q op_tests/test_build_targets_architecture.py` passed with 31 tests, 52 subtests, and one expected Dynamo `lru_cache` warning. This run used the final test implementation before the docstring-only addition; no executable helper code changed afterward.
- Final file contents: `python -m black --check aiter/jit/utils/chip_info.py op_tests/test_build_targets_architecture.py` (26.3.0) and `python -m ruff check --no-cache aiter/jit/utils/chip_info.py op_tests/test_build_targets_architecture.py` (0.15.7) both passed in Docker.
- Earlier regression evidence at `90d2c308`: the architecture test file passed with 31 tests. At the test-only parent, `33e6ca847`, the new regression failed in both `warm=False` and `warm=True` subtests because Dynamo could not trace `posix.stat`.
- Earlier public API validation at `90d2c308`: `torch.compile(fullgraph=True)` with Inductor, `triton.cudagraphs=False`, three fresh inputs per case, and exact (`rtol=0, atol=0`) eager comparisons passed all 8 cases: `flash_attn_varlen_func` for (bf16, 128, 128), (fp16, 128, 128), and (bf16, 192, 128), each with `return_lse` True and False, plus `flash_attn_func` bf16 128 with both `return_lse` values. These cases fall through to non-FlyDSL backends. The first case failed on the baseline with `posix.stat`. These public API checks were not rerun for the documentation and cleanup commits.
- Earlier no-PyTorch validation at `90d2c308`: `chip_info` imported with PyTorch unavailable, strict AOT replay returned `gfx1250-strict`, the offline build target was `[("gfx1250-strict", 256)]`, and no `torch` module loaded. This check was not rerun for the documentation and cleanup commits.
- Remaining FP8 failure reproduced at `90d2c308`: public causal varlen attention with FP8 e4m3, head dimension 128, `fullgraph=True`, and `backend="eager"` fails in FlyDSL's own architecture probe at `_thread.allocate_lock` inside `subprocess.check_output`. Removing the constant-result marker restores the earlier `posix.stat` failure. This confirms the separate blocker on FlyDSL 0.5.0 and PyTorch 2.13.
- GitHub checks at this update: Black, Ruff, Check Repository Dependency, Aiter Test Gate, and OPUS Tests (MI350X DPX) passed. The latest Aiter wheel-build job was still queued; CI was not yet complete.

Unverified locally: gfx942/MI300X, gfx1250 hardware, the Windows `hipinfo`/Torch fallback, PyTorch versions other than 2.13, and compiled runs with CUDA graphs enabled. Other compiled callers of `get_gfx_runtime()` were not exercised individually. FlyDSL FP8 fullgraph execution has the known failure above.

PR-specific question

> What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?

Dependency: none added. The `torch.compiler` import falls back to an identity decorator when PyTorch is unavailable; the earlier no-PyTorch check covers that path. JIT build behavior and cache keys are unchanged: build paths use `get_gfx()` and `GPU_ARCHS`, which this PR does not modify.

Compilation: Dynamo evaluates `get_gfx_runtime()` at trace time and inserts the result without an architecture guard. Python cache clearing does not update an existing graph. The test clears the `get_gfx_runtime`, `_detect_native`, and `_gpu_info_output` caches before each subtest, then compiles once with cold caches and once after an eager warm-up. Both cases fail before the marker and pass with it; the cleanup revision also passed both cases. Final cleanup clears all three probe caches and resets Dynamo.

Build-cache evidence comes from the earlier public API validation at `90d2c308`: the first run used a fresh worktree with an empty `aiter/jit/build` and built the required modules, then a rerun passed with those artifacts cached. The two follow-up commits change only documentation and test cleanup, so the build-cache checks were not repeated.

Changed op tests

`op_tests/test_build_targets_architecture.py` adds `TestRuntimeArchitecture.test_runtime_arch_fullgraph_with_cold_and_warm_caches`. It compiles an architecture-dependent branch with `torch.compile(backend="eager", fullgraph=True)`, checks the exact architecture string and tensor result against eager, and covers both cold and warm probe caches. The CPU tensor and eager compiler backend isolate Dynamo tracing from kernel compilation. The test still needs a live GPU for real architecture detection and skips without one.

The existing tests exercise eager detection and mocks; they do not trace the real probe and cannot detect this graph break. The added cleanup registers each probe once and resets Dynamo after the test, while retaining the per-subtest resets needed for independent cold/warm cases. The final test implementation passed in the full architecture test file: 31 tests and 52 subtests.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

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
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants