CPU: deserializing a compiled executable crashes the process (SIGBUS), breaking the persistent compilation cache
Description
Description
With the persistent compilation cache enabled, the second process that loads one particular
cached executable dies with SIGBUS (occasionally SIGILL) instead of running it. The first
process (compile + write) works and gives correct results. The crash is in executable
deserialization itself: the attached script reproduces it without the compilation cache, by
compiling a StableHLO module, serializing the executable, and calling
backend.deserialize_executable() in a fresh process.
It is not a matter of size: synthetic jit(vmap(optimistix.minimise(...))) programs whose
serialized executables are 110 MB deserialize fine (slowly), while this one (77 MB serialized,
34 MB of StableHLO text) crashes every time. The module comes from a real application (a
binned-likelihood fit: a vmapped L-BFGS while loop over a large objective with many
gathers/scatters); every floating-point constant in it has been replaced by random values
and all locations stripped, and it still crashes.
Reproducer
Files: jax_cpu_deserialize_crash_repro.zip (attached, 5.6 MB: scrubbed.mlir + raw_repro.py, also shown below).
# raw_repro.py
import sys, time
import jax
from jax._src import compiler, xla_bridge
from jax._src.interpreters import mlir
from jax._src.lib import xla_client as xc
from jax._src.lib.mlir import ir
jax.config.update("jax_enable_x64", True)
phase, mlir_path, bin_path = sys.argv[1:4]
backend = xla_bridge.get_backend("cpu")
devices = xc.DeviceList(tuple(backend.devices()[:1]))
options = compiler.get_compile_options(1, 1, backend=backend)
t = time.time()
if phase == "compile":
with mlir.make_ir_context():
module = ir.Module.parse(open(mlir_path).read())
exe = backend.compile_and_load(module, executable_devices=devices, compile_options=options)
data = exe.serialize() if hasattr(exe, "serialize") else backend.serialize_executable(exe)
open(bin_path, "wb").write(data)
print(f"compiled + serialized {len(data)} bytes in {time.time() - t:.1f}s")
else:
data = open(bin_path, "rb").read()
exe = backend.deserialize_executable(data, devices, options)
print(f"deserialized {len(data)} bytes in {time.time() - t:.1f}s")
$ python raw_repro.py compile scrubbed.mlir exe.bin
compiled + serialized 76696941 bytes in 127.8s
$ python raw_repro.py load scrubbed.mlir exe.bin
Bus error: 10 # exit code 138, every time
Through jax.jit with jax_compilation_cache_dir set, the same module crashes the second
process at the cache read.
System info
- jax 0.10.2, jaxlib 0.10.2 (CPU), optimistix 0.1.0, equinox 0.13.8
- macOS 26.5.2, Apple M1 Pro (arm64), Python 3.11
XLA_FLAGS=--xla_cpu_parallel_codegen_split_count=1does not change it.
Workaround
We compile this executable with the persistent cache disabled (every new process recompiles it).
System info (python version, jaxlib version, accelerator, etc.)
jax 0.10.2, jaxlib 0.10.2 (CPU), optimistix 0.1.0, equinox 0.13.8 macOS 26.5.2, Apple M1 Pro (arm64), Python 3.11 XLA_FLAGS=--xla_cpu_parallel_codegen_split_count=1 does not change it.
I'd like to work on this.
The issue is that serialized executables contain memory-mapped regions that are not properly handled during deserialization, causing SIGBUS crashes in the second process. The fix is to ensure that serialized executables are self-contained and do not rely on memory-mapped regions from the original process.
I'll add a regression test based on the reproducer in the issue.