MCPcopy Index your code
hub / github.com/unifyai/ivy

github.com/unifyai/ivy @1.0.0.5 sqlite

repository ↗ · DeepWiki ↗ · release 1.0.0.5 ↗
21,604 symbols 74,555 edges 1,476 files 3,195 documented · 15% 2 cross-repo links
README
<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>

Website Website Docs Docs Demos Demos Design Design FAQ FAQ
<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>

Convert Machine Learning Code Between Frameworks

Ivy enables you to:

  • Convert ML models, tools and libraries between frameworks while maintaining complete functionality using ivy.transpile
  • Create optimized graph-based models and functions in any native framework (PyTorch, TensorFlow, etc..) with ivy.trace_graph

Installing ivy

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!

Supported Frameworks

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 🚧

Getting started

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.

Using ivy

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 model
From TensorFlow
import 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)))
From JAX
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)))
Any library
From Tensorflow
import 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 JAX
import 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)
From NumPy
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)
Any function
From Tensorflow
import 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 JAX
import 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)
From NumPy ``` python import ivy import numpy as np import torch def loss(predictions, targets): return np.sq

Core symbols most depended-on inside this repo

len
called by 2278
ivy/tracer/tracked_var_replacements.py
array
called by 1851
ivy/functional/frontends/pandas/index.py
range
called by 972
ivy/functional/frontends/torch/creation_ops.py
astype
called by 772
ivy/functional/frontends/jax/array.py
to_numpy
called by 630
ivy_tests/test_ivy/test_frontends/config/base.py
where
called by 527
ivy/functional/frontends/torch/tensor.py
allclose
called by 508
ivy/functional/frontends/paddle/tensor/tensor.py
reshape
called by 464
ivy/functional/frontends/jax/array.py

Shape

Function 11,840
Method 5,578
Route 3,405
Class 781

Languages

Python100%

Modules by API surface

ivy_tests/test_ivy/test_frontends/test_torch/test_tensor.py734 symbols
ivy/functional/frontends/torch/tensor.py390 symbols
ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py333 symbols
ivy_tests/test_ivy/test_frontends/test_tensorflow/test_raw_ops.py270 symbols
ivy_tests/test_ivy/test_frontends/test_tensorflow/test_math.py201 symbols
ivy_tests/test_ivy/test_frontends/test_jax/test_numpy/test_mathematical_functions.py198 symbols
ivy_tests/test_ivy/test_frontends/test_torch/test_pointwise_ops.py189 symbols
ivy_tests/test_ivy/test_frontends/test_numpy/test_ndarray/test_ndarray.py185 symbols
ivy/functional/frontends/paddle/tensor/tensor.py178 symbols
ivy_tests/test_ivy/test_frontends/test_jax/test_lax/test_operators.py173 symbols
ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py168 symbols
ivy_tests/test_tracer/test_tracing/test_tracing.py162 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

cryptography40.0.0 · 1×

Datastores touched

(mongodb)Database · 1 repos

For agents

$ claude mcp add ivy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact