Skip to main content

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.

Project description

https://badge.fury.io/py/eagerpy.svg https://codecov.io/gh/jonasrauber/eagerpy/branch/master/graph/badge.svg https://img.shields.io/badge/code%20style-black-000000.svg

EagerPy: PyTorch, TensorFlow, JAX and NumPy — all of them natively using the same code

EagerPy is a Python framework that let’s you write code that automatically works natively with PyTorch, TensorFlow, JAX, and NumPy. EagerPy is also great when you work with just one framework but prefer a clean and consistent API that is fully chainable, provides extensive type annotions and let’s you write beautiful code.

🔥 Design goals

  • Native Performance: EagerPy operations get directly translated into the corresponding native operations.

  • Fully Chainable: All functionality is available as methods on the tensor objects and as EagerPy functions.

  • Type Checking: Catch bugs before running your code thanks to EagerPy’s extensive type annotations.

📖 Documentation

Learn more about in the documentation.

🚀 Quickstart

pip install eagerpy

🎉 Example

import torch
x = torch.tensor([1., 2., 3., 4., 5., 6.])

import tensorflow as tf
x = tf.constant([1., 2., 3., 4., 5., 6.])

import jax.numpy as np
x = np.array([1., 2., 3., 4., 5., 6.])

import numpy as np
x = np.array([1., 2., 3., 4., 5., 6.])

# No matter which framwork you use, you can use the same code
import eagerpy as ep

# Just wrap a native tensor using EagerPy
x = ep.astensor(x)

# All of EagerPy's functionality is available as methods
x = x.reshape((2, 3))
x.flatten(start=1).square().sum(axis=-1).sqrt()
# or just: x.flatten(1).norms.l2()

# and as functions (yes, we gradients are also supported!)
loss, grad = ep.value_and_grad(loss_fn, x)
ep.clip(x + eps * grad, 0, 1)

# You can even write functions that work transparently with
# Pytorch tensors, TensorFlow tensors, JAX arrays, NumPy arrays

def my_universal_function(a, b, c):
    # Convert all inputs to EagerPy tensors
    a, b, c = ep.astensors(a, b, c)

    # performs some computations
    result = (a + b * c).square()

    # and return a native tensor
    return result.raw

🗺 Use cases

Foolbox Native, the latest version of Foolbox, a popular adversarial attacks library, has been rewritten from scratch using EagerPy instead of NumPy to achieve native performance on models developed in PyTorch, TensorFlow and JAX, all with one code base.

🐍 Compatibility

We currently test with the following versions:

  • PyTorch 1.4.0

  • TensorFlow 2.1.0

  • JAX 0.1.57

  • NumPy 1.18.1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eagerpy-0.25.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

eagerpy-0.25.1-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file eagerpy-0.25.1.tar.gz.

File metadata

  • Download URL: eagerpy-0.25.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.10

File hashes

Hashes for eagerpy-0.25.1.tar.gz
Algorithm Hash digest
SHA256 010bae30a8887e187dbad7c70c9fa11e78715a1d348bc03480a60aad56f9708b
MD5 df7757e782585401d158339537c837ec
BLAKE2b-256 a2c7000d62a95ddbf52dd655810ce8c8a91c1b15af8d88512a7ef1adcd4d0b52

See more details on using hashes here.

File details

Details for the file eagerpy-0.25.1-py3-none-any.whl.

File metadata

  • Download URL: eagerpy-0.25.1-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.10

File hashes

Hashes for eagerpy-0.25.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96a520512a30c956b42d048d81b5f3868f187d1157039f4354e8e914e56ef229
MD5 b1836c855306c2ac7567418194647d9e
BLAKE2b-256 93453e1bf1ed522089e8ca7ad2d9b9f87302661ea2c643c4a4145500ea6b83f1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page