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

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

Development

For development, it is recommended to do a an editable installation of Foolbox and Foolbox native using pip install -e . in the corresponding folders (after cloning the two repositories). Unfortunately, pip has a bug with editable installs and namespace packages like Foolbox Native. A simple workaround is to add a symlink to the foolbox/ext/native folder of Foolbox Native in the foolbox/ext/ folder of Foolbox itself.

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.12.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

eagerpy-0.12.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eagerpy-0.12.0.tar.gz
  • Upload date:
  • Size: 10.4 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.0 CPython/3.6.10

File hashes

Hashes for eagerpy-0.12.0.tar.gz
Algorithm Hash digest
SHA256 8bbdf229c9b1c24d131e84f63174c5581ebe5212613dcebd3f6d4c435365bf3c
MD5 445963437b4d29921d056479f4f9ef5c
BLAKE2b-256 e0892e310947cdea721c30342159a13c5fe63c71cd0dc2cff542c36b7c500b4a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eagerpy-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 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.0 CPython/3.6.10

File hashes

Hashes for eagerpy-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be90123a1e12e8a6dccea51391149f0bbd2369f53192670df1531c8fd04b2879
MD5 8f81e93d9bf42708f01267fcfc090f5c
BLAKE2b-256 b03e78d6aac4ed4a50f2ec77878042246f2151730f13faaef0e6b3640adf306a

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