pyhs3.jaxify¶
- pyhs3.jaxify(output, *, inputs=None)[source]¶
Convert a PyTensor expression into a JAX-callable
JaxifiedGraph.The returned callable is not jitted: calling it runs JAX eagerly, one operation at a time, which on a large likelihood is orders of magnitude slower than the same call wrapped in
jax.jit. Jit it for repeated calls:jg = jaxify(model.log_prob) nll = jax.jit(lambda params: -jg(**params)[0])
- Parameters:
- Returns:
Wrapper exposing the compiled JAX function plus input metadata.
- Return type:
Examples
>>> import math >>> import pytensor.tensor as pt >>> x = pt.scalar("x") >>> mu = pt.scalar("mu") >>> sigma = pt.scalar("sigma") >>> pdf = pt.exp(-0.5 * ((x - mu) / sigma) ** 2) / ( ... sigma * pt.sqrt(pt.constant(2 * math.pi, dtype="float64")) ... ) >>> from pyhs3.transpile import jaxify >>> jg = jaxify(pdf) >>> float(jg(x=0.0, mu=0.0, sigma=1.0)[0]) 0.3989422804014327