﻿# JAX static configuration: hashable metadata and changing array data have different roles

Design JAX compiled function arguments with immutable static configuration and dynamic array leaves, avoiding an ever-growing set of accidental specializations.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-jax-static-config-cache-identity/
Language: en

## Decide what should specialize the program

A GPU inference function accepts a normalization mode, model weights and a request identifier. These arguments do not all deserve the same compilation behavior. The [JAX JIT reference](https://docs.jax.dev/en/latest/_autosummary/jax.jit.html) describes static arguments as compile-time constants whose values contribute to cache keys. A small set of algorithm modes can sensibly specialize the program. Unique request identifiers generally should not produce a new specialization for every call.

## Keep mutable data out of static identity

Static values must be hashable and immutable. Making a custom configuration object technically hashable does not establish that mutating its contents has safe semantics. Separate structural decisions from numerical data that changes between steps. In an embedding transform, the choice of algorithm may be configuration while the calibration vectors are data. This distinction also clarifies which changes should produce different compiled behavior and which should simply feed new values into the existing computation.

## Express the boundary in a registered container

The [dataclass registration reference](https://docs.jax.dev/en/latest/_autosummary/jax.tree_util.register_dataclass.html) distinguishes static metadata fields from dynamic data fields. It explicitly excludes array objects from metadata. Use that boundary to make a model container's contract visible. Avoid hiding weights inside a static object merely to pass a complex Python instance into a compiled function; the numerical state should remain accessible as compatible data leaves.

## Review the number of intended variants

The [JIT compilation guide](https://docs.jax.dev/en/latest/jit-compilation.html) explains specialization and caching. List the static values a real workload will use, including uncommon modes and optional settings. Then compare that set with observed compilation activity. Repeatedly changing shape, dtype or static configuration is different from processing new numerical contents with the same program contract. Do not attribute every new compilation to a cache failure without first checking those deliberate distinctions.

## Preserve configuration with the result

Record static mode choices and the model-data revision used for an experiment. A reusable executable and a reproducible scientific result are related but separate artifacts. The guides on [CUDA Graphs and compilation](/journal/cuda-graphs-vs-torch-compile/) and [mixed-precision accumulation](/journal/learn-mixed-precision-accumulation/) provide useful comparisons. Their relevance is the need to identify exactly which program and numerical contract a measured result represents, rather than treating a compiled function name as a complete description.
