Convert Machine Learning Code Between Frameworks
Project description
Website |
Docs |
Demos |
Design |
FAQ |
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
Docker Image
You can pull the Docker image for Ivy from:
docker pull ivyllc/ivy:latest
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
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
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)
How ivy works?
Let's take a look at how Ivy works as a transpiler in more detail to get an idea of why and where to use it.
When is Ivy's transpiler useful?
If you want to use building blocks published in other frameworks (neural networks, layers, array computing libraries, training pipelines...), you want to integrate code developed in various frameworks, or maybe straight up migrate code from one framework to another or even between versions of the same framework, the transpiler is definitely the tool for the job! You can use the converted code just as if it was code originally developed in that framework, applying framework-specific optimizations or tools, instantly exposing your project to all of the unique perks of a different framework.
Ivy's transpiler allows you to use code from any other framework (or
from any other version of the same framework!) in your own code, by just
adding one line of code.
This way, Ivy makes all ML-related projects available for you, independently of the framework you want to use to research, develop, or deploy systems. Feel free to head over to the docs for the full API reference, but the functions you'd most likely want to use are:
# Converts framework-specific code to a target framework of choice. See usage in the documentation
ivy.transpile()
# Traces an efficient fully-functional graph from a function, removing all wrapping and redundant code. See usage in the documentation
ivy.trace_graph()
ivy.transpile
will eagerly transpile if a class or function is provided
import ivy
import torch
import tensorflow as tf
def torch_fn(x):
x = torch.abs(x)
return torch.sum(x)
x1 = torch.tensor([1., 2.])
x1 = tf.convert_to_tensor([1., 2.])
# Transpilation happens eagerly
tf_fn = ivy.transpile(test_fn, source="torch", target="tensorflow")
# tf_fn is now tensorflow code and runs efficiently
ret = tf_fn(x1)
ivy.transpile
will lazily transpile if a module (library) is provided
import kornia
x2 = torch.rand(5, 3, 4, 4)
# Module is provided -> transpilation happens lazily
tf_kornia = ivy.transpile(kornia, source="torch", target="tensorflow")
# The transpilation is initialized here, and this function is converted to tensorflwo
ret = tf_kornia.color.rgb_to_grayscale(x2)
# Transpilation has already occurred, the tensorflow function runs efficiently
ret = tf_kornia.color.rgb_to_grayscale(x2)
ivy.trace_graph
can be used eagerly or lazily
If you pass the necessary arguments for function tracing, the graph tracing step will happen instantly (eagerly). Otherwise, the graph tracing will happen only when the returned function is first invoked.
import ivy
import jax
ivy.set_backend("jax")
# Simple JAX function to transpile
def test_fn(x):
return jax.numpy.sum(x)
x1 = ivy.array([1., 2.])
# Arguments are available -> tracing happens eagerly
eager_graph = ivy.trace_graph(test_fn, to="jax", args=(x1,))
# eager_graph now runs efficiently
ret = eager_graph(x1)
# Arguments are not available -> tracing happens lazily
lazy_graph = ivy.trace_graph(test_fn, to="jax")
# The traced graph is initialized, tracing will happen here
ret = lazy_graph(x1)
# Tracing has already happend, traced graph runs efficiently
ret = lazy_graph(x1)
If you want to learn more, you can find more information in the Ivy as a transpiler section of the docs!
Documentation
You can find Ivy's documentation on the Docs page, which includes:
- Motivation: This contextualizes the problem Ivy is trying to solve by going over
- The current ML Explosion.
- Explaining why it is important to solve this problem.
- Related Work: Which paints a picture of the role Ivy plays in the ML stack, comparing it to other existing solutions in terms of functionalities and abstraction level.
- Design: A user-focused guide about the design decision behind the architecture and the main building blocks of Ivy.
- Deep Dive: Which delves deeper into the implementation details of Ivy and is oriented towards potential contributors to the code base.
Contributing
We believe that everyone can contribute and make a difference. Whether it's writing code, fixing bugs, or simply sharing feedback, your contributions are definitely welcome and appreciated 🙌
Check out all of our Open Tasks, and find out more info in our Contributing guide in the docs! Or to immediately dive into a useful task, look for any failing tests on our Test Dashboard!
Community
Join our growing community on a mission to make conversions between frameworks simple and accessible to all! Whether you are a seasoned developer or just starting out, you'll find a place here! Join the Ivy community on our Discord 👾 server, which is the perfect place to ask questions, share ideas, and get help from both fellow developers and the Ivy Team directly.
See you there!
Citation
If you use Ivy for your work, please don't forget to give proper credit by including the accompanying paper 📄 in your references. It's a small way to show appreciation and help to continue to support this and other open source projects 🙌
@article{lenton2021ivy,
title={Ivy: Templated deep learning for inter-framework portability},
author={Lenton, Daniel and Pardo, Fabio and Falck, Fabian and James, Stephen and Clark, Ronald},
journal={arXiv preprint arXiv:2102.02886},
year={2021}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file ivy-1.0.0.1.tar.gz
.
File metadata
- Download URL: ivy-1.0.0.1.tar.gz
- Upload date:
- Size: 22.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 052908b8ce815763477e8b4cd9400aa0248dc8f74ea896cf79775a61cc00a5ac |
|
MD5 | 0b691df9c289ed1de1d572186d9ae052 |
|
BLAKE2b-256 | 8175d75de3ca1054e6d8baad4e966ba9fd64351d841e06af632277cb21786b97 |
File details
Details for the file ivy-1.0.0.1-cp313-cp313-win_amd64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 17.9 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb4a50968032513dbb51889483369d6da2b8a6935695c32e5f42e723ed06355b |
|
MD5 | 091eeb5a338d7a04cd8dcc1fa6c2d53d |
|
BLAKE2b-256 | 9b41ac50107a61cd0707f278d4302d5d08c6dfa379c2f1d06a8d0f68b9f52d11 |
File details
Details for the file ivy-1.0.0.1-cp313-cp313-manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp313-cp313-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 18.0 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69291dabbf5008882a696be890f07eaaacb1a54552e83e632af2062f25adc6d9 |
|
MD5 | c211385a6db10d0dd04610e8dcbff9b9 |
|
BLAKE2b-256 | 65669fa3123edf0c839e4b0b0139dfc614e799ed5e0314303d3d23709c3b59d9 |
File details
Details for the file ivy-1.0.0.1-cp313-cp313-macosx_12_0_arm64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp313-cp313-macosx_12_0_arm64.whl
- Upload date:
- Size: 23.0 MB
- Tags: CPython 3.13, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0067437e7f24e6491c016cc27e050e8cd8471412b1222efd5c8e56b81414b61 |
|
MD5 | b3e3860c879eb046cc0aaedfa0b9ef45 |
|
BLAKE2b-256 | 36c1c606a99bae702b50c148a922e2eaa4f2f377f1b762463c9246a76cdfe5b2 |
File details
Details for the file ivy-1.0.0.1-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 18.1 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 686cb2e8d4220efc0c9e73531d63d0121d9b0a55115723e702bbc7e1aee3c37b |
|
MD5 | d8debcff45d8901e9a6a120f6ff96b57 |
|
BLAKE2b-256 | b2d7376f93b17d9912b6564f42ec35d1241bcae921cb351205cd6cc3e9d1230d |
File details
Details for the file ivy-1.0.0.1-cp312-cp312-manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp312-cp312-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 18.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6b3d6a09d4d543f1912e38222dd7e025cc2361d8a8b8065671125874ce8d7b7 |
|
MD5 | 14b65420e00fa5eb98a7df55470445c1 |
|
BLAKE2b-256 | d7c66bddb03719d9d18657c60e71ebaa04ec57ebe68ab90e3b3c32c2bc3ce6ac |
File details
Details for the file ivy-1.0.0.1-cp312-cp312-macosx_12_0_arm64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp312-cp312-macosx_12_0_arm64.whl
- Upload date:
- Size: 23.5 MB
- Tags: CPython 3.12, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d48c15e1c326cd3485aae8ce9974b31d00d2db7bf9f9cfa0c28a633324ce7ab |
|
MD5 | 0ebf78a292ee20479902640fab226817 |
|
BLAKE2b-256 | 4946ce4405537b4f6c1dfb3a27f7e11c845bd28926f456718379bcadcdd93e31 |
File details
Details for the file ivy-1.0.0.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 17.2 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ac4f872c76ee8f89a52bb80f7251a62eccf9df10cd0cc0a2478050babf0eb1 |
|
MD5 | fec37f7e7bb006bd008a9d9ef95cafe4 |
|
BLAKE2b-256 | 5b50c186763ed73b66b96674c72175501685c33d044f7999d60adb678cbf0098 |
File details
Details for the file ivy-1.0.0.1-cp311-cp311-manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp311-cp311-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 17.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8567c8b7c917394368fcd7eadc4bdd8dd722a3691de95c91633db07a49b0844f |
|
MD5 | c500ad88e21887510f265a89731dbb0e |
|
BLAKE2b-256 | d2a327cd3da046ac9e18ce3444ae9f43ffab7184e8ea8a9095dc747bcd93a382 |
File details
Details for the file ivy-1.0.0.1-cp311-cp311-macosx_12_0_arm64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp311-cp311-macosx_12_0_arm64.whl
- Upload date:
- Size: 23.8 MB
- Tags: CPython 3.11, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22fa4b05aa26923a7febf813b8e9de499476f46704538f348f6a23d723abcb34 |
|
MD5 | 7a0854900479315253b18c8e5cd971d4 |
|
BLAKE2b-256 | ce4376034e974b42f370b04ef503ff540aaafacd377bb1042b7ffadbed080190 |
File details
Details for the file ivy-1.0.0.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 17.2 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35d82bbd80456fbc853499a34f8d7bbe720cb2747e7018dc71606a113ac9cb49 |
|
MD5 | d09d8db982d70aad9314102b2330c7d3 |
|
BLAKE2b-256 | db30aa14a530a54fcdf1813ba03866fa7d7eee2bf911f45bb58542c5a5a6faad |
File details
Details for the file ivy-1.0.0.1-cp310-cp310-manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp310-cp310-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 18.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45811a118f3895ddaa90eb7d633d731332d5b542edbc4702b55e615732d51b6a |
|
MD5 | 0e7c2e053c83c09524fae545d8674d81 |
|
BLAKE2b-256 | 537deb2c69cc1278b2a09edbec29f2a2630497621d6b3788feff38a2a0edc381 |
File details
Details for the file ivy-1.0.0.1-cp310-cp310-macosx_12_0_arm64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp310-cp310-macosx_12_0_arm64.whl
- Upload date:
- Size: 23.8 MB
- Tags: CPython 3.10, macOS 12.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a572a2591ecfe600e51fc138eaddc52b1dbf43af2a936b326f2ab9ceaab00f0b |
|
MD5 | 6dbee6ad989241231421c9592f5318ff |
|
BLAKE2b-256 | 4c363ec209cdd0e30ec854e43b3fccbb3ca8da3562487f161e3d10b3fb1b1836 |
File details
Details for the file ivy-1.0.0.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 18.0 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b38f47c0fc818d4c125ca674245f8c6b87c429a4f8b72a10fec626b95230ae35 |
|
MD5 | 0b6db0136e50cbf077d48ca41da3369f |
|
BLAKE2b-256 | 6d6b7924db03eeec40abd7e40bd2d948ef80a51b7a8f51f3a53098eb5a2ce5e7 |
File details
Details for the file ivy-1.0.0.1-cp39-cp39-manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp39-cp39-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 18.2 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff1b8c1141916ae42094840cef5598104caadbf9bff02fbddf29360bc5b0d64e |
|
MD5 | a409b4ca71920d8898e0b4e1ce739d1c |
|
BLAKE2b-256 | 36eb8d5f14f18695cbf6b38215ab3c87d89fdf2781d36233a9763650c0e338be |
File details
Details for the file ivy-1.0.0.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 18.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f110e62158a0712b42eace9f435c0031589e81aef9f0c6860878dded92f42e0 |
|
MD5 | 9466d4378f34548a35dac23a491d4c22 |
|
BLAKE2b-256 | 984bd3e645ec88aacc70b601a3e3d61cec5f2b2830045eb486303418bd71de84 |
File details
Details for the file ivy-1.0.0.1-cp38-cp38-manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: ivy-1.0.0.1-cp38-cp38-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 9.9 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c76c4c6a6e370c858e278bdaf4cfc4171eebf2435ceb4f213c03cc2a17438c7b |
|
MD5 | 231e6bee2efef6f7e688c9b616ca52b1 |
|
BLAKE2b-256 | 3067d1ceff8435285ca0929ee90d29be9eb1f3f3fa6ba26938a05ef777bfc2d6 |