Skip to content

[FlyDSL] [CI] [AOT_TO_C] Fix/flydsl aot key guards hgemm - #8565

Merged
coderfeli merged 18 commits into
mainfrom
fix/flydsl-aot-key-guards-hgemm
Nov 25, 2026
Merged

coderfeli merged 18 commits into
mainfrom
fix/flydsl-aot-key-guards-hgemm

Conversation

@coderfeli

@coderfeli coderfeli commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #8451 (FlyDSL AOT cache through _run_compiled).

  1. Cache fixes. An exported object ignores a launcher's Constexpr launch arguments, so an entry built with one value was loaded by a later process that passed another. The cache now records what an entry bakes in and only serves calls that match.
  2. Coverage. Every FlyDSL launcher that the GEMM and 2-stage MoE AOT replays compile for gfx942 and gfx950 now launches through the cache.

gfx1250 is not touched. Replaces #8537 (closed).

Motivation

FlyDSL keys its artifacts by the traced IR, so every new process traces every kernel again on first use (70 ms to several seconds each). #8451 added a cache of exported objects that skips the trace, for a first set of launchers. Two things were missing: the cache key did not cover everything an exported object bakes in, and most GEMM and MoE launchers of gfx942 and gfx950 still took the JIT path.

Changes

Cache (aiter/ops/flydsl/aot_cache.py, aot_launch.py):

Problem Fix
Every AITER_FLYDSL_* / FLYDSL_* variable was in the fingerprint: setting one that a single kernel reads made every cache miss The fingerprint keeps FlyDSL's own compile variables. A cache declares the variables its source files read (env=); a prebuild and a unit test raise for one read by a literal name and not declared
verify compared exported objects byte for byte, but the code generator can make different bytes of one IR An entry records FlyDSL's key of the traced IR; verify compares that
A launch with no entry built one in-process. A long-running process traces the code it imported, which may no longer be what the files say, so it could store old code under the digest of the new files Only a prebuild (a launch under COMPILE_ONLY, as the replays in aiter/aot/flydsl run) builds entries. A launch loads an entry or, with none, logs an error and traces on the JIT path
A launch sent to the JIT path was logged as info, warning or not at all Every one is logged once per key with logger.error (no entry, failed load or export, a key the cache cannot store, a launcher it cannot bind, a reset factory). Nothing raises; AITER_FLYDSL_AOT_CACHE=0 stays silent
Constexpr launch arguments not in the key: another process silently loads the wrong object Values are recorded in the entry's sidecar (baked) and compared on lookup. Within a process, one key launched with another value raises. Ints, floats, bools, strings, None and tuples are supported
A specialization_key holding an Enum or numpy scalar raised on every launch That key takes the JIT path, with one warning
factory.cache_clear() kept the loaded kernels Drops them and keeps the factory on the JIT path for the rest of the process
An entry recorded the files its build ran (sys.setprofile); what a build runs depends on what the process ran before, so an edit to a missed file left stale entries Each cache declares its files, as FlashInfer's gen_jit_spec(name, sources) does: aot_factory(name, sources=[...], env=[...]). Their contents and the variables' values are hashed into the entry's name. Nothing is detected at run time
A source missing from the list Checked when an entry is built: a declared kernel file that imports an undeclared kernel file raises _UndeclaredSourceError in every mode. A unit test runs the check over every cache in the tree. tensor_shim.py counts as a kernel file (ptr_buf_tensor emits code)
Bitcode linked with link_extern not in the key Declared in sources; a build that links undeclared bitcode raises
ROCm device bitcode (ocml, ockl) not in the fingerprint FlyDSL's own digest of it is added
LLVM_GFX1250_ANY_XNACK_CODEGEN not in the fingerprint The fingerprint follows FlyDSL's own list of cache-invalidating variables
Caller's CompilationContext.compile_hints not in the key Hashed into the disk digest
A factory returning a tuple or dict made bind_aot raise Left unbound, on the JIT path
An AOT replay hook that stops flyc.compile to identify kernels counted as an export failure under verify Takes the JIT path in every mode
A bound launch cost about 4 us more host time than the JIT path (20-argument factory) A binding keeps the kernels the cache loaded for it; lazy() keys its handles with functools.cache

