README 的框架支持表中只有 PyTorch 作为源框架已支持,TensorFlow、JAX、NumPy 作为源框架仍标注为 planned;转译目标框架需自行安装对应框架(如 tensorflow、jax);README 示例代码中 trace_graph 段落误用了未定义的 jax_fn,照抄会报错
把 PyTorch 等框架的模型和库代码转译成其他框架的 Python 工具
把 PyTorch、TensorFlow、JAX、NumPy 等框架的机器学习代码互相转换,省去为不同框架重写模型的麻烦。
核心能力
- 用 ivy.transpile 把源码框架的函数转成目标框架代码
- 传入类或函数时立即转译,传入模块时惰性转译
- 用 ivy.trace_graph 追踪出可复用的计算图
- 支持 PyTorch 转 TensorFlow、JAX、NumPy 等目标
- 可直接转译 kornia 这类第三方库模块
容易踩的坑
- 1.0.0.5Ivy v1.0.0.5最新正式版2025-06-16 · 2025-06-16 00:11 UTC
What's Changed
- fix: remove old hf tests from the ci by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28861
- fix: docker image build by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28862
- refactor: clean up redundant parts of the codebase by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28863
- refactor: extract globals into ivy.transpiler by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28865
- refactor: remove redundant classes and imports from import_utils by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28867
- refactor: isolate source_utils from the main translator by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28868
- refactor: remove ast_utils module interdependencies and create new ivy.transpiler.ast module by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28869
- refactor: extract BaseObjectLike and similar into a separate 'core' module by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28870
- refactor: remove ivy cython wrappers logic by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28871
- refactor: remove redundant references to binaries by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28872
- refactor: remove git tools that are no longer needed by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28873
- fix: run transpiler tests in ci without docker by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28875
- refactor: remove redundant workflows by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28876
- refactor: remove ivy.engines by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28874
- refactor: remove need for docker by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28877
- fix: docstring tests by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28879
- refactor: remove some optional deps that are no longer needed by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28878
Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.4...1.0.0.5
- 1.0.0.4Ivy v1.0.0.42025-02-21 · 2025-02-21 00:06 UTC
查看更新说明
What's Changed
- Update README.md by @xandie985 in https://github.com/ivy-llc/ivy/pull/28857
- define type_params on gast.ClassDef instantiation to support compatibility with python>=3.12 by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28858
New Contributors
- @xandie985 made their first contribution in https://github.com/ivy-llc/ivy/pull/28857
Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.3...1.0.0.4
- 1.0.0.3Ivy v1.0.0.32025-01-22 · 2025-01-22 20:14 UTC
查看更新说明
What's Changed
- fix: python wheel build by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28856
Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.2...1.0.0.3
- 1.0.0.2Ivy v1.0.0.22025-01-21 · 2025-01-21 16:32 UTC
查看更新说明
Release which fully open-sources Ivy's transpiler and graph tracer!
What's Changed
- open source ivy's transpiler by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28849
- fix: unify the torch.Tensor.cuda frontends by @Sam-Armstrong in https://github.com/ivy-llc/ivy/pull/28827
Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.1...1.0.0.2
- 1.0.0.1Ivy v1.0.0.12024-11-03 · 2024-11-03 19:38 UTC
查看更新说明
What's Changed
- Removed dependencies on astunparse and termcolor
- Added networkx dependency
- fixing circular reference bug in
Array.sizeby @YushaArif99 in https://github.com/ivy-llc/ivy/pull/28840 - fixing
ivy.inputs_to_native_arrayswhenarray_mode=Falseby @YushaArif99 in https://github.com/ivy-llc/ivy/pull/28841
Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.0...1.0.0.1
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Convert Machine Learning Code Between Frameworks
ivy enables you to convert ML models, tools and libraries between frameworks using ivy.transpile
Installation
The easiest way to install ivy is using pip:
pip install ivy
You can also install ivy from source if you want to take advantage of the latest changes:
git clone https://github.com/ivy-llc/ivy.git
cd ivy
pip install --user -e .
Supported Frameworks
These are the frameworks that ivy.transpile currently supports conversions from and to.
| Framework | Source | Target |
|---|---|---|
| PyTorch | ✓ | planned |
| TensorFlow | planned | ✓ |
| JAX | planned | ✓ |
| NumPy | planned | ✓ |
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.
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)
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)
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 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 ivy
import kornia
import tensorflow as tf
x2 = tf.random.normal((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 tensorflow
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)
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.
Citation
@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}
}