jit

jit – "Failed in nopython mode pipeline" error, despite not using nopython in numba

jit – "Failed in nopython mode pipeline" error, despite not using nopython in numba Question: I am using value function iteration to solve a complex dynamic programming problem with many states. I want to use numba/jit to speed up my code (and eventually parallelize the for loops). When I use the @jit decorator in my …

Total answers: 1

Returning a distribution object from a jittable function

Returning a distribution object from a jittable function Question: I want to create a jittable function that outputs a distrax distribution object. For instance: import distrax import jax import jax.numpy as jnp def f(x): dist = distrax.Categorical(logits=jnp.sin(x)) return dist jit_f = jax.jit(f) a = jnp.array([1,2,3]) dist = jit_f(a) Currently this code gives me the following …

Total answers: 1

Caching Behavior in JAX

Caching Behavior in JAX Question: I have a function f that takes in a boolean static argument flag and performs some computation based on it’s value. Below is a rough outline of this function. @partial(jax.jit, static_argnames=[‘flag’]) def f(x, flag): # Preprocessing if flag: … else: … # Postprocessing Each time f is called with a …

Total answers: 1

Why is this JAX jitted function so much slower than the non-jitted JAX version?

Why is this JAX jitted function so much slower than the non-jitted JAX version? Question: I’m in the process of rewriting some code from pure Python to JAX. I have a function that I need to call a lot. Why is the jitted version of the following function so much slower than the non-jitted version? …

Total answers: 1

How to un-JIT-compile a function which is called by a JIT-compiled function

How to un-JIT-compile a function which is called by a JIT-compiled function Question: I have a script which performs some calculations on some given arrays. These calculations are performed thousands of times, so naturally I want to use JAX’s JIT decorator to speed up these calculations. I have several functions which are called from some …

Total answers: 1

JAX – jitting functions: parameters vs "global" variables

JAX – jitting functions: parameters vs "global" variables Question: I’ve have the following doubt about Jax. I’ll use an example from the official optax docs to illustrate it: def fit(params: optax.Params, optimizer: optax.GradientTransformation) -> optax.Params: opt_state = optimizer.init(params) @jax.jit def step(params, opt_state, batch, labels): loss_value, grads = jax.value_and_grad(loss)(params, batch, labels) updates, opt_state = optimizer.update(grads, opt_state, …

Total answers: 1

Why does my @jit decorated function return zeros only when parallel=True?

Why does my @jit decorated function return zeros only when parallel=True? Question: I am writing a function that I want to optimize with Numba. The function performs operations on two vectors along with other operations with some scalars. When I set @jit’s parallel argument to False everything runs fine but when it is set to …

Total answers: 1

Concatenate python tuples in numba

Concatenate python tuples in numba Question: I’m looking to fill up an array of zeros with numbers taken from some tuples, easy as that. Usually, this is not a problem even when the tuples are not the same length (which is the point here). but it seems it won’t compile and I cannot figure out …

Total answers: 2