Skip to main content
+-------------------------------------+
|       __              __      __    |
|      /_/\            / /\    /_/\   |
|     /_/  \          / /  \  /_/ /   |
|    /_/ /\ \        / / /\ \/_/ /    |
|   /_/ /\_\ \      / / /\_\ \/ /     |
|  /_/ /  \_\ \    / / /__\_\  /      |
|  \_\ \  /_/ /   / / ______   \      |
|   \_\ \/_/ /   / / /   /_/ /\ \     |
|    \_\ \/_/___/ / /   /_/ /\_\ \    |
|     \_\/_______/ /   /_/ /  \_\ \   |
|      \_\_\_\_\_\/    \_\/    \_\/   |
|                                     |
+-------------------------------------+

Github | Documentation

What is OJAX

OJAX is a small extension of JAX to facilitate modular coding.

You might have already noticed, due to its functional nature, JAX does not pair well with the generic Python class structure. People tend to instead write closures/functionals which are functions that return JAX functions (e.g. the Stax NN library from the JAX codebase), which is far from ideal for complex projects.

OJAX lets you write JAX code using class again, with full JAX compatibility, max flexibility, and zero worry. Here is an example custom class using OJAX that can be directly jax.jitted:

class AddWith(ojax.OTree):
    value: float

    def __call__(self, t: jax.Array) -> jax.Array:
        return t + self.value


add42_jitted = jax.jit(AddWith(42.0))
print(add42_jitted(jax.numpy.ones(1)))  # [43.]

OJAX is a simple library that needs less than 1 hour to learn, and will save you countless hours for your JAX projects!

Why OJAX

"Library XXX already did something similar, why reinvent the wheel?"

The short answer is: because the wheel is rounder this time ;)

Motivated by deep learning applications, there are many JAX libraries that already propose some kind of module system: Flax, Equinox, Haiku, Simple Pytree, Treeo / Treex, PAX, just to name a few.

However, none of them offers a perfect “JAX base class” that fulfills all of the desiderata below:

  • Simple to understand and use

  • Flexible custom classes for general JAX computation

  • Compatible with JAX and its functional paradigm

OJAX strives to define how a JAX base class should be. It provides a natural way to structure custom JAX code and discourages users from common pitfalls.

P.S.: the name “OJAX” is a chapeau-bas to OCaml, an awesome functional programming language.

How to code with OJAX

OJAX is easy to install following the installation guide.

You can have a look at the quickstart section to get started, and there is also a simple example code using OJAX.

Of course, check out the OJAX API reference for exact definitions.

Release files for ojax 4.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ojax 4.0.1
File Size Uploaded
ojax-4.0.1.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ojax 4.0.1
File Interpreter ABI Platform
ojax-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 28.6 kB

Release files / ojax-4.0.1.tar.gz

Download URL ojax-4.0.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7778d1493f96619de9f6ca5780fd6047dec8ea1f6241db53b3af4da10397d86b
BLAKE2b-256 checksum
How to use checksums
989d8338c77090e1c8a466d09e088fb8f2e9c59492e69c3271c6ae7ac0e6b5d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.16

Release files / ojax-4.0.1-py3-none-any.whl

Download URL ojax-4.0.1-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f12874b733e5e8e8bd8d8d2ec219f03505c5a23fb26fb53456564521b9c25530
BLAKE2b-256 checksum
How to use checksums
c87b80e32cde0530138a16266b323ebc649539c571a4305b38f8955542d91b5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.16

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page