jax

finding the maximum of a function using jax

finding the maximum of a function using jax Question: I have a function which I would like to find its maximum by optimizing two of its variables using Jax. The current code that I have currently, which does not work, reads import jax.numpy as jnp import jax import scipy import numpy as np def temp_func(x,y,z): …

Total answers: 1

How to vmap over cho_solve and cho_factor?

How to vmap over cho_solve and cho_factor? Question: The following error appears because of the last line of code below: jax.errors.ConcretizationTypeError Abstract tracer value encountered where concrete value is expected… The problem arose with the bool function. It looks like it is due to the lower return value from cho_factor, which _cho_solve (note underscore) requires …

Total answers: 2

JAX performance problems

JAX performance problems Question: I am obviously not following best practices, but maybe that’s because I don’t know what they are. Anyway, my goal is to generate a tubular neighborhood about a curve in three dimensions. A curve is give by an array of length three f(t) = jnp.array([x(t), y(t), z(t)]). Now, first we compute …

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

Nested vmap in pmap – JAX

Nested vmap in pmap – JAX Question: I currently can run simulations in parallel on one GPU using vmap. To speed things up, I want to batch the simulations over multiple GPU devices using pmap. However, when pmapping the vmapped function I get a tracing error. The code I use to get a trajectory state …

Total answers: 2

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 with JIT and custom differentiation

JAX with JIT and custom differentiation Question: I am working with JAX through numpyro. Specially, I want to use a B-spline function (e.g. implemented in scipy.interpolate.BSpline) to transform different points into a spline where the input depends on some of the parameters in the model. Thus, I need to be able to differentiate the B-spline …

Total answers: 2