Skip to content

[Bugfix] Drop arch env vars from the JIT cache key (fix AOT cache misses) - #624

Merged
coderfeli merged 3 commits into
mainfrom
fix-aot-cache-key-arch-env
Jun 2, 2026
Merged

coderfeli merged 3 commits into
mainfrom
fix-aot-cache-key-arch-env

Conversation

@coderfeli

Copy link
Copy Markdown
Collaborator

Motivation

After #597 hardened the JIT cache key to fold whitelisted code-gen env vars into the key, AOT-precompiled-then-shipped caches stopped being hit at runtime. This surfaces downstream in aiter as RuntimeError: AOT cache miss for FlyDSL MoE kernels under its strict check_aot_cache=True tests (the cache dir is present with the right manager_key, but the inner key never matches).

Root cause

_cache_invalidating_env_values() folds these arch selectors into the key: ARCH, FLYDSL_GPU_ARCH, HSA_OVERRIDE_GFX_VERSION. Their only effect is to pick the target arch — which is already in the key via ("_target_", GPUTarget).

The arch can be supplied two ways, and detect_target() normalizes both to the same GPUTarget:

  • AOT pre-compilation runs on a GPU-less build host and injects ARCH=gfx950 / FLYDSL_GPU_ARCH=gfx950 via env.
  • Runtime has those env vars unset; arch comes from device detection.

So the resolved ("_target_", GPUTarget(arch="gfx950", ...)) is identical in both, but the raw ("_env_", (... "ARCH"="gfx950"/"" ...)) segment diverges ("gfx950" at build vs "" at runtime) → cache key mismatch → guaranteed miss for any shipped AOT cache.

Fix

Drop the three arch selectors from _CACHE_INVALIDATING_ENV_VARS. No key precision is lost — any arch change still changes ("_target_", ...). Genuine code-gen knobs (FLYDSL_COMPILE_OPT_LEVEL, FLYDSL_COMPILE_BACKEND, FLYDSL_COMPILE_LLVM_DIR, FLYDSL_DEBUG_ENABLE_DEBUG_INFO, FLYDSL_EXTRA_SOURCE_DIRS) stay in the key.

Tests

Existing cache-key tests are unaffected:

  • test_compile_hints.py::test_different_arch_gives_different_key asserts the change flows through ("_target_", ...) (it resets _sig and checks t1.arch != t2.arch) — still holds, since ARCH still feeds detect_target().
  • test_jit_cache_key_completeness.py env-drift tests use FLYDSL_COMPILE_OPT_LEVEL (retained).

Follow-up note

FLYDSL_COMPILE_LLVM_DIR / FLYDSL_EXTRA_SOURCE_DIRS are path-like and could similarly diverge build-vs-runtime for shipped AOT caches; they're kept here because their contents can affect codegen. A more robust long-term approach would key on their effect (e.g. resolved LLVM version / source content hash) rather than the raw path string. Out of scope for this fix.

🤖 Generated with Claude Code

…ses)

The hardened cache key (#597) folds whitelisted code-gen env vars into the key
via _cache_invalidating_env_values(). Among them, ARCH / FLYDSL_GPU_ARCH /
HSA_OVERRIDE_GFX_VERSION are pure arch selectors whose only effect is to pick the
target arch -- which is already in the key via ("_target_", GPUTarget).

Keeping them double-counts arch and, worse, makes the key depend on *how* arch
was supplied: AOT pre-compilation on a GPU-less build host injects ARCH=<gfxNNN>
via env, while at runtime those vars are unset and arch comes from the device.
detect_target() normalizes both paths to the same GPUTarget, but the raw "_env_"
segment diverges ("gfx950" vs ""), so an AOT-precompiled-then-shipped cache can
never be hit at runtime -- surfacing downstream (e.g. aiter's strict
check_aot_cache MoE tests) as "AOT cache miss" despite the cache being present.

Drop the three arch selectors from _CACHE_INVALIDATING_ENV_VARS. No key
precision is lost: any arch change still changes ("_target_", ...). Genuine
code-gen knobs (opt level, backend, llvm dir, debug info, extra source dirs)
stay in the key. Existing tests are unaffected: the arch-drift test asserts the
change flows through ("_target_", ...) (it resets _sig and checks t.arch), and
the env-drift tests use FLYDSL_COMPILE_OPT_LEVEL.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
coderfeli added a commit to ROCm/aiter that referenced this pull request Jun 2, 2026
FlyDSL 0.2 (ROCm/FlyDSL#597) renamed JitFunction._make_cache_key to
_build_full_cache_key. The AOT cache-miss reporter called the old name, which
now raises (swallowed) and prints "looked-up cache_key: <unknown>". Use getattr
with a fallback so the diagnostic works on both 0.1.x and 0.2.x. Diagnostic-only;
the actual AOT cache hit/miss is fixed on the FlyDSL side (ROCm/FlyDSL#624).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderfeli
coderfeli merged commit 28a18d3 into main Jun 2, 2026
8 checks passed
@coderfeli
coderfeli deleted the fix-aot-cache-key-arch-env branch June 2, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant