boost-histogram and traced computation (jax, TF and co) #563
Replies: 1 comment 2 replies
-
Hi @mayou36 I think this is interesting and sorry that I somehow missed to comment, I hope @henryiii can also comment.
I am not sure why this is a problem, the histogram itself should not change in whatever you do with TF and Jax. The histogram holds the data, while TF and JAX act on the model for the data. The data itself is static, you do not modify it in a fit. You only modify the predictions for the data as a function of the model parameters. So, in principle it should not be an issue at all that JAX or TF cannot interact directly with BH, it is sufficient if they can interface with the bin contents of BH, which can be converted to static numpy arrays and the bin edges, which can also be converted to static numpy arrays. That being said, could you post a link or paste some code here that shows what kind of changes you think are required to implemented your first proposal? |
Beta Was this translation helpful? Give feedback.
-
Hi all, having used BH for a while and liking it, it's simple, fast and intuitive, I started wondering about integrating it within other workflows using jax, TensorFlow etc (specifically for binned fits in zfit). The peculiarity of it is that any Python code not written in TF, Jax... will not be rerun after the first execution. Or wrap the actual function with something like
numpy_function
that explicitly allows Python execution in a jitted function.It seems somewhat similar to numba support #552 at first glance but may be different that jax should actually mimic the boost library histogram, as I am not quite sure whether, and how, that is actually possible to implement.
So the first question is maybe whether you have any thoughts on this? @HDembinski since you've also used jax, maybe you have an idea on good integration?
I see two (or three) possibilities:
_BaseHistogram
with a TF/numpy-like implementation. With this, (and 2-3 changes in Histogram), I was able to get the functionality up for some test cases. This way would stick close to BH and maybe add to BH but has the disadvantage that we may would need to add (some) changes (I think minimal though) within BH. I see very well that this is rather not what is wanted for BH as it is just the bindings for the boost library. This has the problem that maybe a few things are incompatible in the API, such as*args
, which are disliked by jax etc usually(- maybe we can use directly BH by wrapping all the functions with
numpy_function
(something that adds a dynamic node inside the jitted function), but it seems no quite golden to me)What are your general ideas on this?
Beta Was this translation helpful? Give feedback.
All reactions