| 1 |
--- |
| 2 |
home: true |
| 3 |
heroImage: /logo.png |
| 4 |
heroText: EagerPy |
| 5 |
tagline: Writing Code That Works Natively with PyTorch, TensorFlow, JAX, and NumPy |
| 6 |
actionText: Get Started → |
| 7 |
actionLink: /guide/ |
| 8 |
features: |
| 9 |
- title: Native Performance |
| 10 |
details: EagerPy operations get directly translated into the corresponding native operations. |
| 11 |
- title: Fully Chainable |
| 12 |
details: All functionality is available as methods on the tensor objects and as EagerPy functions. |
| 13 |
- title: Type Checking |
| 14 |
details: Catch bugs before running your code thanks to EagerPy's extensive type annotations. |
| 15 |
footer: Copyright © 2020 Jonas Rauber |
| 16 |
|
| 17 |
--- |
| 18 |
|
| 19 |
### What is EagerPy? |
| 20 |
|
| 21 |
**EagerPy** is a **Python framework** that lets you write code that automatically works natively with [**PyTorch**](https://pytorch.org), [**TensorFlow**](https://www.tensorflow.org), [**JAX**](https://github.com/google/jax), and [**NumPy**](https://numpy.org). |
| 22 |
|
| 23 |
```python |
| 24 |
import eagerpy as ep |
| 25 |
|
| 26 |
def norm(x): |
| 27 |
x = ep.astensor(x) |
| 28 |
result = x.square().sum().sqrt() |
| 29 |
return result.raw |
| 30 |
``` |
| 31 |
|
| 32 |
You can now **use** the `norm` function **with native tensors** and arrays from PyTorch, TensorFlow, JAX and NumPy with **virtually no overhead compared to native code**. Of course, it also works with **GPU tensors**. |
| 33 |
|
| 34 |
```python |
| 35 |
import torch |
| 36 |
norm(torch.tensor([1., 2., 3.])) |
| 37 |
# tensor(3.7417) |
| 38 |
``` |
| 39 |
|
| 40 |
```python |
| 41 |
import tensorflow as tf |
| 42 |
norm(tf.constant([1., 2., 3.])) |
| 43 |
# <tf.Tensor: shape=(), dtype=float32, numpy=3.7416575> |
| 44 |
``` |
| 45 |
|
| 46 |
```python |
| 47 |
import jax.numpy as np |
| 48 |
norm(np.array([1., 2., 3.])) |
| 49 |
# DeviceArray(3.7416575, dtype=float32) |
| 50 |
``` |
| 51 |
|
| 52 |
```python |
| 53 |
import numpy as np |
| 54 |
norm(np.array([1., 2., 3.])) |
| 55 |
# 3.7416573867739413 |
| 56 |
``` |
| 57 |
|
| 58 |
### Getting Started |
| 59 |
|
| 60 |
You can install the latest release from [PyPI](https://pypi.org/project/eagerpy/) using `pip`: |
| 61 |
|
| 62 |
```bash |
| 63 |
python3 -m pip install eagerpy |
| 64 |
``` |
| 65 |
|
| 66 |
::: warning NOTE |
| 67 |
EagerPy requires Python 3.6 or newer. |
| 68 |
::: |