Persistent compilation cache key depends on the cache directory's path when the XLA kernel cache is enabled
Description
When using the jax_persistent_cache_enable_xla_caches config to enable the kernel cache (by setting it to "all" or "xla_gpu_kernel_cache_file"), every persistent cache key depends on the cache directory's absolute path. So when a cache dir is moved (or mounted at a different path), it never hits.
Mechanism:
compiler.py sets debug_options.xla_gpu_kernel_cache_file to <cache_dir>/xla_gpu_kernel_cache_file, and _hash_serialized_compile_options in cache_key.py hashes it.
Notice that the sibling option xla_gpu_per_fusion_autotune_cache_dir is cleared before hashing (#35699).
Reproducer (CPU)
fill a cache in one directory, copy it, and run the same program against the copy.
import os, shutil, subprocess, sys, tempfile
CHILD = """
import sys, jax, jax.numpy as jnp
jax.config.update("jax_compilation_cache_dir", sys.argv[1])
jax.config.update("jax_persistent_cache_min_compile_time_secs", 0)
jax.config.update("jax_persistent_cache_enable_xla_caches", sys.argv[2])
jax.jit(lambda x: jnp.tanh(x @ x.T).sum())(jnp.ones((128, 128))).block_until_ready()
"""
def entries(d):
return sorted(f for f in os.listdir(d) if f.endswith("-cache"))
for mode in ["xla_gpu_per_fusion_autotune_cache_dir", "xla_gpu_kernel_cache_file"]:
a = tempfile.mkdtemp()
subprocess.run([sys.executable, "-c", CHILD, a, mode], check=True)
b = a + "_copy"
shutil.copytree(a, b)
subprocess.run([sys.executable, "-c", CHILD, b, mode], check=True)
print(f"{mode}: copy has {len(entries(b))} entries -> {'hit' if entries(b) == entries(a) else 'miss'}")Output (JAX_PLATFORMS=cpu):
xla_gpu_per_fusion_autotune_cache_dir: copy has 3 entries -> hit
xla_gpu_kernel_cache_file: copy has 6 entries -> missSame result on main (f5181873d). I ran into this on TPU through sglang-jax, which sets jax_persistent_cache_enable_xla_caches="all": two hosts with the same toolchain shared no cache entries because their cache directories were spelled differently.
Suggested fix:
clear xla_gpu_kernel_cache_file before hashing, as is done for xla_gpu_per_fusion_autotune_cache_dir (add it to xla_flags_to_exclude_from_cache_key and blank it in _hash_serialized_compile_options).
I have a small patch with a test and can open a PR if this approach is welcome.
System info (python version, jaxlib version, accelerator, etc.)
jax: 0.11.2
jaxlib: 0.11.2
numpy: 2.5.3
python: 3.12.14 (main, Sep 24 2026, 17:46:32) [Clang 22.1.3 ]
device info: cpu-1, 1 local devices"
process_count: 1
platform: uname_result(system='Darwin', node='Tsvikas-MacBook-Pro.local', release='25.6.0', version='Darwin Kernel Version 25.6.0: Sat Jul 11 15:26:21 PDT 2026; root:xnu-12377.161.13~4/RELEASE_ARM64_T6000', machine='arm64')
JAX_PLATFORMS=cpuSource: jax-ml/jax