High-performance composable JAX library
Project description
xtrax
A set of composable building blocks for JAX/Equinox training loops — engine + trainer orchestration, safety-checked steps, axis tiling strategies, inference-time sparsification, distributed/sharding helpers, streaming output callbacks, and orbax checkpointing — extracted from the author's research code.
Status
xtrax is alpha, experimental software built primarily for the author's personal research use. APIs may change without notice between releases; no backward-compatibility guarantees pre-1.0. Issues and pull requests are welcome, but support is best-effort — the project exists first to serve the author's own JAX training workflows.
Why xtrax?
- Composable training steps — Use
TrainerorSafetyTrainStepwith your own loss functions and optimizers - Safety-checked arithmetic — Avoid NaN/Inf propagation with safe operations (
safe_norm,safe_reciprocal) - Flexible tiling strategies — Partition computations with
AxisSpec,BatchPlan, andVmap/SafeMapfor data and model parallelism - Inference sparsification — Apply structured sparsity masks with
SparseConfigandsparsify_model - Distributed helpers — Initialize and coordinate multi-GPU/TPU training with
init_dist,LogicalMesh, and sharding utilities
Installation
pip install xtrax
Requires Python 3.13 or later.
Quick Start
import jax
import optax
from xtrax import Trainer, ResumableState, Engine, save_checkpoint, load_checkpoint
# 1. Create a simple loss function
def loss_fn(model, batch):
predictions = model(batch["inputs"])
return jnp.mean((predictions - batch["targets"]) ** 2)
# 2. Set up trainer with optimizer
optimizer = optax.adam(1e-3)
trainer = Trainer(loss_fn=loss_fn, optimizer=optimizer)
# 3. Initialize training state
model = ... # Your equinox model
opt_state = optimizer.init(...)
state = ResumableState(model=model, opt_state=opt_state, step=0)
# 4. Run a training step
new_state, metrics = trainer.step(state, batch={"inputs": x, "targets": y})
print(f"Loss: {metrics['loss']}")
For a complete training loop with callbacks and checkpointing, use the Engine:
from xtrax import Engine, DataModule
# Create or load a DataModule (must implement train_iter())
data = DataModule(...)
# Create an engine with trainer and optional callbacks
engine = Engine(trainer=trainer)
# Run multi-epoch training with checkpoint saving
final_state = engine.fit_sync(
state=state,
data=data,
num_epochs=10,
checkpoint_dir="./checkpoints"
)
Getting Results Out
Streaming Callbacks
Log metrics asynchronously to files or external services:
from xtrax.io import BoundedCallbackHandler, async_indexed_stream
# Create a custom async callback
class LogCallback:
async def on_step_end(self, state, metrics):
print(f"Step {state.step}: {metrics}")
# Use in your Engine
engine = Engine(
trainer=trainer,
callbacks=[LogCallback()]
)
Checkpoint Save and Load
Save model state and restore for inference or resumption:
from xtrax import save_checkpoint, load_checkpoint
# After training
save_checkpoint(checkpoint_dir="./checkpoints/final", state=final_state)
# Load for inference
restored_state = load_checkpoint(checkpoint_dir="./checkpoints/final")
model = restored_state.model
# Run inference
predictions = model(test_inputs)
Documentation
Full API docs, architecture guides, and advanced examples at xtrax.readthedocs.io.
Project links
License
Licensed under the Apache License 2.0.
Citation
If you use xtrax in research, please cite it:
@software{xtrax,
title = {xtrax: High-Performance Composable JAX Training},
author = {Russo, Marielle},
version = {0.3.0},
year = {2026},
url = {https://github.com/maraxen/xtrax}
}
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 xtrax-0.3.1.tar.gz.
File metadata
- Download URL: xtrax-0.3.1.tar.gz
- Upload date:
- Size: 866.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93e8cad47c8b93ac318c329756bb78cd4a98a050dbdbdd9a675fbb9fd1f6ed83
|
|
| MD5 |
d6ceee282c97198569172eef55e42f0c
|
|
| BLAKE2b-256 |
a5f5ab6652550526db950999bd67c88d4d7d288be9547dfc700e665f5fc6db0c
|
Provenance
The following attestation bundles were made for xtrax-0.3.1.tar.gz:
Publisher:
publish.yml on maraxen/xtrax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xtrax-0.3.1.tar.gz -
Subject digest:
93e8cad47c8b93ac318c329756bb78cd4a98a050dbdbdd9a675fbb9fd1f6ed83 - Sigstore transparency entry: 2048338466
- Sigstore integration time:
-
Permalink:
maraxen/xtrax@5687942a9c9ddbe53ef7b8b70dd8136166e92d72 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/maraxen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5687942a9c9ddbe53ef7b8b70dd8136166e92d72 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xtrax-0.3.1-py3-none-any.whl.
File metadata
- Download URL: xtrax-0.3.1-py3-none-any.whl
- Upload date:
- Size: 114.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2286d98eb81bc45bbb8a0dc8864ac2e344325b12ea26f0cc472135edeed3fc6f
|
|
| MD5 |
a5748928b1f42fcf8770e436c707c49f
|
|
| BLAKE2b-256 |
a0b9644027917cfecf1f13675e7c58b30a021d58572e5200516258a1030f9946
|
Provenance
The following attestation bundles were made for xtrax-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on maraxen/xtrax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xtrax-0.3.1-py3-none-any.whl -
Subject digest:
2286d98eb81bc45bbb8a0dc8864ac2e344325b12ea26f0cc472135edeed3fc6f - Sigstore transparency entry: 2048338471
- Sigstore integration time:
-
Permalink:
maraxen/xtrax@5687942a9c9ddbe53ef7b8b70dd8136166e92d72 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/maraxen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5687942a9c9ddbe53ef7b8b70dd8136166e92d72 -
Trigger Event:
push
-
Statement type: