Skip to main content

Stainless neural networks in JAX

Project description

Inox's banner

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 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, Inox modules are compatible with native JAX transformations out of the box, and do not require custom lifted transformations.

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.

Contributing

If you have a question, an issue or would like to contribute, please read our contributing guidelines.

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

inox-0.3.1.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inox-0.3.1-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file inox-0.3.1.tar.gz.

File metadata

  • Download URL: inox-0.3.1.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for inox-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e58d5815e4f5eda0b7b2cc09dc07cae4984d4162fd57c7c321b9476ceb1d384f
MD5 78e9c5e89a67c260653e5a663b2add8e
BLAKE2b-256 22f189b8a83aa06e872193abeb5cfebaa6fe91de8a49e01ecd0aeaa31958cea6

See more details on using hashes here.

File details

Details for the file inox-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: inox-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for inox-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb967fa12c2ff08085f85985c548850891230cd6cf3ca28a52406c266c1ff11d
MD5 4fbae8dcb6f80d20b7283b645a014aef
BLAKE2b-256 47b8c40b9f4101bb0bb4f74ebeb56056bcc205eb6512fdc96bc1c4c96d45a42e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page