EagerPy is a thin wrapper around PyTorch, TensorFlow Eager, JAX and NumPy that unifies their interface and thus allows writing code that works natively across all of them.


Keywords
python, tensorflow, numpy, pytorch, jax, eager-execution, tensorflow2
License
MIT
Install
pip install eagerpy==0.30.0

Documentation

EagerPy

EagerPy is a thin wrapper around PyTorch, TensorFlow Eager, JAX and NumPy that unifies their interface and thus allows writing code that works natively across all of them.

Warning: this is work in progress; the tests should run through just fine, but lot's of features are still missing. Let me know if this project is useful to you and which features are needed.

EagerPy is now in active use to develop Foolbox Native.

Installation

pip install eagerpy

Example

import eagerpy as ep

import torch
x = torch.tensor([1., 2., 3.])
x = ep.PyTorchTensor(x)

import tensorflow as tf
x = tf.constant([1., 2., 3.])
x = ep.TensorFlowTensor(x)

import jax.numpy as np
x = np.array([1., 2., 3.])
x = ep.JAXTensor(x)

import numpy as np
x = np.array([1., 2., 3.])
x = ep.NumPyTensor(x)

# In all cases, the resulting EagerPy tensor provides the same
# interface. This makes it possible to write code that works natively
# independent of the underlying framework.

# EagerPy tensors provide a lot of functionality through methods, e.g.
x.sum()
x.sqrt()
x.clip(0, 1)

# but EagerPy also provides them as functions, e.g.
ep.sum(x)
ep.sqrt(x)
ep.clip(x, 0, 1)
ep.uniform(x, (3, 3), low=-1., high=1.)  # x is needed to infer the framework

Compatibility

We currently test with the following versions:

  • PyTorch 1.3.1
  • TensorFlow 2.0.0
  • JAX 0.1.57
  • NumPy 1.18.1