Skip to content

[FlyDSL] [CI] [Build] Add an on-disk AOT cache for the FlyDSL GEMM launchers - #8356

Merged
coderfeli merged 14 commits into
mainfrom
felix/flydsl-aot-cache-v2
Nov 22, 2026
Merged

coderfeli merged 14 commits into
mainfrom
felix/flydsl-aot-cache-v2

Conversation

@coderfeli

@coderfeli coderfeli commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Supersedes #8287: the same AOT cache changes, pinned to FlyDSL 0.5.1 and without #8287's radix_topk_one_block workaround.

Summary

This PR adds an on-disk AOT cache for the FlyDSL GEMM launchers (aiter/ops/flydsl/aot_cache.py).

  • Miss: the kernel is compiled with flyc.compile(..., compile_only=True) and exported with export_to_c.
  • Hit: it is loaded with flyc.load_module, so a cold process skips MLIR tracing and the LLVM compile.

Converted launchers:

  • preshuffle GEMM (gfx942/gfx950)
  • a8w8 blockscale
  • mxfp8 8-wave
  • mxscale preshuffle (GEMM, fused GEMM, split-K reduce)
  • batched mxfp8 GEMM (gfx950)

Motivation

Today every new process traces and compiles each FlyDSL GEMM on its first call, which takes about 80–330 ms per kernel. With many tuned shapes this dominates warm-up. The dry_run prebuild replay (python -m aiter.aot.flydsl.gemm) also has to keep working, and must not under-build.

Changes

  • aiter/ops/flydsl/aot_cache.py (new): FlyDSLAotCache.launch(key, make_exe, *args).
    • Invalidation: each entry records the Python sources its trace touched (<digest>-<srchash>.o/.json). The fingerprint directory covers the FlyDSL/HIP/Python versions, the code-affecting environment and the arch. Editing one kernel file invalidates only the entries that depend on it.
      • Source paths inside the aiter package are stored relative to it, so entries prebuilt into a wheel (PREBUILD_KERNELS=1) still hit after install.
      • The fingerprint also covers the CU count and the FLYDSL_* / AITER_FLYDSL_* variables that change code; cache, replay and debug switches (FLYDSL_RUNTIME_RUN_ONLY, AITER_FLYDSL_AOT_TIMEOUT, ...) are ignored, so the replay's --check reads the entries a build made.
      • Each entry also records the aiter modules its build-feeding code imports values from (from .common import TILE_M records common.py), resolved statically through re-exports, star imports, namespace packages and the names a value is computed from. This replaces hand-written extra_sources.
      • Each entry also records the other environment variables its build read by name (os.environ[...], getenv, get) and the ones named in kernel files, and is rebuilt when they change. Reads of the whole environment (os.environ.copy(), dict(os.environ)) are not recorded, so no unrelated values or secrets are written to the sidecar.
      • An entry whose build uses chip_info.get_gfx() records its value, since under GPU_ARCHS="gfx942;gfx950" it differs from the device arch the fingerprint hashes. None of the converted launchers uses it today, so they do not record it.
    • Concurrency: builds take a per-digest fcntl.flock. An entry is published atomically, .json first and then .o. Concurrent processes and parallel replays never compile or export the same entry twice.
    • Modes: AITER_FLYDSL_AOT_CACHE=0|1|verify (default 1) and AITER_FLYDSL_AOT_CACHE_DIR.
    • Prebuild: under COMPILE_ONLY the cache exports the entry and also runs FlyDSL's compile-only launch. The replay's kernel identification and M-bisection hook that launch. The launch is skipped when the export has just traced the kernel.
    • Keys: in-memory keys include the device; the on-disk digest uses only the device type.
  • Launchers: preshuffle, blockscale, mxfp8 8-wave, mxscale preshuffle and batched mxfp8 now go through the cache. tensor_shim gains current_raw_stream / current_stream_arg.
  • docs/flydsl_aot_cache.md: design, invalidation, prebuild interplay and limits.
    • Known limit, pre-existing on main: ops routed through torch.ops.aiter_routed run their fake under the dry run, so they are not prebuilt. That fix is left to a separate PR.
  • tests/test_flydsl_aot_cache.py: an end-to-end JIT vs AOT check (pytest; added to the explicit list in .github/scripts/split_tests.sh).

Performance (if applicable)

Hardware Workload/configuration Before After Change
MI308X (gfx942) preshuffle GEMM, first call in a cold process (8 shapes, fp8/int8) 174–464 ms (JIT) 3.3–26 ms (AOT hit) ~10–80x faster first call
MI308X (gfx942) preshuffle GEMM, steady-state kernel time 4.1–11.3 us 4.5–11.4 us within noise
MI308X (gfx942) preshuffle GEMM wrapper host time (m=1, 2000 calls) 37.7 us 36.4 us -3%

Testing

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

Documentation

  • Docstrings updated
  • User guide updated (docs/flydsl_aot_cache.md)
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

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

FlyDSL APIs used, classified by FlyDSL's docs/api_stability.md:

  • Stable: flyc.compile(compile_only=True), CompiledFunction.export_to_c, flyc.load_module, flyc.JitArgumentRegistry, flydsl.compiler.protocol.cache_signature and flydsl.runtime.device.get_rocm_arch.
  • Not stable (internal):
    • flydsl.compiler.jit_argument.PointerJitArg, constructed directly to make a null-pointer placeholder for the compile-only export.
    • flydsl.utils.env (env.compile.compile_only), to detect COMPILE_ONLY.
    • The _is_stream_param marker on fx.Stream, to recognize stream arguments and build a null-stream placeholder.
    • The fingerprint also hashes the installed FlyDSL package's sources and native libraries, so a FlyDSL change invalidates entries rather than reusing them.

A FlyDSL release that moves or renames one of the internal symbols breaks this module at import or at the first launch, so the pin bump must re-run tests/test_flydsl_aot_cache.py.

Breaking Changes

None.

  • The cache is on by default and writes under the aiter cache directory. Set AITER_FLYDSL_AOT_CACHE=0 to get the previous pure-JIT behavior.
  • Kernel binaries are unchanged.

PR Self-Review

Reviewed revision

4423ba0

Behavior and intent

The first call of a converted FlyDSL GEMM now loads a cached object instead of tracing and compiling. Kernel code, launch arguments and binaries are unchanged. Prebuild keeps working and builds the same kernels as before.

