Skip to content

fix: jax backend tolist for tracers in logging #2580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pyhf/tensor/jax_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

config.update('jax_enable_x64', True)

import jax
from jax import Array
import jax.numpy as jnp
from jax.scipy.special import gammaln, xlogy
Expand All @@ -14,6 +15,10 @@
log = logging.getLogger(__name__)


def currently_jitting():
return isinstance(jnp.array(1) + 1, jax.core.Tracer)


class _BasicPoisson:
def __init__(self, rate):
self.rate = rate
Expand Down Expand Up @@ -184,6 +189,9 @@ def conditional(self, predicate, true_callable, false_callable):
return true_callable() if predicate else false_callable()

def tolist(self, tensor_in):
if currently_jitting():
# .aval is the abstract value and has a little nicer representation
return tensor_in.aval
try:
return jnp.asarray(tensor_in).tolist()
except (TypeError, ValueError):
Expand Down
Loading