Stainless neural networks in JAX
Project description
Stainless neural networks in JAX
Inox is a minimal JAX library for neural networks with an intuitive PyTorch-like interface. As with Equinox, modules are represented as PyTrees, which allows to pass networks in and out of native JAX transformations, like jax.jit or jax.vmap. However, Inox implements modules in a different way such that non-array leaves, like hyper-parameters or boolean flags, are automatically marked as static. Consequently, working with Inox modules does not require custom versions of JAX transformations that filter out non-array leaves.
As a philosophical successor to Equinox, Inox inherits its speed, elegance and expressiveness, but tries to be closer to PyTorch in terms of ease of use and intuitiveness. In short, the strengths of JAX and PyTorch, without the rust.
Inox means "stainless steel" in French 🔪
Installation
The inox package is available on PyPI, which means it is installable via pip.
pip install inox
Alternatively, if you need the latest features, you can install it from the repository.
pip install git+https://github.com/francois-rozet/inox
Getting started
Networks are defined using an intuitive PyTorch-like syntax,
import jax
import inox.nn as nn
init_key, data_key = jax.random.split(jax.random.PRNGKey(0))
class MLP(nn.Module):
def __init__(self, key):
keys = jax.random.split(key, 3)
self.l1 = nn.Linear(keys[0], 3, 64)
self.l2 = nn.Linear(keys[1], 64, 64)
self.l3 = nn.Linear(keys[2], 64, 3)
self.relu = nn.ReLU()
def __call__(self, x):
x = self.l1(x)
x = self.l2(self.relu(x))
x = self.l3(self.relu(x))
return x
network = MLP(init_key)
and are fully compatible with native JAX transformations.
X = jax.random.normal(data_key, (1024, 3))
Y = jax.numpy.sort(X, axis=-1)
@jax.jit
def loss_fn(network, x, y):
pred = jax.vmap(network)(x)
return jax.numpy.mean((y - pred) ** 2)
loss = loss_fn(network, X, Y)
For more information, check out the documentation at inox.readthedocs.io.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inox-0.1.0.tar.gz.
File metadata
- Download URL: inox-0.1.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1092f7ffbe4187c87ffec61bfee1521696ee83600ddae66b7fdf18358078143f
|
|
| MD5 |
cd744c27484da958f8b837e5b73ad5d8
|
|
| BLAKE2b-256 |
85ed159e821307256afae5a36a74d34bbf963cc849dd10bbe89515eaab256729
|
File details
Details for the file inox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: inox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9276135c6b4ac4ccc2d9602fc0ff0527a7babfdda6480c35f1a6c6ad163f04e8
|
|
| MD5 |
2c6edd0dbbe1897e5c1c217c648e2dc8
|
|
| BLAKE2b-256 |
894f6c7db6c887ee1c5d873bc8939954280b6cc33b41b99de0731e2be826bd75
|