You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible to integrate jax into pytorch ? #17569
Is it possible to incorporate jax into implementation of Pytorch? It looks so promising to speed up machine learning.
I would like to know if there is any plan about jax. Thanks.
JAX provides a JIT (just-in-time) compiler which takes a standard Python/numpy function and compiles it to via XLA
run efficiently on an accelerator (GPU/TPU)
avoids the overhead of the Python interpreter, whether you are on CPU/GPU/TPU.
1.2. JAX can parallelly process a minibatch
JAX provides jax.vmap, which is a transformation which automatically “vectorizes” a function. What this means is that it allows you to compute the output of a function in parallel over some axis of the input.
2. Examples
Haven't found a concrete example yet. But according to this tweet, he said "he is getting something like a 100x boost compared to autograd".
And founder of Keras is thinking of implementing Keras API on it. (tweet)
3. What I would like to see/know
Maybe Pytorch can collaborate with JAX team?
Is there any plan about JAX? / Will there any plan about JAX?
Enter Jax. Jax is built by the same people who built the original Autograd, and features both forward- and reverse-mode auto-differentiation. This allows computation of higher order derivatives orders of magnitude faster than what PyTorch/TensorFlow can offer.
Jax offers more than just higher order derivatives, however. The Jax developers view Jax as a framework for composing arbitrary functional transformations, including vmap (for automatic batching) or pmap (for automatic parallelization).
The original autograd had its devoted followers (11 papers at ICML used it despite having no GPU support), and it’s likely that Jax will soon pick up a similar devoted community, using it for all sorts of n-th order derivatives.
Just as a side note - for research, it might be the case that there are JAX implementations and Pytorch implementations that should be integrated.
For example, if you use a pre-trained JAX model for encoder A and Pytorch implementation for some arbitrary encoder B, while network C (written in JAX or Pytorch) gets the output of encoders A and B.
Sure, it's not a problem to implement if the encoders are fixed, however - once you try to train the whole "structure"/large network jointly, it's a little more challenging. I don't know much about the internals of JAX, but is it somehow possible to just pass the gradients and use the hyperparameters to jointly train the JAX network along with Pytorch?
I know it's an edge case and probably not too relevant for production code, but if it's possible an easy integration could be a decisive feature when one chooses a framework.
Reacted by Elizaveta Semenova, Muhammad Maaz, Martin Kocour, Sayna Ebrahimi and George Pearse
Activity
zou3519 commentedon Feb 28, 2019
What are some examples of things that jax enables you to do that you cannot easily do today with PyTorch?
richarddwang commentedon Mar 1, 2019
Sorry I don't know much about Pytorch implementation, but I think JAX has some good features.
1. What JAX can do
(excerpts from You don't know JAX by Colin Raffel )
1.1. jax.jit can dramatically speed-up your code
JAX provides a JIT (just-in-time) compiler which takes a standard Python/numpy function and compiles it to via XLA
1.2. JAX can parallelly process a minibatch
JAX provides jax.vmap, which is a transformation which automatically “vectorizes” a function. What this means is that it allows you to compute the output of a function in parallel over some axis of the input.
2. Examples
Haven't found a concrete example yet. But according to this tweet, he said "he is getting something like a 100x boost compared to autograd".
And founder of Keras is thinking of implementing Keras API on it. (tweet)
3. What I would like to see/know
soumith commentedon Mar 28, 2019
1.1, we already have with torch.jit
1.2 seems interesting
2. probably not relevant
1.2 is tracked in #1642
Overall, there isn't really the concept of "jax in pytorch" or "pytorch in jax" in the same sense that they're both frontends
KiaraGrouwstra commentedon Nov 24, 2019
some additional description on JAX: https://thegradient.pub/state-of-ml-frameworks-2019-pytorch-dominates-research-tensorflow-dominates-industry/
maayanorner commentedon Sep 3, 2022
Just as a side note - for research, it might be the case that there are JAX implementations and Pytorch implementations that should be integrated.
For example, if you use a pre-trained JAX model for encoder A and Pytorch implementation for some arbitrary encoder B, while network C (written in JAX or Pytorch) gets the output of encoders A and B.
Sure, it's not a problem to implement if the encoders are fixed, however - once you try to train the whole "structure"/large network jointly, it's a little more challenging. I don't know much about the internals of JAX, but is it somehow possible to just pass the gradients and use the hyperparameters to jointly train the JAX network along with Pytorch?
I know it's an edge case and probably not too relevant for production code, but if it's possible an easy integration could be a decisive feature when one chooses a framework.
brando90 commentedon Oct 30, 2022
I'd like to at least see how to load jax models/weights to pytorch and visa versa. Ping me for a ref :)