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 modules automatically detect non-array leaves, like hyper-parameters or boolean flags, and consider them as static. Consequently, working with Inox modules does not require custom versions of JAX transformations that filter out non-array leaves.
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 with an intuitive PyTorch-like syntax,
import jax
import inox.nn as nn
init_key, data_key = jax.random.split(jax.random.key(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)
grads = jax.grad(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.2.0.tar.gz.
File metadata
- Download URL: inox-0.2.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45c521dc8fbc625f16e14be78b2779a6bf2a123a2980f9a1677b06744c12fb49
|
|
| MD5 |
d81230c62fe55058ea1bcea70f8f3b58
|
|
| BLAKE2b-256 |
c9206ca87674efbdf9ef67ad527bfc94ece05059b44705d993f065191d584785
|
File details
Details for the file inox-0.2.0-py3-none-any.whl.
File metadata
- Download URL: inox-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c273f8f5450826f21ec4af2b309a2a7ec0c97d0ee0ac352a01663d6fc3ab5d9
|
|
| MD5 |
d4499f6a4df8c748de007dc1e5cad78d
|
|
| BLAKE2b-256 |
8a36e38a5171c163f0bd78cd501bba490212700600a7e26ede548b5cc78d6606
|