JAX gotchas cheat sheet#
A quick-reference list of the ways JAX will surprise you when you arrive from NumPy or Fortran. Chapter 1.1 walks through most of these with examples; this page is the condensed version to keep open while you work. See also the official JAX sharp bits page.
Gotcha |
Symptom |
Fix |
Shown in |
|---|---|---|---|
Arrays are immutable |
|
|
1.1 |
float32 by default |
Gradients disagree with finite differences; drifting budgets |
|
3.5 |
Python |
|
|
1.1 |
Python |
Minutes-long compile times |
|
1.1 |
Side effects in jitted functions |
|
|
1.1, 3.5 |
Implicit global RNG |
No |
Explicit keys: |
1.1 |
Recompilation |
First call after a shape/dtype change is slow |
Keep shapes static; pad instead of resizing |
1.1 |
|
|
The “double- |
3.3, 3.5 |
Thresholds/switches in physics |
Loss varies but gradient is exactly zero |
Smooth, reformulate, or |
3.3 |
Long-rollout |
Adjoint memory grows with steps |
|
3.2 |
Integer/weak-type promotion |
Silent dtype surprises in mixed expressions |
Be explicit with dtypes in model constants |
— |
(Starter list — group members: add gotchas as you hit them, one row each.)