<a href="https://ivy.dev/">
<img class="dark-light" width="50%" src="https://raw.githubusercontent.com/ivy-llc/assets/refs/heads/main/assets/logos/ivy-long.svg"/>
</a>
|
|
|
|
|
|
<a href="https://github.com/ivy-llc/ivy/issues">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/github/issues/ivy-llc/ivy">
</a>
<a href="https://github.com/ivy-llc/ivy/network/members">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/github/forks/ivy-llc/ivy">
</a>
<a href="https://github.com/ivy-llc/ivy/stargazers">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/github/stars/ivy-llc/ivy">
</a>
<a href="https://github.com/ivy-llc/ivy/pulls">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg">
</a>
<a href="https://pypi.org/project/ivy">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://badge.fury.io/py/ivy.svg">
</a>
<a href="https://github.com/ivy-llc/ivy/actions?query=workflow%3Adocs">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://github.com/ivy-llc/ivy/actions/workflows/docs.yml/badge.svg">
</a>
<a href="https://discord.gg/uYRmyPxMQq">
<img class="dark-light" style="padding-right: 4px; padding-bottom: 4px;" src="https://img.shields.io/discord/1220325004013604945?color=blue&label=%20&logo=discord&logoColor=white">
</a>
Ivy enables you to:
ivy.transpileCreate optimized graph-based models and functions in any native framework (PyTorch, TensorFlow, etc..) with ivy.trace_graph
The easiest way to set up Ivy is to install it using pip:
pip install ivy
From Source
You can also install Ivy from source if you want to take advantage of the latest changes, but we can\'t ensure everything will work as expected 😅
git clone https://github.com/ivy-llc/ivy.git
cd ivy
pip install --user -e .
If you want to set up testing and various frameworks it\'s probably best to check out the Setting Up page, where OS-specific and IDE-specific instructions are available!
These are the frameworks that ivy.transpile currently supports conversions from and to.
We're working hard on adding support for more frameworks, let us know on Discord if there are source/target frameworks that would be useful for you!
| Framework | Source | Target |
|---|---|---|
| PyTorch | ✅ | 🚧 |
| TensorFlow | 🚧 | ✅ |
| JAX | 🚧 | ✅ |
| NumPy | 🚧 | ✅ |
Ivy's transpiler allows you convert code between different ML frameworks. Have a look at our Quickstart notebook to get a brief idea of the features!
Beyond that, based on the frameworks you want to convert code between, there are a few more examples further down this page 👇 which contain a number of models and libraries transpiled between PyTorch, JAX, TensorFlow and NumPy.
Here's some examples, to help you get started using Ivy! The examples page also features a wide range of demos and tutorials showcasing some more use cases for Ivy.
Transpiling any code from one framework to another
``` python import ivy import torch import tensorflow as tf
def torch_fn(x): a = torch.mul(x, x) b = torch.mean(x) return x * a + b
tf_fn = ivy.transpile(torch_fn, source="torch", target="tensorflow")
tf_x = tf.convert_to_tensor([1., 2., 3.]) ret = tf_fn(tf_x) ```
Tracing a computational graph of any code
``` python import ivy import torch
def torch_fn(x): a = torch.mul(x, x) b = torch.mean(x) return x * a + b
torch_x = torch.tensor([1., 2., 3.]) graph = ivy.trace_graph(jax_fn, to="torch", args=(torch_x,)) ret = graph(torch_x) ```
<!--
I'm using PyTorch 
You can use Ivy to get PyTorch code from: Any modelFrom TensorFlowAny libraryFrom JAXimport ivy import torch import tensorflow as tf # Get a pretrained keras model eff_encoder = tf.keras.applications.efficientnet_v2.EfficientNetV2B0( include_top=False, weights="imagenet", input_shape=(224, 224, 3) ) # Transpile it into a torch.nn.Module with the corresponding parameters noise = tf.random.normal(shape=(1, 224, 224, 3)) torch_eff_encoder = ivy.transpile(eff_encoder, source="tensorflow", to="torch", args=(noise,)) # Build a classifier using the transpiled encoder class Classifier(torch.nn.Module): def __init__(self, num_classes=20): super().__init__() self.encoder = torch_eff_encoder self.fc = torch.nn.Linear(1280, num_classes) def forward(self, x): x = self.encoder(x) return self.fc(x) # Initialize a trainable, customizable, torch.nn.Module classifier = Classifier() ret = classifier(torch.rand((1, 244, 244, 3)))import ivy import jax import torch # Get a pretrained haiku model # https://github.com/unifyai/demos/blob/15c235f/scripts/deepmind_perceiver_io.py from deepmind_perceiver_io import key, perceiver_backbone # Transpile it into a torch.nn.Module with the corresponding parameters dummy_input = jax.random.uniform(key, shape=(1, 3, 224, 224)) params = perceiver_backbone.init(rng=key, images=dummy_input) ivy.set_backend("jax") backbone = ivy.transpile( perceiver_backbone, source="jax", to="torch", params_v=params, kwargs={"images": dummy_input} ) # Build a classifier using the transpiled backbone class PerceiverIOClassifier(torch.nn.Module): def __init__(self, num_classes=20): super().__init__() self.backbone = backbone self.max_pool = torch.nn.MaxPool2d((512, 1)) self.flatten = torch.nn.Flatten() self.fc = torch.nn.Linear(1024, num_classes) def forward(self, x): x = self.backbone(images=x) x = self.flatten(self.max_pool(x)) return self.fc(x) # Initialize a trainable, customizable, torch.nn.Module classifier = PerceiverIOClassifier() ret = classifier(torch.rand((1, 3, 224, 224)))From TensorflowAny functionFrom JAXimport ivy import torch import os os.environ["SM_FRAMEWORK"] = "tf.keras" import segmentation_models as sm # transpile sm from tensorflow to torch torch_sm = ivy.transpile(sm, source="tensorflow", to="torch") # get some image-like arrays output = torch.rand((1, 3, 512, 512)) target = torch.rand((1, 3, 512, 512)) # and use the transpiled version of any function from the library! out = torch_sm.metrics.iou_score(output, target)From NumPyimport ivy import rax import torch # transpile rax from jax to torch torch_rax = ivy.transpile(rax, source="jax", to="torch") # get some arrays scores = torch.tensor([2.2, 1.3, 5.4]) labels = torch.tensor([1.0, 0.0, 0.0]) # and use the transpiled version of any function from the library! out = torch_rax.poly1_softmax_loss(scores, labels)import ivy import torch import madmom # transpile madmon from numpy to torch torch_madmom = ivy.transpile(madmom, source="numpy", to="torch") # get some arrays freqs = torch.arange(20) * 10 # and use the transpiled version of any function from the library! out = torch_madmom.audio.filters.hz2midi(freqs)From TensorflowFrom JAXimport ivy import tensorflow as tf import torch def loss(predictions, targets): return tf.sqrt(tf.reduce_mean(tf.square(predictions - targets))) # transpile any function from tf to torch torch_loss = ivy.transpile(loss, source="tensorflow", to="torch") # get some arrays p = torch.tensor([3.0, 2.0, 1.0]) t = torch.tensor([0.0, 0.0, 0.0]) # and use the transpiled version! out = torch_loss(p, t)From NumPy ``` python import ivy import numpy as np import torch def loss(predictions, targets): return np.sqimport ivy import jax.numpy as jnp import torch def loss(predictions, targets): return jnp.sqrt(jnp.mean((predictions - targets) ** 2)) # transpile any function from jax to torch torch_loss = ivy.transpile(loss, source="jax", to="torch") # get some arrays p = torch.tensor([3.0, 2.0, 1.0]) t = torch.tensor([0.0, 0.0, 0.0]) # and use the transpiled version! out = torch_loss(p, t)