Validation and unverified scope

  • FlyDSL used: 0.5.0.dev1039, with flyc.load_module. The AOT cache test was re-run on MI308X with the released 0.5.1.dev1059 wheel: all four modes pass, including the path assertions. After the switch to the PyPI 0.5.1 wheel, tests/test_flydsl_aot_cache.py passes again on MI308X. With the same wheel, the unmodified radix_topk_one_block passes test_topk_per_row, test_topk_per_row_stable and test_qsa (110 passed).
  • Runtime, MI308X (gfx942):
    • Command: python3 -m pytest tests/test_flydsl_aot_cache.py.
    • Coverage: 2 fp8 shapes (one split-K), in 5 cold subprocesses for jit, aot miss, aot hit, aot verify and a rebuild on a variable the build read; about 45 s on MI308X.
    • Result: all outputs are bitwise equal to JIT.
  • Multi-GPU and CUDA graphs:
    • One entry launched on all 8 GPUs in one process gives identical results. load_module creates a HIP context only on the current device.
    • 4 concurrent cold processes sharing one cache build the entry once.
    • CUDA graph capture and replay match eager, including when the first call (and so the load) happens inside the capture, and on a second GPU.
  • Prebuild, gfx950 compile-only:
    • Command: GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm --csv a8w8_mxfp8_bpreshuffle_tuned_gemm.csv.
    • Result: 20 ok, 0 failed.
    • With the a4w4 blockscale CSV (3 rows) as well, AITER_FLYDSL_AOT_CACHE=0 and two runs of =1 give the same 62 gpu.binary blobs (from the FlyDSL cache .pkl files).
    • These are also identical to main built with the previous FlyDSL.
    • The second =1 run rebuilds nothing.
  • Full prebuild, gfx950 compile-only (MI308X host):
    • Command: GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm over all tuned CSVs.
    • Result: 24136 ok, 0 failed; 3790 entries, 995 MB, 14.5 min (MI308X host, compile-only).
    • A second run over the warm cache rebuilds nothing.
    • No entry records get_gfx() or any environment variable. Entries built first in a replay worker also record modules that build imported for the first time (e.g. aiter/ops/triton/comms/*); that over-records, so it costs a rebuild when those files change, never a stale entry. Editing gemm_tune/flydsl_gemm_a8w8_blockscale_common.py makes the blockscale entries stale, and restoring it makes them current again.
  • Stale dist-info: a flydsl-0.5.0.dist-info holding only REQUESTED (left by an in-place pip upgrade) next to the 0.5.1.dev1059 wheel gives the same toolchain digest as a clean install; before d75cc7d it raised TypeError on importlib versions where metadata is None, so the whole cache fell back to JIT.
  • Object size: the FlyDSL AOT runtime linked into each .o carries about 240 KB of DWARF next to about 15 KB of kernel, so a full gfx950 cache was about 990 MB. Each export is now run through objcopy --strip-debug: 263 KB → 24 KB per entry (about 90 MB for the full cache). The same fix is going upstream to FlyDSL.
  • Prebuild robustness:
    • Two concurrent replays sharing one cache: no duplicate LLVM compile or export.
    • Re-running a replay rebuilds nothing.
    • Touching one kernel file rebuilds only the entries that depend on it.
  • Unverified:
    • Mode 0 (pure JIT) still launches only on the first GPU a process compiled for. This is a FlyDSL JIT limitation that exists on main too (docs §7, issue 4); the AOT path is not affected.
    • Runtime on gfx950 hardware. The gfx950 binaries are only proven identical to main; they were not executed.
    • Unconverted FlyDSL kernels still JIT on their first call: gemm_a16w16 (hgemm), the a8w4 comm_fused_moe and gfx1250 mxfp8.
    • The prebuild replays tuned CSV rows only. A shape without a tuned row, such as a DSV4 batched mxfp8 GEMM on its heuristic config, builds at its first call.
    • Prebuild size per arch: the full gfx950 prebuild above writes 3790 entries (995 MB) in 14.5 min. Rows tuned for another CU count (MiniMax-M3, 128 CUs) go to a second fingerprint directory, which the default CU count does not read.
    • Garbage collection of stale variants and .lock files is not implemented.
    • flock assumes a local filesystem for the cache directory.

PR-specific question

  • Compiled-handle cache keys: in-memory handles are keyed by constexprs, the dtypes that change the launcher signature, and the device. All tensors are passed as flat pointers (ptr_arg), so rank and stride do not change the ABI. The on-disk digest normalizes the device to its type, so one entry serves every GPU of the same arch.

Changed tests

  • tests/test_flydsl_aot_cache.py (new):
    • Runs the preshuffle GEMM in fresh subprocesses in all four cache modes and asserts bitwise equality with JIT.
    • It also asserts the path each mode took, so it cannot pass on a silent JIT fallback:
      • mode 0 runs the JIT and writes nothing;
      • a miss exports one .o/.json pair per entry, with no fallback;
      • a hit neither traces, builds nor rewrites the cache;
      • verify neither builds nor falls back.
    • It is the only test that covers cross-process cache hit, miss and verify; the existing op tests run in one process and never load from disk.
    • It skips outside gfx942/gfx950, and with a FlyDSL that has no flyc.load_module (before 0.5.1.dev1058), where every mode would run the JIT.
    • It lives in tests/ because it is not an op test; split_tests.sh lists it explicitly, since it scans only op_tests/.
    • Checked that the assertions fire: forcing every mode to the JIT, or running the hit on an empty cache, fails the test.

🤖 Generated with Claude Code

The first call of a converted FlyDSL GEMM launcher loads a cached
export_to_c object through flyc.load_module instead of tracing and
compiling it. Kernel code, launch arguments and binaries are unchanged;
with AITER_FLYDSL_AOT_CACHE=0, or a FlyDSL without flyc.load_module,
every key takes the existing JIT path. See docs/flydsl_aot_cache.md.

Pin FlyDSL 0.5.1.dev1059: flyc.load_module first shipped in dev1058,
and dev1059 also folds fly.get_iter of fly.make_view (FlyDSL #1454),
which dev1058 needs to compile rmem writes under a traced `if`
(radix_topk_one_block).

Supersedes #8287 without its radix_topk_one_block workaround.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 8356 --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.

coderfeli and others added 2 commits November 20, 2026 06:39
…installs

Two problems kept prebuilt .o files from being hit in a container image
such as ATOM's, whose build stage runs PREBUILD_KERNELS=1 and whose final
stage copies only the aiter tree and reinstalls FlyDSL from the pin:

- The default cache root was ~/.aiter/flydsl_aot, outside the aiter tree,
  so the final stage never got the entries. It is now flydsl_aot in
  get_user_jit_dir(), where aiter's JIT modules already live (aiter/jit/
  when writable, else ~/.aiter/jit/, or AITER_JIT_DIR).
  AITER_FLYDSL_AOT_CACHE_DIR still overrides it.
- The fingerprint hashed FlyDSL's native libraries by size and mtime, and
  a reinstall of the same wheel changes the mtimes, so every entry missed.
  It now hashes the package's entries in the wheel's RECORD (sha256 per
  file). A source build without a RECORD keeps size+mtime, now including
  versioned libraries (*.so.*): libFlyPythonCAPI.so.24.0git was not
  covered by *.so.

Checked: two pip installs of the dev1059 wheel give different digests
with the old hash and the same fingerprint with the new one.
op_tests/test_flydsl_aot_cache.py passes (8 rows bitwise equal). With no
AITER_FLYDSL_AOT_CACHE_DIR, a first process builds under aiter/jit/
flydsl_aot and a second one hits it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fingerprint now includes the CU count, so the dry run, which sets
CU_NUM per target, and the runtime, which reads the device, agree.

Each entry also records the environment variables its build depends on,
with their values, and a lookup requires the same values. Names come from
reads seen during the factory and trace, and from literals in kernel code
under aiter/ops/flydsl. Shared modules are not scanned, and variables that
describe the build (CU_NUM, GPU_ARCHS, COMPILE_ONLY, AITER_AOT_*,
AITER_CONFIG_*) are left out, so prebuilt entries still hit at runtime.
Only reads of one name count: copying or iterating os.environ is not
recorded, which would write the whole environment into the sidecar.

The op test asserts that a variable the build read, and another CU count,
each rebuild, that restoring the variable hits, and that a bulk read in the
trace leaves only the variable read by name in the sidecar.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Thanks, the design holds up well: per-entry source recording, the flock plus .json-then-.o publish, and running the export before the compile-only launch in the replay. The preshuffle test also checks the path each mode took, not just the output.

I'm not approving yet, for two reasons.

  1. Entries leak across aiter checkouts (inline on _find). Sidecars record absolute source paths, and neither the digest nor the fingerprint depends on which aiter tree is running. A second checkout on the same machine can therefore load the first checkout's .o even when its own kernel file differs. The cache is on by default and shared under ~/.aiter, so this affects the kernel-development and A/B-benchmark workflows the docs describe as safe.
  2. CI hasn't run any FlyDSL op test on this PR yet. When I looked, the Aiter Test run was still building the wheel. The FlyDSL pin bump affects every FlyDSL kernel, not only the converted GEMMs, so the CI guide's ci:atom_full (meant for FlyDSL upgrades) seems warranted. ci:mi300x also seems worth adding: the runtime validation was on gfx942, and default PR CI runs only on MI35X.

Non-blocking: op_tests/test_flydsl_aot_cache.py only drives the preshuffle launcher. The description lists the gfx950 launchers (bmm, mxscale fused and split-K with the reduce, 8-wave, blockscale) as not yet run on hardware. In mode 1, an export or load failure there falls back to the JIT with a warning, so the existing op tests would pass either way. Running the gfx950 GEMM op tests once with AITER_FLYDSL_AOT_CACHE=verify, which raises instead of falling back, or adding one of those launchers to the miss/hit/verify test, would cover them.

Comment thread aiter/ops/flydsl/aot_cache.py Resolved
Comment thread aiter/ops/flydsl/aot_cache.py Resolved
Comment thread aiter/ops/flydsl/gemm_kernels.py Outdated
m,
n,
fx.Stream(torch.cuda.current_stream()),
current_stream_arg(),

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.

Nit, pre-existing: the split-K workspace and semaphore above come from torch.cuda.current_stream(device=Out.device), but the launch uses the current device's stream. Now that current_stream_arg takes a device, current_stream_arg(Out.device) would make them agree, as the blockscale, 8-wave and bmm launchers already do.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3397166: the preshuffle launch now passes current_stream_arg(Out.device), matching the workspace/semaphore stream and the other launchers.

Comment thread docs/flydsl_aot_cache.md Outdated
### 5.1 gfx942: `flydsl_preshuffle_gemm_a8`

```python
key = (tuple(sorted(compile_kwargs.items())), x_scale.dtype, w_scale.dtype)

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.

Nit: in the code this key also ends with XQ.device (memory only, see §4.1).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3397166: the §5.1 key now ends with XQ.device.

coderfeli and others added 2 commits November 20, 2026 08:05
…dule, --check

- Sidecars stored absolute source paths, so a cache prebuilt in a source
  tree (PREBUILD_KERNELS=1 setup.py bdist_wheel packs aiter/jit/flydsl_aot)
  missed every entry once the wheel was installed elsewhere. Files inside
  the aiter package are now stored relative to it.
- The blockscale factory only reads TILE_* and kernels_by_name from its
  gemm_tune common module, so the trace never ran a function there and the
  entry did not record it; editing a tile there reused the old object. The
  module is now passed as extra_sources.
- FLYDSL_RUNTIME_RUN_ONLY (set by the replay's --check),
  FLYDSL_RUNTIME_ENABLE_CACHE and the replay's AITER_FLYDSL_AOT_TIMEOUT /
  MAX_RETRIES / TRACEBACK went into the fingerprint, so --check looked in
  another directory and built entries there. They change no code and are
  now ignored.
- flydsl_mxscale_preshuffle_gemm again accepts an fx.Stream or a raw handle
  as stream=, as on main; only torch streams worked after the conversion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s start

A process runs the code it imported. If a kernel file is edited after that
(a git checkout during a long test run), a later miss in the process traced
the old in-memory code but recorded the new file's hash, so every later
process running the new code hit an object built from the old one. Reproduced
with the preshuffle GEMM: after an edit to compile_preshuffle_gemm, the next
process loaded the old kernel while its JIT produced the new one.

The build is now not written when a recorded source was modified after the
process started; that key takes the JIT path with a warning, and the next
process builds the entry from the new code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Re-reviewed at 576954f.

Resolved:

  • Cross-checkout hits. I re-ran the earlier check with _portable, _entry_current and _find from this revision. A tree with an edited kernel now misses, and the same files installed at another path hit.
  • FlyDSL fingerprint. The RECORD lookup matches the dev1059 wheel: 192 package entries, 14 of them .so.
  • The blockscale extra_sources, the --check variables and the mxscale stream= fix also look right.

I'm still not approving, for two reasons:

  1. New: on Python 3.11+, the build-time environment tracking doesn't record most reads (inline on _ENV_PLUMBING). The new check_paths assertions depend on that tracking, so they should fail on the py3.12 standard-test image.
  2. No FlyDSL op test has run on this PR yet. This push cancelled the Aiter Test run for the previous head, and the run for 576954f is still queued. I'd still add ci:atom_full and ci:mi300x.

The two nits and the gfx950-coverage suggestion from the last round are unchanged. None of them block.

Comment thread aiter/ops/flydsl/aot_cache.py Outdated


# os.getenv, os.environ.get and `in` reach _Environ.__getitem__ through these.
_ENV_PLUMBING = frozenset({os.__file__, _collections_abc.__file__})

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.

On Python 3.11+ this set never matches, so reads through get, getenv, in and setdefault are not recorded. os and _collections_abc are frozen modules there. Their code objects have co_filename "<frozen os>" and "<frozen _collections_abc>", while os.__file__ is the real path. In prof, the Mapping.get frame is therefore not recognized as plumbing and is treated as the caller instead. _subscript then sees its self[key], so the read is attributed to <frozen _collections_abc>, and _is_tracked drops it. Only a direct os.environ["X"] is recorded.

To check, I ran _record_sources copied from this file around a tracked module. The module reads READ_BY_GET, READ_BY_GETENV, READ_BY_IN and READ_BY_SETDEFAULT the four ways above, subscripts HOME, and does one dict(os.environ):

python 3.12.3:                       recorded env: ['HOME']
python 3.12.3 -X frozen_modules=off: recorded env: ['HOME', 'READ_BY_GET', 'READ_BY_GETENV', 'READ_BY_IN', 'READ_BY_SETDEFAULT']

The new check_paths assertions read TEST_ENV with os.environ.get, so they should fail on the standard-test image: it uses py3.12, and split_tests.sh picks up every op_tests/test_*.py. On 3.10 nothing is frozen, so it works there. For the converted GEMMs I don't see anything lost today, because none of their files name a variable. Still, on 3.11+ the runtime half of the tracking does nothing: names computed at runtime and reads in shared modules are never recorded.

Taking the names from the code objects works with and without frozen modules:

# Frozen on 3.11+, where co_filename is "<frozen os>" rather than os.__file__.
_ENV_PLUMBING = frozenset(
    {os.getenv.__code__.co_filename, _collections_abc.Mapping.get.__code__.co_filename}
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. Fixed in 3397166: _ENV_PLUMBING now takes the co_filename of the plumbing functions' code objects (os.getenv, Mapping.get, _Environ.__getitem__, ...) instead of os.__file__, so it matches <frozen os> / <frozen _collections_abc> on 3.11+. Checked on Python 3.12: get, getenv, in and setdefault reads are attributed to the calling aiter file and recorded.

The literal-name scan read whole kernel files, so a variable named only in
host code the build never runs (PYTORCH_HIP_ALLOC_CONF in mega_moe_tp's IPC
setup) was recorded and made prebuilt entries miss. Scan module and
class-body statements, the functions the build called and memoized
functions only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yitingw1

Copy link
Copy Markdown
Contributor

Re-tested #8356 (576954fc) end to end on gfx950. Shipping the .o files through the default dir works: with the prebuild in place, the first pass gets the full warm-cache gain.

Setup. Same as my FlyDSL#1413 test: DeepSeek-V4-Pro on 8× gfx950, DP attention, 8k/1k, concurrency 64, CI image (rocm/atom-dev@sha256:f3c2fcd6…) and CI args. I installed flydsl==0.5.1.dev1059, applied #8356, then ran run_aot for gfx950 the way setup.py:417 does, with no cache env vars set. The .o files went to aiter/jit/flydsl_aot/, which the ATOM Dockerfile already copies into the final stage. Then I started the server.

arm config output tok/s vs A3 first-launch stall, union over ranks
A3 stock image 1791 — 60.8 s
P dev1059 + #8356, prebuilt default dir 2030 +13.3% 20.0 s

GSM8K 3-shot with P is 0.9515. One pass per arm; A3 matches the earlier A2 baseline (1793).

  • Ask 1 (ship the .o files) is resolved. The prebuild fingerprint matches the runtime one, and every converted kernel except bmm hits 100% at runtime.
  • Correction to my earlier comment: B built 22 new .o files, not 19, and that was a key B0 hadn't reached rather than one the prebuild missed (V3 had no prebuild).

Remaining asks:

  1. Untuned bmm shapes still miss. At runtime P built 11 bmm_a8w8_mxscale_gfx950 objects, all with variant acd353300d3c. None of the 1273 prebuilt bmm objects has that variant. The server log shows B:16 M:2 N:1024 K:4096 w_scale 128x128 has no MXFP8 BMM tuned row. The replay covers only tuned CSV rows, so the default-config fallback never gets prebuilt. Could the replay also prebuild the fallback config, or could we add tuned rows for the DSV4 bmm shapes?
  2. comm_fused_moe (a8w4) and gemm_a16w16 are still JIT. With prebuild they account for almost all of the remaining trace time: 216 traces for 21.9 s and 134 traces for 4.5 s. If they are a follow-up, please list them under Known limits in the PR body.
  3. Document the image cost. For gfx950 alone the prebuild took 1041 s and produced 3716 .o files (976 MB), and flydsl_cache grew by about 213 MB. Ten objects ended up under a second fingerprint (bb81df4a8b274d38) that the runtime never uses. Please put per-arch size and build time in the PR body, and check where that second fingerprint comes from.
  4. Doc §7 contradicts itself. The next-steps item still says "Wire AITER_FLYDSL_AOT_CACHE=1 into aiter/aot/flydsl so a wheel or container image can ship prebuilt .o files", but §4.2 and aot_cache.py:54 say that already happens by default. Please drop the item or say what is still missing.

I haven't repeated @zhiding512's points (py3.11+ _ENV_PLUMBING, CI labels, the stream device in gemm_kernels.py:662, gfx950 verify coverage).

coderfeli and others added 3 commits November 20, 2026 09:52
…ntries

- Imported module-level values: the profile hook sees calls, not reads
  of an imported constant. After a build, the imports in the build code
  of each recorded file are resolved statically, and the aiter module a
  non-function value comes from is recorded too (re-exports and the
  names it is computed from are followed; memoized functions count,
  loggers do not). This replaces blockscale's manual extra_sources.
- get_gfx(): it honours GPU_ARCHS, while the fingerprint hashes the
  device arch. An entry whose build calls it now stores its value under
  "get_gfx()" and is compared on lookup. Its memo is cleared before each
  build so the hook sees the call; module-level and memoized code is
  scanned. None of the five converted launchers records it.
- Python 3.11+: os and _collections_abc are frozen, so the env plumbing
  is matched by the code objects' co_filename, not module __file__.
- Review nits: the preshuffle stream is taken on Out.device, and the
  docs' 5.1 key includes the device.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test checks cache infrastructure, not an op, so it now lives next
to tests/test_flydsl_aot_replay.py (the file move landed in the
previous commit) and is a pytest test. split_tests.sh only scans
op_tests/, so it is listed there to keep running in the GPU shards;
aiter_test.sh runs tests/test_*.py with pytest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… when recording sources

Review of the import closure found values whose defining module was not
recorded, so editing it left a stale entry:

- from aiter.utility import dtypes: aiter/utility has no __init__.py, and
  _imported gave up before checking for the submodule.
- from aiter import QuantType: a name re-exported by a star import resolved
  only to the re-exporting module, not to the module that defines it.
- X = helper() at import: an uncached function was skipped even when it
  was called to compute the value.
- if FLAG: X = 1 / for k in KEYS: TABLE[k] = ...: names read in the enclosing
  condition or loop, and subscript stores, were not followed.
- A memoized function's body was not followed, so a constant it reads
  through another import was missed.

Bump _SCHEMA to 5 so entries recorded with the smaller set are rebuilt, and
clear the parse caches after each build. Update the module docstring and
the guide, which overstated the closure, and replace the stale §7 item with
the known limits: untuned shapes, unconverted launchers and the gfx950
prebuild size.

A full gfx950 replay into an empty cache: 24136 ok, 0 failed, 3790 entries
(995 MB, 14.5 min); no entry records get_gfx() or an env variable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aiter-bot

aiter-bot commented Nov 20, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 4423ba0150c7 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Changed op tests in the PR description

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

@coderfeli

Copy link
Copy Markdown
Collaborator Author

Thanks for the end-to-end re-test. Addressed in d865032 (PR body updated):

  1. Untuned bmm shapes. The replay can only build what a CSV names: the fallback config is chosen at runtime from the shape (lookup_mxscale_bmm_config → _heuristic_mxscale_bmm_kid in aiter/ops/opus/policy.py), and the replay has no shape list outside the tuned rows. Adding tuned rows for the DSV4 bmm shapes (e.g. B:16 M:2 N:1024 K:4096) puts them in the prebuild with no code change; I'd rather do that in the tuning CSVs than invent shapes in the replay. Listed under Known limits in the PR body and in docs §7.
  2. comm_fused_moe (a8w4) and gemm_a16w16. Not converted in this PR; listed under Known limits (with gfx1250 mxfp8) and in docs §7 as a follow-up.
  3. Image cost. Locally a full GPU_ARCHS=gfx950 prebuild over all tuned CSVs: 24136 rows ok, 3790 entries, 995 MB, 14.5 min (MI308X host, compile-only); now in the PR body and docs §7. The second fingerprint is the CU count, which is part of the fingerprint: 10 preshuffle_gemm_a8 entries come from the MiniMax-M3 rows tuned with cu_num=128, so they land in the 128-CU directory and are read only on a 128-CU part. That is intended; documented.
  4. Doc §7. Dropped the stale "wire into aiter/aot/flydsl" item and replaced it with the actual remaining limits (untuned shapes, unconverted launchers, prebuild size).

coderfeli and others added 5 commits November 20, 2026 14:58
An in-place pip upgrade of FlyDSL can leave a stale dist-info holding
only REQUESTED. _wheel_record read dist.metadata["Name"] for every
dist-info under site-packages; on importlib.metadata versions where
metadata is None for such a dist this raised TypeError, the fingerprint
failed and every key fell back to JIT behind a single warning (Python
3.12 warns that it will become a KeyError). Skip dist-infos without
METADATA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts in the two launchers main changed under #8296:
- mxscale_preshuffle_kernels: the split-K reduce gained row_dw/ldc_dw
  and a strided Constexpr; _bound_reduce_exe binds strided and takes the
  new runtime arguments, and its cache key includes strided.
- gemm_a8w8_mxfp8_8wave: the launcher gained ldc and Out may be a
  column slice; the tail split's K-split GEMM and strided reduce go
  through the AOT caches like the unsplit launch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Most of its time was cold-process startup (about 6 s to import aiter per
child) and a timing loop nothing asserted. Run two fp8 shapes (one
split-K) instead of four shapes x {fp8, int8}, drop run_perftest, and
drop the restore-variable and CU-count runs. The path assertions for
jit, miss, hit, verify and the env-variable rebuild are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The FlyDSL AOT runtime linked into every exported object carries about
240 KB of DWARF, against about 15 KB of kernel: a full gfx950 replay
cache was ~990 MB. objcopy --strip-debug brings an entry from 263 KB to
24 KB. Linux exports already require objcopy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
0.5.1 is the release of the dev1059 line the AOT cache was built and
tested against, including flyc.load_module. tests/test_flydsl_aot_cache.py
passes on MI308X with the PyPI 0.5.1 wheel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderfeli

Copy link
Copy Markdown
Collaborator Author

Non-blocking follow-up for symlinked installs. _record_sources filters the raw filename before resolving symlinks. With site-packages/aiter symlinked to a checkout, this can drop the kernel sources and publish an AOT entry with an empty sources map. On gfx942, I reproduced a fresh process reusing the old preshuffle GEMM object after editing the kernel. Source recording code

Resolve filenames before filtering, then invalidate entries that may have been built without their source dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants