ivy

unifyai活跃维护

把 PyTorch、TensorFlow、JAX、NumPy 等框架的机器学习代码互相转换,省去为不同框架重写模型的麻烦。

Convert Machine Learning Code Between Frameworks

1.0.0.5发布于 2025-06-16 00:11 UTC14,167star5,434fork同步于 2026-11-10 17:27 UTC

怎么上手

由 README 提炼,执行前请确认
pip install ivy
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把 PyTorch 等框架的模型和库代码转译成其他框架的 Python 工具

把 PyTorch、TensorFlow、JAX、NumPy 等框架的机器学习代码互相转换,省去为不同框架重写模型的麻烦。

核心能力

  • 用 ivy.transpile 把源码框架的函数转成目标框架代码
  • 传入类或函数时立即转译,传入模块时惰性转译
  • 用 ivy.trace_graph 追踪出可复用的计算图
  • 支持 PyTorch 转 TensorFlow、JAX、NumPy 等目标
  • 可直接转译 kornia 这类第三方库模块

容易踩的坑

README 的框架支持表中只有 PyTorch 作为源框架已支持,TensorFlow、JAX、NumPy 作为源框架仍标注为 planned;转译目标框架需自行安装对应框架(如 tensorflow、jax);README 示例代码中 trace_graph 段落误用了未定义的 jax_fn,照抄会报错

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本1.0.0.5
  1. 1.0.0.5Ivy v1.0.0.5最新正式版2025-06-16 · 2025-06-16 00:11 UTC

    What's Changed

    Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.4...1.0.0.5

  2. 1.0.0.4Ivy v1.0.0.42025-02-21 · 2025-02-21 00:06 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.3...1.0.0.4

  3. 1.0.0.3Ivy v1.0.0.32025-01-22 · 2025-01-22 20:14 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.2...1.0.0.3

  4. 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

    Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.1...1.0.0.2

  5. 1.0.0.1Ivy v1.0.0.12024-11-03 · 2024-11-03 19:38 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/ivy-llc/ivy/compare/1.0.0.0...1.0.0.1

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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.

    FrameworkSourceTarget
    PyTorch✓planned
    TensorFlowplanned✓
    JAXplanned✓
    NumPyplanned✓

    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}
    }