JAX Frequently Asked Questions (FAQ) — JAX documentation
If you have a Python function that changes behavior after using jax.jit(), perhaps your function uses global state, or has side-effects. In the following code, the impure_func uses the global y and has a side-effect due to print: Without jit the output is: and with jit it is: For jax.jit(), the function is executed once using the Python interpreter, at which time the Inside printing happens, and the first value of y is observed. Then, the function is compiled and cached, and executed multiple times with different values of x, but with the same first value of y. Additional reading: JAX - The Sharp Bits Sometimes users are surprised by the fact that wrapping a function with jit() can change the function’s outputs. For example: This slight difference in output comes from optimizations within the XLA compiler: during compilation, XLA will sometimes rearrange or elide certain operations to make the overall computation more efficient. In this case, XLA utilizes the properties of the logarith
Frequently asked questions (FAQ) # We are collecting answers to frequently asked questions here. Contributions welcome! jit changes the behavior of my function # If you have a Python function that changes behavior after using jax.jit() , perhaps your function uses global state, or has side-effects. In the following code, the impure_func uses the global y and has a side-effect due to print : y = 0 # @jit # Different behavior with jit def impure_func ( x ): print ( "Inside:" , y ) return x + y for y in range ( 3 ): print ( "Result:" , impure_func ( y )) Without jit the output is: Inside : 0 Resu
Explore this link on the map →related reading
- 🔪 JAX - The Sharp Bits 🔪 — JAX documentationjax.readthedocs.io
- Quickstart: How to think in JAX — JAX documentationjax.readthedocs.io
- Just-in-time compilation — JAX documentationjax.readthedocs.io
- GitHub - jax-ml/jax: Composable transformations of Python+NumPy programs: differentiate, vectorize, JIT to GPU/TPU, and more · GitHubgithub.com
- Why You Should (or Shouldn't) be Using Google's JAX in 2023assemblyai.com
- Key concepts — JAX documentationjax.readthedocs.io
- Why You Should (or Shouldn't) be Using Google's JAX in 2023assemblyai.com
- Introduction to debugging — JAX documentationjax.readthedocs.io
- Just In Time Compilation with JAX — JAX documentationjax.readthedocs.io
- JAX As Accelerated NumPy — JAX documentationjax.readthedocs.io
- A guide to JAX for PyTorch developers | Google Cloud Blogcloud.google.com
- jax.Array — JAX documentationjax.readthedocs.io