What happens when a JAX loop or branch depends on an input value? Ordinary Python control flow cannot be traced reliably. Structured control flow replaces it with jax.lax primitives that JAX can compile and differentiate. section 5.3.3 section 3.6
Use the lower-level API when:
- A small set of concrete values is acceptable; mark arguments static, understanding that new values trigger recompilation. section 5.5
A traceable loop and branch
f5 = lambda x: jax.lax.fori_loop(0, x, lambda i, v: v + i, 0) relu = lambda x: jax.lax.cond(x > 0, lambda x: x, lambda x: 0.0, x) Both functions accept input-dependent values while remaining compatible with make_jaxpr() and jit().
