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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file eagerpy-0.26.0.tar.gz
.
File metadata
- Download URL: eagerpy-0.26.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5d76e42d2166c130cd10bf6684f972336c80e6c8f992767014fd9c98236d33 |
|
MD5 | ae61e57e3fd9cc694f4bf7886bd2ba33 |
|
BLAKE2b-256 | c2b3c51e052ae4c88130af07c97a53a1873e63a14a512b50991adde3a85d5c45 |
File details
Details for the file eagerpy-0.26.0-py3-none-any.whl
.
File metadata
- Download URL: eagerpy-0.26.0-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.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d150f75789ae85679de43f4b3bd9915a9d14626577af01bf9eae3ebce0e15b1 |
|
MD5 | 09e981c06052b1b00ae86c1e7273da93 |
|
BLAKE2b-256 | e7688ba19dce9d88091dbf4a2bad28cf2412c3a88835ca5e15ac114afe02aadc |