Repository navigation
[FlyDSL] [CI] [Build] Add an on-disk AOT cache for the FlyDSL GEMM launchers - #8356
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…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
left a comment
There was a problem hiding this comment.
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.
- 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.oeven 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. - 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:mi300xalso 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.
| m, | ||
| n, | ||
| fx.Stream(torch.cuda.current_stream()), | ||
| current_stream_arg(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done in 3397166: the preshuffle launch now passes current_stream_arg(Out.device), matching the workspace/semaphore stream and the other launchers.
| ### 5.1 gfx942: `flydsl_preshuffle_gemm_a8` | ||
|
|
||
| ```python | ||
| key = (tuple(sorted(compile_kwargs.items())), x_scale.dtype, w_scale.dtype) |
There was a problem hiding this comment.
Nit: in the code this key also ends with XQ.device (memory only, see §4.1).
There was a problem hiding this comment.
Done in 3397166: the §5.1 key now ends with XQ.device.
…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
left a comment
There was a problem hiding this comment.
Re-reviewed at 576954f.
Resolved:
- Cross-checkout hits. I re-ran the earlier check with
_portable,_entry_currentand_findfrom this revision. A tree with an edited kernel now misses, and the same files installed at another path hit. - FlyDSL fingerprint. The
RECORDlookup matches the dev1059 wheel: 192 package entries, 14 of them.so. - The blockscale
extra_sources, the--checkvariables and the mxscalestream=fix also look right.
I'm still not approving, for two reasons:
- New: on Python 3.11+, the build-time environment tracking doesn't record most reads (inline on
_ENV_PLUMBING). The newcheck_pathsassertions depend on that tracking, so they should fail on the py3.12 standard-test image. - 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_fullandci:mi300x.
The two nits and the gfx950-coverage suggestion from the last round are unchanged. None of them block.
|
|
||
|
|
||
| # os.getenv, os.environ.get and `in` reach _Environ.__getitem__ through these. | ||
| _ENV_PLUMBING = frozenset({os.__file__, _collections_abc.__file__}) |
There was a problem hiding this comment.
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}
)There was a problem hiding this comment.
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]>
|
Re-tested #8356 ( Setup. Same as my FlyDSL#1413 test: DeepSeek-V4-Pro on 8× gfx950, DP attention, 8k/1k, concurrency 64, CI image (
GSM8K 3-shot with P is 0.9515. One pass per arm; A3 matches the earlier A2 baseline (1793).
Remaining asks:
I haven't repeated @zhiding512's points (py3.11+ |
…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]>
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
Thanks for the end-to-end re-test. Addressed in d865032 (PR body updated):
|
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]>
|
Non-blocking follow-up for symlinked installs. Resolve filenames before filtering, then invalidate entries that may have been built without their source dependencies. |
Supersedes #8287: the same AOT cache changes, pinned to FlyDSL 0.5.1 and without #8287's
radix_topk_one_blockworkaround.Summary
This PR adds an on-disk AOT cache for the FlyDSL GEMM launchers (
aiter/ops/flydsl/aot_cache.py).flyc.compile(..., compile_only=True)and exported withexport_to_c.flyc.load_module, so a cold process skips MLIR tracing and the LLVM compile.Converted launchers:
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).<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.PREBUILD_KERNELS=1) still hit after install.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--checkreads the entries a build made.from .common import TILE_Mrecordscommon.py), resolved statically through re-exports, star imports, namespace packages and the names a value is computed from. This replaces hand-writtenextra_sources.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.chip_info.get_gfx()records its value, since underGPU_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.fcntl.flock. An entry is published atomically,.jsonfirst and then.o. Concurrent processes and parallel replays never compile or export the same entry twice.AITER_FLYDSL_AOT_CACHE=0|1|verify(default1) andAITER_FLYDSL_AOT_CACHE_DIR.tensor_shimgainscurrent_raw_stream/current_stream_arg.docs/flydsl_aot_cache.md: design, invalidation, prebuild interplay and limits.torch.ops.aiter_routedrun 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)
Testing
Documentation
docs/flydsl_aot_cache.md)Dependencies
FlyDSL APIs used, classified by FlyDSL's
docs/api_stability.md:flyc.compile(compile_only=True),CompiledFunction.export_to_c,flyc.load_module,flyc.JitArgumentRegistry,flydsl.compiler.protocol.cache_signatureandflydsl.runtime.device.get_rocm_arch.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._is_stream_parammarker onfx.Stream, to recognize stream arguments and build a null-stream placeholder.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.flyc.load_modulelanded in FlyDSL CI: Move Triton tests from TW cluster to internal cluster #1451 and was first released in 0.5.1.dev1058. This PR bumps the FlyDSL pin from 0.5.0 to 0.5.1 inrequirements.txt,pyproject.toml,setup.pyand.github/requirements/triton-test.txt.shuffle_scale_a16w4andshuffle_weight_a16w4#1454): dev1058 cannot compile an rmem tensor written inside a tracedif('ub.poison' op register operand/result remain after rmem SSA promotion, from FlyDSL Fix gemm tuner error mi350 #1313), whichradix_topk_one_block.pydoes. Fix inconsistent tensor shapes betweenshuffle_scale_a16w4andshuffle_weight_a16w4#1454 fixes it in FlyDSL (Fix inconsistent tensor shapes betweenshuffle_scale_a16w4andshuffle_weight_a16w4#1454, foldingfly.get_iteroffly.make_view), so no aiter kernel changes.Breaking Changes
None.
AITER_FLYDSL_AOT_CACHE=0to get the previous pure-JIT behavior.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
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.pypasses again on MI308X. With the same wheel, the unmodifiedradix_topk_one_blockpassestest_topk_per_row,test_topk_per_row_stableandtest_qsa(110 passed).python3 -m pytest tests/test_flydsl_aot_cache.py.load_modulecreates a HIP context only on the current device.GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemm --csv a8w8_mxfp8_bpreshuffle_tuned_gemm.csv.AITER_FLYDSL_AOT_CACHE=0and two runs of=1give the same 62gpu.binaryblobs (from the FlyDSL cache.pklfiles).mainbuilt with the previous FlyDSL.=1run rebuilds nothing.GPU_ARCHS=gfx950 python -m aiter.aot.flydsl.gemmover all tuned CSVs.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. Editinggemm_tune/flydsl_gemm_a8w8_blockscale_common.pymakes the blockscale entries stale, and restoring it makes them current again.flydsl-0.5.0.dist-infoholding onlyREQUESTED(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 raisedTypeErroron importlib versions wheremetadataisNone, so the whole cache fell back to JIT..ocarries 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 throughobjcopy --strip-debug: 263 KB → 24 KB per entry (about 90 MB for the full cache). The same fix is going upstream to FlyDSL.0(pure JIT) still launches only on the first GPU a process compiled for. This is a FlyDSL JIT limitation that exists onmaintoo (docs §7, issue 4); the AOT path is not affected.main; they were not executed.gemm_a16w16(hgemm), the a8w4comm_fused_moeand gfx1250 mxfp8..lockfiles is not implemented.flockassumes a local filesystem for the cache directory.PR-specific question
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):0runs the JIT and writes nothing;.o/.jsonpair per entry, with no fallback;flyc.load_module(before 0.5.1.dev1058), where every mode would run the JIT.tests/because it is not an op test;split_tests.shlists it explicitly, since it scans onlyop_tests/.🤖 Generated with Claude Code