Launchers moved to the cache (gfx942 / gfx950):

Cache Launcher How
gemm_a16w16_gfx950 default HGEMM bind_aot; launched through _run_compiled with its config items and device as the specialization key, in place of its private flyc.compile cache (run_cached, removed). Its dynamic-layout tensor arguments now carry torch_tensor
gemm_a16w16_band_gfx950, gemm_a16w16_skinny_gfx950 band and skinny HGEMM aot_factory
gemm_a8w8_fp8_8wave, gemm_a8w8_int8_4wave per-token-per-channel a8w8 aot_factory
mixed_moe_gemm1/2, mixed_fhmoe_gemm1/2 MX 2-stage MoE, FHMoE aot_factory
mxfp4_moe_gemm1 a4w4 stage 1 aot_factory
mxmoe_gemm2 MX stage 2 (mxmoe_dispatcher.get_g2) bind_aot under get_g2's key
moe_reduction stage-2 reduce aot_factory

CI: .github/scripts/aiter_test.sh runs the op tests under AITER_FLYDSL_AOT_CACHE=verify unless the variable is already set. An entry a test loads from disk (built by the wheel's prebuild) is re-traced and compared byte for byte, and a load failure fails the test. A test shape with no prebuilt entry takes the JIT path and is not checked. Running a test by hand is unchanged (mode 1).

Also: .claude/skills/flydsl-aot-export/SKILL.md and pointers to it, and a merge of main for the Triton 3.9.0 bump (#8266).

Performance (if applicable)

Host time of one launch, MI308X (gfx942), FlyDSL 0.5.3, an empty kernel, arguments built on every call, pinned cores. "Before" is the JIT path (AITER_FLYDSL_AOT_CACHE=0), "After" is a cache hit.

Hardware Workload/configuration Before After Change
MI308X 6 typed pointers, 2 ints (mxscale, bmm, gfx942 MoE) 20.5 us 20.3 us -0.2 us
MI308X 6 raw addresses, 2 ints, 2 floats (a16wmix, MX MoE GEMMs) 10.3 us 11.3 us +1.0 us
MI308X 5 flat tensors, 2 ints (preshuffle, blockscale, 8-wave) 12.1 us 14.2 us +2.1 us
MI308X 3 dynamic-layout tensors with torch_tensor, constexpr struct, arguments prebuilt (the gfx950 HGEMM's argument shape) 11.9 us 12.5 us +0.6 us
MI308X the same without torch_tensor 11.8 us 30.8 us +19 us

Compiled kernels are unchanged: the replays below leave the same FlyDSL artifacts, byte for byte, with AITER_FLYDSL_AOT_CACHE=0 and =1 (4874 gfx950 GEMM, 80 gfx942 GEMM, 2747 gfx950 MoE, 100 gfx942 MoE).

Size: an exported object averages 29 KiB against 6.5 KiB for FlyDSL's own cache file of the same kernel. For the gfx950 GEMMs that is 146 MiB on disk and about 53 MiB inside a wheel.

Testing

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

Documentation

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

docs/flydsl_aot_cache.md (sections 4.2, 5.4, 6, 7) and the module docstring of aot_launch.py.

Dependencies

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

Breaking Changes

  • A launch no longer builds a missing entry. A shape the prebuild did not cover traces in every process (as before [FlyDSL] [CI] Launch FlyDSL AOT cache entries through _run_compiled #8451) and logs one error per key. The gfx942 whole-MoE caches (moe_gfx942_gemm, moe_gfx942_sorted_sum, moe_gfx942_absmax, moe_gfx942_quant_per_tensor) have no replay, so they take the JIT path until one is added.
  • aot_factory(..., extra_sources=) is now sources=, and bind_aot has no rebuild argument. A cache whose kernel files import a kernel file it does not declare, or whose sources= names a missing file, fails its prebuild.
  • The cache schema goes from 5 to 7: existing AOT entries, including prebuilt ones shipped in a wheel, are rebuilt by the next prebuild.
  • A launcher with Constexpr launch arguments that is launched under one key with two values now raises _BakedArgumentError; the JIT path silently ran the first.
  • kernels_common.run_cached is removed (its only user was gemm_a16w16_gfx950). It serialised the first compile of an HGEMM config with a lock; _run_compiled's JIT path does not, so with the cache off two threads may both compile a config. Results are unaffected.

PR Self-Review

Reviewed revision

cd3c7b0

Behavior and intent

A launch of a FlyDSL kernel that is bound to the AOT cache loads an exported object instead of tracing the kernel. Before this change the cache could hand a later process an object built for other compile-time inputs: Constexpr launch arguments, linked bitcode, the ROCm device bitcode, LLVM_GFX1250_ANY_XNACK_CODEGEN and the caller's compile hints were not part of an entry's identity. They are now, and the cache falls back to the JIT path where it used to raise for inputs it cannot key. An entry's sources are the files its cache declares, in place of the files a build happened to run.

The GEMM and 2-stage MoE launchers that the AOT replays compile for gfx942 and gfx950 now use the cache, so a serving process no longer traces them on first use. Their compiled code is unchanged.

Validation and unverified scope

MI308X (gfx942), FlyDSL 0.5.3, on the pre-merge head plus the commits after the merge of main (the merged head needs Triton 3.9.0, which that machine lacks; there only lint and a static run of the source check ran: 25 caches, none missing a file).

  • Compile-only replays (the prebuild), each run twice on one cache directory, every flyc.compile logged: GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm (5240 entries), GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.moe --row-tokens-only (2877), GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.gemm (80), GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.moe --row-tokens-only (132). The second run builds nothing; no launcher is compiled by the JIT path. The gfx950 MoE replay exits 1 for one row it rejects before compiling (stage-2 output over the 32-bit buffer limit), with the cache on or off.
  • FlyDSL artifacts of those replays against AITER_FLYDSL_AOT_CACHE=0 runs of an earlier revision: all identical in the last run (gfx950 GEMM 4874, gfx950 MoE 2747, gfx942 GEMM 80, gfx942 MoE 100); see below for earlier runs.
  • On the GPU, against the entries the gfx942 replays built, under 0, verify and 1: op_tests/test_gemm_a8w8.py loads 80 entries, no miss; op_tests/test_flydsl_moe_a16wfp4.py loads 11, no miss; op_tests/test_flydsl_moe_gfx942.py loads none and logs 138 misses (no replay builds those caches). All pass, verify finds no stale entry, and no run adds a file to the cache directory.
  • tests/test_flydsl_aot_launch.py and tests/test_flydsl_aot_cache.py under 1, verify and 0.
  • Variables, on the gfx942 GEMM replay over its 80 entries: with a variable only the gfx942 MoE declares set, 0 built; with an undeclared AITER_FLYDSL_* variable set, 0 built; with a common one (AITER_FLYDSL_KERNARG_PRELOAD=0), 80 built and 0 on the next run; with FLYDSL_COMPILE_OPT_LEVEL=1, 80 built in another fingerprint directory.
  • verify, on the GPU, with a kernel whose code depends on a value outside its key: mode 1 returns the prebuilt value, verify raises (traces to other IR).
  • Before the last commit, not repeated after it: with one kernel file removed from a cache's sources=, the gfx942 GEMM replay fails with _UndeclaredSourceError and writes no entry; an edit to an undeclared file builds 0, an edit to a declared file rebuilds its 80, reverting builds 0; a kernel linking real bitcode raises when the bitcode is not declared, and replacing declared bitcode makes a new entry with the new result.
  • Three independent reviews of the cache; their findings are fixed or listed below.

Unverified or known:

  • gfx950 runtime; verify on gfx950 and gfx1250 runners.
  • The same FlyDSL IR can compile to different GPU binaries. Reproduced with the cache off: flydsl_mxpsh_96x256x128_F8_F8_B16_w0_x4_sk4… (gfx950) compiled alone in a fresh process gives the rarer of two binaries in 6 of 45 runs, also with one worker and with address randomization off. The two differ in register allocation and instruction order. Which LLVM pass does it is not found; their equivalence is read from the disassembly, not run. verify no longer depends on the bytes.
  • What the cache cannot see is listed in the skill ("What leaves a stale entry"): values a factory closes over that are not in the key, module globals changed at run time, undeclared files and variables. verify finds them only when a process loads the entry with another value.
  • The variable check sees names read by a literal; a computed name (os.environ.get(f"X_{stage}")) is not seen. The three variables tensor_shim.py reads are inputs of every cache. On the merged head the check was run statically (25 caches, none missing a variable).
  • A preload in a serving process turns COMPILE_ONLY on for the process; launches of other threads meanwhile do not run (as on the JIT path).
  • The launch overhead table above was measured before this revision; a hit's path is unchanged.

PR-specific question

The CI change is one line in .github/scripts/aiter_test.sh: it exports AITER_FLYDSL_AOT_CACHE=verify when the variable is not already set. It changes no workflow file, no permissions block, no token or secret, and adds no input read from PR text (title, body, labels, branch name). The variable is read by aiter/ops/flydsl/aot_cache.py inside the test processes the existing jobs already run, and selects a mode of an on-disk cache under the job's own aiter install. Code from a fork PR runs in those test jobs today under the repository's existing policy; this change gives it no new execution path and no access it did not have.

Changed op tests

None. (tests/test_flydsl_aot_launch.py changes; it is not under op_tests/.)

🤖 Generated with Claude Code

coderfeli and others added 10 commits November 23, 2026 09:39
…d compile hints

An exported object ignores a launcher's Constexpr launch arguments, so an
entry built with one value was loaded by a later process that passed
another. Record the values an entry was built with in its sidecar and
accept a disk entry only for a call that passes them; one in-memory key
launched with two values raises. Strings, None and tuples are keyed too.

Also:
- a specialization_key the cache cannot key on disk (an Enum, a numpy
  scalar) launches through the JIT path instead of raising on every launch
- factory.cache_clear() drops the launchers the cache loaded and keeps the
  factory on the JIT path for the rest of the process
- bitcode a kernel links with link_extern is hashed into its entry, and the
  ROCm device bitcode into the fingerprint
- the fingerprint follows FlyDSL's own list of cache-invalidating
  variables (LLVM_GFX1250_ANY_XNACK_CODEGEN)
- CompilationContext.compile_hints of the caller are part of the disk key
- CI runs the op tests under AITER_FLYDSL_AOT_CACHE=verify

The cache schema goes from 5 to 6: existing entries are rebuilt once.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…inked bitcode

- A loaded launcher with constexpr launch arguments raises when a later
  launch of the key passes another number of arguments: a constexpr the
  first launch left to its default was not compared.
- A tuple constexpr is compared as the disk entry is, so (True, 2) is not
  (1, 2).
- A linked bitcode file may be newer than the process (extracted on first
  use): it is hashed as the compile read it, and no longer keeps the entry
  from being written.
- The device bitcode digest follows the environment instead of being cached
  per process.
- bind_aot leaves a factory result that is not one launcher (a tuple or a
  dict of them) on the JIT path instead of raising.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…h the AOT cache

Every FlyDSL launcher the GEMM and MoE AOT replays compile for gfx942 and
gfx950 now launches through FlyDSLAotCache, so a later process loads the
exported object instead of tracing the kernel again:

- gemm_a16w16_gfx950 (the default HGEMM): launched through _run_compiled
  with its config items as the specialization key, in place of its own
  flyc.compile cache (run_cached, removed)
- the band and skinny HGEMM, the a8w8 4-wave and 8-wave GEMMs
- the MX 2-stage MoE and FHMoE GEMMs, the a4w4 stage 1, the MX stage 2
  (mxmoe_dispatcher.get_g2) and the stage-2 reduce

Compile-only on gfx942 with the full replays, each run twice on one cache
directory: gfx950 GEMM 5240 entries, gfx950 MoE 2882, gfx942 GEMM 80,
gfx942 MoE 132; the second run builds none, no launcher is compiled by the
JIT path and none falls back. Runtime on gfx950 is still to be checked.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…conversion

- gemm_a16w16_gfx950 keys its launches by the device too: a JIT handle
  launches only on the device it was compiled on.
- mxmoe_dispatcher.get_g2 lets the cache compile the launcher an entry is
  built from, so the files that compile runs are recorded with the entry.
- A launcher with constexpr launch arguments may leave trailing runtime
  arguments to their defaults; only a launch with more arguments, or too
  few for the baked ones, raises.
- Constexpr values other than ints, bools and strings are compared as the
  disk entry is (-0.0 is not 0.0).
- A factory whose result cannot be bound is not asked to bind it again on
  every call.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A launch through the cache cost about 4 us more host time than the JIT path
for a factory with 20 keyword arguments (MI308X, trivial kernel: 13.4 us
against 9.4 us), most of it hashing the factory's arguments again:

- A binding keeps the objects the cache loaded for it, by specialization
  key, so a launch no longer hashes the whole key; cache.invalidate() bumps
  an epoch that drops them.
- factory.lazy() keys its handles with functools.cache, as the factory keys
  its launchers.
- The factory wrapper binds a launcher only if it is not bound yet, which
  costs one attribute read on later calls.

Now 9.9 us through factory.lazy() and 11.1 us through an unchanged call
site, against 9.3 us on the JIT path.

Also fixes four statements in the docs that the code contradicted.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ing race

- gemm_a16w16_gfx950 goes back to its own flyc.compile cache (run_cached),
  as on main. It passes its tensors as flyc.from_dlpack dynamic-layout
  arguments, and a function loaded with flyc.load_module takes 27 us to
  launch with three of them, against 9.6 us for the JIT one: a launch would
  cost about 55 us of host time instead of 35 us (MI308X, empty kernel).
- A binding kept a kernel read from the cache under the epoch that followed
  a concurrent invalidate(), and then launched it for good. It now keeps a
  kernel only under the epoch it read before the launch, and lets go of
  what it holds when the epoch moves.

Docs: host time of a launch for the argument kinds the converted kernels
pass, and the replays' artifacts compared with AITER_FLYDSL_AOT_CACHE=0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…fy-only hook pass verify

- gemm_a16w16_gfx950 launches through _run_compiled and the cache again,
  with its config items and device as the specialization key. Its
  dynamic-layout tensor arguments now carry their torch tensor
  (`torch_tensor`, as FlyDSL's TorchTensorJitArg does), which FlyDSL's
  launch-argument fills read instead of making a DLPack view per fill. On
  MI308X with a launcher of the same shape, a launch with prebuilt arguments
  takes 22 us through a loaded object and 23.5 us through the JIT, against
  35 us on the JIT path before and 68-80 us through a loaded object
  without the attribute. Row- and column-major layouts give the same
  results on both paths.
- A compile hook that stops flyc.compile (an AOT replay that only
  identifies the kernels a call requests) leaves nothing to export. That is
  not an export failure: the key takes the JIT path, under verify too.
  op_tests/test_gemm_group32_interface.py relies on it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Corrects the numbers given with the previous commit, which were taken on a
loaded machine. On a quiet MI308X, a launch of a launcher with the HGEMM's
argument shape (three dynamic-layout tensors, a constexpr struct, arguments
prebuilt) takes 11.9 us on the JIT path and 12.5 us through a loaded
object when the arguments carry `torch_tensor`, and 30.8 us through a
loaded object when they do not. The attribute does not change the JIT path.

The full gfx950 GEMM replay now writes 5240 entries, compiles no launcher
on the JIT path, and leaves the same 4874 FlyDSL artifacts, byte for byte,
as with AITER_FLYDSL_AOT_CACHE=0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A procedure and checklist for moving a FlyDSL launch onto the export_to_c
AOT cache and for reviewing such a change: the three launcher patterns,
what must be in the key or specialization_key, compile-only validation
without the target GPU, and a table of the cache's errors and fallbacks.
AGENTS.md and the FlyDSL review instructions point to it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderfeli
coderfeli requested a review from a team November 24, 2026 11: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 8565 --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.

@github-actions github-actions Bot changed the title [FlyDSL] [AOT_TO_C] Fix/flydsl aot key guards hgemm [FlyDSL] [CI] [AOT_TO_C] Fix/flydsl aot key guards hgemm Nov 24, 2026
@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

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

A launch of a FlyDSL kernel that is bound to the AOT cache loads an exported object instead of tracing the kernel. Before this change the cache could hand a later process an object built for other compile-time inputs: `Constexpr` launch arguments, linked bitcode, the ROCm device bitcode, `LLVM_GFX1250_ANY_XNACK_CODEGEN` and the caller's compile hints were not part of an entry's identity. They are now, and the cache falls back to the JIT path where it used to raise for inputs it cannot key. An entry's sources are the files its cache declares, in place of the files a build happened to run.

The GEMM and 2-stage MoE launchers that the AOT replays compile for gfx942 and gfx950 now use the cache, so a serving process no longer traces them on first use. Their compiled code is unchanged.

Validation and unverified scope

MI308X (gfx942), FlyDSL 0.5.3, on the pre-merge head plus the commits after the merge of main (the merged head needs Triton 3.9.0, which that machine lacks; there only lint and a static run of the source check ran: 25 caches, none missing a file).

- Compile-only replays (the prebuild), each run twice on one cache directory, every `flyc.compile` logged: `GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm` (5240 entries), `GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.moe --row-tokens-only` (2877), `GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.gemm` (80), `GPU_ARCHS=gfx942 python -m aiter.aot.flydsl.moe --row-tokens-only` (132). The second run builds nothing; no launcher is compiled by the JIT path. The gfx950 MoE replay exits 1 for one row it rejects before compiling (stage-2 output over the 32-bit buffer limit), with the cache on or off.
- FlyDSL artifacts of those replays against `AITER_FLYDSL_AOT_CACHE=0` runs of an earlier revision: all identical in the last run (gfx950 GEMM 4874, gfx950 MoE 2747, gfx942 GEMM 80, gfx942 MoE 100); see below for earlier runs.
- On the GPU, against the entries the gfx942 replays built, under `0`, `verify` and `1`: `op_tests/test_gemm_a8w8.py` loads 80 entries, no miss; `op_tests/test_flydsl_moe_a16wfp4.py` loads 11, no miss; `op_tests/test_flydsl_moe_gfx942.py` loads none and logs 138 misses (no replay builds those caches). All pass, `verify` finds no stale entry, and no run adds a file to the cache directory.
- `tests/test_flydsl_aot_launch.py` and `tests/test_flydsl_aot_cache.py` under `1`, `verify` and `0`.
- Variables, on the gfx942 GEMM replay over its 80 entries: with a variable only the gfx942 MoE declares set, 0 built; with an undeclared `AITER_FLYDSL_*` variable set, 0 built; with a common one (`AITER_FLYDSL_KERNARG_PRELOAD=0`), 80 built and 0 on the next run; with `FLYDSL_COMPILE_OPT_LEVEL=1`, 80 built in another fingerprint directory.
- `verify`, on the GPU, with a kernel whose code depends on a value outside its key: mode `1` returns the prebuilt value, `verify` raises (`traces to other IR`).
- Before the last commit, not repeated after it: with one kernel file removed from a cache's `sources=`, the gfx942 GEMM replay fails with `_UndeclaredSourceError` and writes no entry; an edit to an undeclared file builds 0, an edit to a declared file rebuilds its 80, reverting builds 0; a kernel linking real bitcode raises when the bitcode is not declared, and replacing declared bitcode makes a new entry with the new result.
- Three independent reviews of the cache; their findings are fixed or listed below.

Unverified or known:

- gfx950 runtime; `verify` on gfx950 and gfx1250 runners.
- The same FlyDSL IR can compile to different GPU binaries. Reproduced with the cache off: `flydsl_mxpsh_96x256x128_F8_F8_B16_w0_x4_sk4…` (gfx950) compiled alone in a fresh process gives the rarer of two binaries in 6 of 45 runs, also with one worker and with address randomization off. The two differ in register allocation and instruction order. Which LLVM pass does it is not found; their equivalence is read from the disassembly, not run. `verify` no longer depends on the bytes.
- What the cache cannot see is listed in the skill ("What leaves a stale entry"): values a factory closes over that are not in the key, module globals changed at run time, undeclared files and variables. `verify` finds them only when a process loads the entry with another value.
- The variable check sees names read by a literal; a computed name (`os.environ.get(f"X_{stage}")`) is not seen. The three variables `tensor_shim.py` reads are inputs of every cache. On the merged head the check was run statically (25 caches, none missing a variable).
- A preload in a serving process turns `COMPILE_ONLY` on for the process; launches of other threads meanwhile do not run (as on the JIT path).
- The launch overhead table above was measured before this revision; a hit's path is unchanged.

PR-specific question

The CI change is one line in `.github/scripts/aiter_test.sh`: it exports `AITER_FLYDSL_AOT_CACHE=verify` when the variable is not already set. It changes no workflow file, no `permissions` block, no token or secret, and adds no input read from PR text (title, body, labels, branch name). The variable is read by `aiter/ops/flydsl/aot_cache.py` inside the test processes the existing jobs already run, and selects a mode of an on-disk cache under the job's own aiter install. Code from a fork PR runs in those test jobs today under the repository's existing policy; this change gives it no new execution path and no access it did not have.

Changed op tests

None. (`tests/test_flydsl_aot_launch.py` changes; it is not under `op_tests/`.)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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
  • 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.

Picks up the Triton 3.9.0 bump (#8266): CI installs that Triton wheel, and
without the matching aiter/utility/fp4_utils.py op_tests/test_gemm_a4w4.py
fails to compile its quant kernel.
zhiding512
zhiding512 previously approved these changes Nov 24, 2026

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

Approving at 4abc1e3 (same head as #8537). I read the cache, binding and launcher changes against the base and the call sites in the tree. I did not find a correctness blocker. The launchers you converted all launch through _run_compiled (get_g2 goes through the run_compiled alias), and their per-call values (grid, M, sizes) are runtime fx.Int32 / fx.Int64 arguments, not Constexpr, so _BakedKernel will not trip on them. No production code calls cache_clear() on any of the converted factories.

I ran the tests myself on MI308X (gfx942), using the pinned flydsl==0.5.3 wheel and the PR worktree:

  • tests/test_flydsl_aot_launch.py: 13 passed under AITER_FLYDSL_AOT_CACHE=1 and 13 passed under verify. That includes test_moe_gfx942_through_aot_cache.
  • tests/test_flydsl_aot_cache.py: 1 passed, once. Its modes 0, 1 miss, 1 hit, verify and the env variant all agreed bitwise in that run, the split_k=2 case included.

I did not run anything on gfx950.

Comments, none blocking (approval is conditional only on a green MI35X run on this head, see 7):

  1. gfx1250 is touched through moe_reduction. The summary says gfx1250 is not touched. But compile_moe_reduction is now an aot_factory, and _run_moe_reduction does not depend on the arch, so a gfx1250 MoE in reduce mode now launches the reduce through the cache. Docs §7 already says this is not validated. Please either say so in the PR body or run one gfx1250 reduce-mode MoE test under verify.

  2. The unexplained split-K mismatch in tests/test_flydsl_aot_cache.py. This test asserts that all modes produce bitwise identical output, and the failing case (64x1024x2048, split_k=2) writes BF16 through the split-K fp32 workspace. If the order of that reduction is not fixed, this is the same class of problem as #8374, not the cache. One way to tell: under the same load, compare mode 0 against mode 0. If that also differs about 1 time in 15, take split_k>1 out of the bitwise cross-mode assertion, or give that case fp32 output. Otherwise it will flake now that CI runs verify.

  3. HGEMM _PARAM_ITEMS[id(param)]. This works today because every param that reaches gemm_a16w16 comes from _gemm_a16w16_gfx950_param_for, whose unbounded cache keeps it alive. An id()-keyed side table is still fragile, though. Two threads making the first call for the same items can each build a param, and the one the cache does not keep can later be collected and its id reused. A future caller that passes its own param gets a KeyError. make_gemm_a16w16_param_and_validate already builds tuple(sorted(kwargs.items())). Computing the same tuple in gemm_a16w16, or returning (param, items) from the cached helper, would remove the side table.

  4. get_g2. bind_aot(compile_g2(), ..., compile_g2) still calls compile_gemm2_a4w4_port, which is uncached, the first time each key is seen. On a disk miss it is called a second time inside the build. So MX stage 2 does not get the "a hit never runs the factory" benefit that .lazy() gives the other launchers. This is not a correctness issue. A _LazyLauncher(_AotBinding(cache, key, compile_g2, compile_g2)) handle, built the way aot_factory.lazy builds one, would give stage 2 the same benefit.

  5. Silent coverage loss on a FlyDSL bump. _device_bitcode_digest() falls back to "unknown:<Exc>" and _flydsl_cache_env() falls back to () when FlyDSL internals move. Both fallbacks are silent, so the fingerprint quietly stops covering those inputs. _link_libs fails loudly under verify, which is good. A one-line test that asserts not _device_bitcode_digest().startswith("unknown:") on the pinned FlyDSL would make the next bump fail CI instead.

  6. Steady-state host cost and wheel size. These are trade-offs worth stating next to the breaking changes:

    • A cache hit costs +1.0 us per launch for the MX MoE GEMMs and +2.1 us for preshuffle, blockscale and 8-wave, against the JIT path. That does not matter under graph capture, but eager decode pays it on every launch.
    • The body gives about 53 MiB in the wheel for the gfx950 GEMM entries, and docs §7 says 180 MB on disk where the body says 146 MiB. What is the total wheel growth once the 2882 MoE entries are included? And does the wheel still ship FlyDSL's own .pkl artifacts for the same kernels?
  7. Process.

    • #8537 is still open at the same head. Closing one of the two keeps reviews and CI in one place.
    • When I looked, the standard MI35X tests on this head were still in progress, with no results yet. The evidence for gfx950 at runtime is the earlier #8537 run (6/8 shards; the a4w4 failure is fixed by the merge of main, and the hgemm failure is #8374). A full green run on 4abc1e3 before merging would close that gap.

An entry used to record the files its build ran (sys.setprofile) and
compare them on a lookup. What a build runs depends on what the process
ran before (a memoized factory, a module already imported), so the
recorded set could miss a file, and an edit to it left stale entries.

Each cache now lists the files its launchers are built from, as
FlashInfer's gen_jit_spec(name, sources) does:

    @aot_factory("my_kernel", sources=["kernels/my_kernel.py", ...])

- The contents of the declared files, and the values of the variables
  named in env=, are hashed into the digest that names an entry. An edit
  makes new entries for that cache only; going back finds the earlier
  ones. The file creating the cache is always a source.
- Nothing is detected at run time. A forgotten source is checked for
  when an entry is built: a declared kernel file that imports an
  undeclared kernel file, or linked bitcode that is not declared, raises
  _UndeclaredSourceError in every mode. A unit test runs the import
  check over every cache in the tree.
- A declared .py edited after the process imported aiter's FlyDSL code
  keeps that cache on the JIT path for the process.
- bind_aot loses its rebuild argument, aot_factory's extra_sources is
  now sources, and the cache schema is 7.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
coderfeli and others added 2 commits November 24, 2026 16:12
ptr_buf_tensor and its helpers emit code, so the source check no longer
exempts the file: the caches whose kernels import it declare it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…they were hashed

- The source digest is read once per process, but a kernel module may be imported later (a factory's first miss, the trace). An entry is now stored only if its declared sources still have the hashed contents, checked before and after the build.
…r XCD

- Kernels size themselves by these per-arch constants, which live outside aiter/ops/flydsl where no cache declares sources.
- kernels_common.py, tensor_shim.py, buffer_ops.py and the jit hardware tables (chip_info.py, lds_capacity.py) are sources of every cache; a cache lists only its own files.
AndreasKaratzas added a commit that referenced this pull request Nov 26, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
AndreasKaratzas added a commit that referenced this pull request Nov 27, 2026
chip_info.py is a common source of every FlyDSL AOT cache. The partition
code reads HIP_VISIBLE_DEVICES, CUDA_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES to map a torch device to its GPU. The guard of #8565
then rejects every cache, and the wheel build fails in run_aot.

These variables select the GPU only. The arch and the CU count of that GPU
are already in the cache fingerprint, and a replay sets them to "". Add
them to ENV_NOT_CODE, like GPU_ARCHS and CU_NUM, instead of keying every
entry on the visible GPUs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
(cherry picked from commit 1016ff2)
Signed-off-by: Andreas Karatzas <[email protected]>
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