liveBook · Manning

Ahead-of-time compilation

As explained in Deep Learning with JAX

Compilation performed before execution time so the resulting code can run without a warm-up JIT step.

Need predictable startup time instead of paying compilation cost on the first call? Ahead-of-time (AOT) compilation moves compilation before execution, so the resulting function runs without a JIT warm-up. section 5.2.3 section 5.1.1

JAX first stages a Python function for a fixed input type signature, lowers the staged representation to StableHLO through MLIR and XLA, and compiles device-specific code for CPU, GPU, or TPU. The AOT API controls the lowering and compilation stages before invocation. section 5.2.3 section 5.5

Compile SELU before calling it

A JIT-wrapped function compiles when first invoked, while an AOT function compiles directly: selu_jit = jax.jit(selu) selu_aot = jax.jit(selu).lower(1.0).compile() The side effect inside selu runs during the direct AOT compilation, but during the first call to selu_jit. Both functions then produce the same result for the compiled signature. section 5.2.3

Keep these constraints in mind:

  • Use AOT when compilation timing matters; use JIT when compilation on first use and later reuse better fit the call pattern. section 5.2.3 section 5.1.1

How Deep Learning with JAX covers it

How deep it goes
Explains staging, StableHLO lowering, device compilation, fixed signatures, and transformation limits without detailing compiler internals.
Examples
Demonstrates SELU compilation, observable side effects, mismatched scalar types, and attempted batching with vmap.
What it assumes
Assumes familiarity with Python functions, JAX arrays, jax.jit(), tracing, and function invocation.
What you can do after
Apply it via JAX's jax.stages API and lower().compile() workflow when startup timing and compilation control matter.
How it connects
Connects JIT compilation with tracing, MLIR, XLA, StableHLO, and device-specific code generation.

Also explained in

Compare how 3 books explain ahead-of-time compilation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with JAX. The section links point to the parts of the book it draws on.