gitmyhub

ivy

Python ★ 14k updated 25d ago

Convert Machine Learning Code Between Frameworks

Ivy converts machine learning code between PyTorch, TensorFlow, JAX, and NumPy so you can run models in a different framework without rewriting them by hand.

PythonPyTorchTensorFlowJAXNumPysetup: easycomplexity 3/5

Ivy is a Python tool for converting machine learning code from one framework to another. In machine learning, a framework is a software toolkit that people use to build and run models. PyTorch, TensorFlow, JAX, and NumPy are four popular ones, and code written for one of them does not normally run on the others. Ivy aims to bridge that gap.

The central feature is a function called ivy.transpile. You give it code written for a source framework and tell it which target framework you want, and it produces equivalent code for that target. The README shows a small example: a function written with PyTorch is passed to ivy.transpile with source set to torch and target set to tensorflow, and the result is a TensorFlow version of the same function that you can then run on TensorFlow data. The README notes that PyTorch is currently supported as a source, while TensorFlow, JAX, and NumPy are supported as targets.

There is a second function, ivy.trace_graph, which records the underlying steps a piece of code performs and builds a streamlined version with the extra wrapping removed. According to the docs, transpile can work in two ways: it converts a single function or class right away, and for a whole library it converts pieces only when they are actually used.

Installing Ivy is done with a normal pip install ivy command, or from source by cloning the repository. The README also includes examples, a pointer to fuller documentation and demos, a contributing guide for people who want to help, and a citation for the academic paper behind the project.

The practical point of Ivy is portability: if you have model code tied to one framework and need it in another, this tool tries to do that translation for you instead of rewriting everything by hand.

Where it fits