ivy README

The project's README from github.com/unifyai/ivy. As one markdown file: README.md.

Ivy — convert machine learning code between frameworks


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
From Source

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 ✅ 🚧
TensorFlow 🚧 ✅
JAX 🚧 ✅
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 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 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}
}

ivy (unifyai/ivy)

Searching Database…

14.2K ·GitHub
archived
这是什么东西?Ivy 是一个开源的 Python 库,可以在不同机器学习框架之间转换代码——用 ivy.transpile 就能把机器学习模型、工具和库从一个框架迁移到另一个框架。
它是我在自己代码里调用的库,还是一个独立的转换工具?它是一个 Python 库:你在自己的代码里调用 ivy.transpile,就能使用用其他任何框架写的代码。对类或函数的转换是立即执行的,对整个模块或库则是延迟执行的。
它能在哪些机器学习框架之间转换代码?开箱即用的情况下,它可以把 PyTorch 代码转换成 TensorFlow、JAX 或 NumPy——README 的表格里标明 PyTorch 是唯一支持的源框架,TensorFlow、JAX 和 NumPy 是支持的目标框架。
它也能把代码转换成 PyTorch 吗?暂时不行:PyTorch 目前只支持作为源框架。目标框架是 TensorFlow、JAX 和 NumPy,PyTorch 作为目标框架还标记为开发中。
这个项目还在积极开发吗?不在了——GitHub 仓库已被归档,处于只读状态,不会再继续开发,不过已发布的包仍然可以安装和使用。
有没有示例和教程可以看看 Ivy 能做什么?有——示例页面上有丰富的演示和教程,展示了更多使用场景,文档里还有完整的 API 参考。
Ivy 有对应的学术论文吗?有——论文题为 'Ivy: Templated deep learning for inter-framework portability',作者是 Lenton、Pardo、Falck、James 和 Clark,2021 年作为 arXiv 预印本 2102.02886 发表。
Creator
unifyai
Size
159.3 MB
Stars
14.2K
Age
5y
Commits · 90 Days