rax

jax + rust => a memory safe DL framework

https://github.com/viraatdas/rax

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

jax + rust => a memory safe DL framework

Basic Info
  • Host: GitHub
  • Owner: viraatdas
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Size: 16.5 MB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created 12 months ago · Last pushed 12 months ago
Metadata Files
Readme Changelog Contributing License Citation Authors

README.md

RAX: A Safe JAX Frontend

RAX is a compiler-like frontend for JAX that adds shape/type safety and memory correctness guarantees to your JAX code, without requiring any code changes beyond adding type annotations.

Installation

From GitHub

bash pip install git+https://github.com/viraatdas/rax.git

For Development

bash git clone -b rax https://github.com/viraatdas/rax.git cd rax pip install -e .

Quick Start

  1. Annotate your functions with jaxtyping:

```python

my_model.py

import jax.numpy as jnp from jaxtyping import Float, Array

def dense(x: Float[Array, "batch 128"], w: Float[Array, "128 64"]) -> Float[Array, "batch 64"]: return jnp.dot(x, w)

def model(x: Float[Array, "batch 128"]) -> Float[Array, "batch 64"]: w = jnp.ones((128, 64)) return dense(x, w)

Run your model

x = jnp.ones((32, 128)) output = model(x) print(f"Output shape: {output.shape}") ```

  1. Run with RAX:

bash rax run my_model.py

What RAX Does

When you run rax run script.py, RAX:

  1. Scans for user-defined functions in your script
  2. Validates type annotations - Requires all functions to have jaxtyping annotations
  3. Enforces shapes at runtime via beartype integration
  4. Traces functions symbolically using jax.make_jaxpr to catch shape/math errors
  5. JIT-compiles by default for performance
  6. Monkeypatches JAX operations to validate shapes

Safety Guarantees

| Guarantee | Mechanism | |-----------|-----------| | Type & shape correctness | @beartype + jaxtyping | | Math logic validation | jax.make_jaxpr(fn)(*args) | | Compilation before execution | jax.jit (automatic) | | Early failure on errors | Compile-time trace validation | | Memory predictability | Enforced size-consistent ops |

Examples

Valid Code

```python

This runs successfully

def add(x: Float[Array, "10"], y: Float[Array, "10"]) -> Float[Array, "10"]: return x + y

result = add(jnp.ones(10), jnp.ones(10)) ```

Invalid Code (Caught by RAX)

```python

This fails at validation time

def bad_dot(x: Float[Array, "32 100"], w: Float[Array, "128 64"]) -> Float[Array, "32 64"]: return jnp.dot(x, w) # Shape mismatch!

RAX output:

[RAX] Shape/dimension error in function 'bad_dot':

dot shape mismatch: (32, 100) · (128, 64)

```

CLI Options

```bash rax run script.py [options]

Options: --no-jit Disable automatic JIT compilation --no-monkeypatch Disable JAX operation monkeypatching --verbose Enable verbose output ```

Requirements

  • JAX code must use jaxtyping annotations for all function parameters and returns
  • No other code changes needed - RAX is fully compatible with existing JAX code

Future Extensions

  • rax compile - Validate without execution
  • rax trace - Output compiled JAXPR for debugging
  • rax lint - Detect missing annotations
  • rax export - Export to XLA/MLIR format

Owner

  • Name: Viraat Das
  • Login: viraatdas
  • Kind: user

SDE @ Amazon | Purdue CS Alum Machine and deep learning enthusiast

GitHub Events

Total
  • Watch event: 1
  • Push event: 1
  • Create event: 2
Last Year
  • Watch event: 1
  • Push event: 1
  • Create event: 2

Dependencies

docs/requirements.txt pypi
  • absl-py *
  • cmake *
  • flatbuffers *
  • ipython >=8.8.0
  • matplotlib *
  • myst-nb >=1.0.0
  • numpy *
  • pooch *
  • pydata-sphinx-theme ==0.14.4
  • pytest *
  • pytest-xdist *
  • rich *
  • scikit-learn *
  • snowballstemmer <3.0.0
  • sphinx >=7.3.2,<8.0
  • sphinx-book-theme ==1.1.1
  • sphinx-copybutton >=0.5.0
  • sphinx-design *
  • sphinx-remove-toctrees *
  • sphinxext-rediraffe *
examples/ffi/pyproject.toml pypi
  • jax *
jax/experimental/jax2tf/examples/requirements.txt pypi
  • flax *
  • tensorflow_datasets *
  • tensorflow_hub *
jax_plugins/cuda/pyproject.toml pypi
jax_plugins/cuda/setup.py pypi
jax_plugins/rocm/pyproject.toml pypi
jax_plugins/rocm/setup.py pypi
jaxlib/setup.py pypi
  • ml_dtypes >=0.5.0
  • numpy >=1.26
  • scipy >=1.12
pyproject.toml pypi
  • beartype >=0.15.0
  • jax >=0.4.0
  • jaxlib >=0.4.0
  • jaxtyping >=0.2.0
  • numpy >=1.20.0
setup.py pypi