Skip to content

Is it possible to integrate jax into pytorch ? #17569

Closed

Description

@richarddwang

What is jax (just in case for other reader)

jax is full numpy acceleration and autodiff with functional neural networks, and is essentially autograd 2.0. (from Italian Association for Machine Learning)

Feature Request

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.

Activity

  1. zou3519 commented on Feb 28, 2019

    @zou3519
    Contributor

    What are some examples of things that jax enables you to do that you cannot easily do today with PyTorch?

  2. added
    feature
    on Feb 28, 2019
  3. richarddwang commented on Mar 1, 2019

    @richarddwang
    Author

    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

    • 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?
  4. soumith commented on Mar 28, 2019

    @soumith
    Collaborator

    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

  5. KiaraGrouwstra commented on Nov 24, 2019

    @KiaraGrouwstra

    some additional description on JAX: https://thegradient.pub/state-of-ml-frameworks-2019-pytorch-dominates-research-tensorflow-dominates-industry/

    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.

  6. maayanorner commented on Sep 3, 2022

    @maayanorner

    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.

  7. brando90 commented on Oct 30, 2022

    @brando90

    I'd like to at least see how to load jax models/weights to pytorch and visa versa. Ping me for a ref :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretriage review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions