Skip to main content

An extension for modular JAX code.

Project description

+-------------------------------------+
|       __              __      __    |
|      /_/\            / /\    /_/\   |
|     /_/  \          / /  \  /_/ /   |
|    /_/ /\ \        / / /\ \/_/ /    |
|   /_/ /\_\ \      / / /\_\ \/ /     |
|  /_/ /  \_\ \    / / /__\_\  /      |
|  \_\ \  /_/ /   / / ______   \      |
|   \_\ \/_/ /   / / /   /_/ /\ \     |
|    \_\ \/_/___/ / /   /_/ /\_\ \    |
|     \_\/_______/ /   /_/ /  \_\ \   |
|      \_\_\_\_\_\/    \_\/    \_\/   |
|                                     |
+-------------------------------------+

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.

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

ojax-3.1.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

ojax-3.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file ojax-3.1.0.tar.gz.

File metadata

  • Download URL: ojax-3.1.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for ojax-3.1.0.tar.gz
Algorithm Hash digest
SHA256 1095940d9cc2b0e99eb2b14c2680d4bdd660d09d3c1172548dad13f952006554
MD5 db7db4bd53af8c5c0f5777e2a027d146
BLAKE2b-256 c98bd2f4f6dad0d05802c09ad3adc6d89c977977bbcfd6eb11c2f76e698796f3

See more details on using hashes here.

File details

Details for the file ojax-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: ojax-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for ojax-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0931bcc7348a4e941bca3ca92fbfbf80423554554b7b6668f8a717fb0e16a5e2
MD5 388fc562b4c8882bb2b4f5035e5998ef
BLAKE2b-256 2995cc5fe73428497a6cc084a62498cea123b82620be943124563cbad5e180da

See more details on using hashes here.

Supported by

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