- Notifications
You must be signed in to change notification settings - Fork5.6k
Convert Machine Learning Code Between Frameworks
License
ivy-llc/ivy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Ivy enables you to convert ML models, tools and libraries between frameworks usingivy.transpile
The easiest way to install Ivy is usingpip:
pip install ivy
From Source
You can also install Ivy from source if you want to take advantage ofthe latest changes:
git clone https://github.com/ivy-llc/ivy.gitcd ivypip install --user -e.
These are the frameworks thativy.transpile
currently supports conversions from and to.
Framework | Source | Target |
---|---|---|
PyTorch | ✅ | 🚧 |
TensorFlow | 🚧 | ✅ |
JAX | 🚧 | ✅ |
NumPy | 🚧 | ✅ |
Here's some examples, to help you get started using Ivy! Theexamples page also features a wide range ofdemos and tutorials showcasing some more use cases for Ivy.
Transpiling any code from one framework to another
importivyimporttorchimporttensorflowastfdeftorch_fn(x):a=torch.mul(x,x)b=torch.mean(x)returnx*a+btf_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
importivyimporttorchdeftorch_fn(x):a=torch.mul(x,x)b=torch.mean(x)returnx*a+btorch_x=torch.tensor([1.,2.,3.])graph=ivy.trace_graph(jax_fn,to="torch",args=(torch_x,))ret=graph(torch_x)
How does ivy work?
Ivy's transpiler allows you to use code from any other framework in your own code.Feel free to head over to the docs for the full APIreference, 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 documentationivy.transpile()# Traces an efficient fully-functional graph from a function, removing all wrapping and redundant code. See usage in the documentationivy.trace_graph()
importivyimporttorchimporttensorflowastfdeftorch_fn(x):x=torch.abs(x)returntorch.sum(x)x1=torch.tensor([1.,2.])x1=tf.convert_to_tensor([1.,2.])# Transpilation happens eagerlytf_fn=ivy.transpile(test_fn,source="torch",target="tensorflow")# tf_fn is now tensorflow code and runs efficientlyret=tf_fn(x1)
importivyimportkorniaimporttensorflowastfx2=tf.random.normal((5,3,4,4))# Module is provided -> transpilation happens lazilytf_kornia=ivy.transpile(kornia,source="torch",target="tensorflow")# The transpilation is initialized here, and this function is converted to tensorflowret=tf_kornia.color.rgb_to_grayscale(x2)# Transpilation has already occurred, the tensorflow function runs efficientlyret=tf_kornia.color.rgb_to_grayscale(x2)
We believe that everyone can contribute and make a difference. Whetherit's writing code, fixing bugs, or simply sharing feedback,your contributions are definitely welcome and appreciated"
Check out all of ourOpen Tasks,and find out more info in ourContributing Guidein the docs.
@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}}
About
Convert Machine Learning Code Between Frameworks
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.