Tools for JAX
This repository implements a variety of tools for the differential programming library JAX.
Major components
Tjax's major components are:
- A dataclass decorator
dataclassthat facilitates defining structured JAX objects (so-called "pytrees"), which benefits from:- the ability to mark fields as static (not available in
chex.dataclass), and - a display method that produces formatted text according to the tree structure.
- the ability to mark fields as static (not available in
- A gradient package that provides every transformation in optax as a pytree. (See Gradient transformations.)
- A pretty printer
print_genericfor aggregate and vector types, including dataclasses. (See display.) It features:- support for traced values,
- colorized tree output for aggregate structures, and
- formatted tabular output for arrays (or statistics when there's no room for tabular output).
Gradient transformations
tjax.gradient provides every optax transformation as a dataclass whose fields are the
transformation's arguments. Each transformation is a pytree, so JAX traces its hyperparameters like
any other array.
This matters because an optax transformation is a pair of functions that close over their
hyperparameters, which JAX can't see. You can't pass an optax transformation to a jitted function;
you construct it inside the traced function or wrap it with optax.inject_hyperparams. A tjax
transformation instead behaves like data:
- Jit. A transformation can be an argument of a jitted function, and a new value of a numeric hyperparameter, such as the learning rate, reuses the compiled function.
- Differentiation.
jax.graddifferentiates through an update with respect to its hyperparameters, for example to tune a learning rate by gradient descent. - Vectorization.
jax.vmapmaps an update over hyperparameter values, for example to sweep learning rates in one call. - Static options. Structural arguments, such as
nesterovand weight-decay masks, are static fields, so jit compiles a specialized function for each setting. - Types.
GradientTransformation[State, Weights]is generic in its state and weight types, so a type checker can check what you pass toupdate. - Display. A transformation prints with its hyperparameters, for example
Adam(learning_rate=0.01, b1=0.9, ...).
For example, this code compiles one Adam step for two learning rates, then differentiates and maps the loss after one SGD step over the learning rate:
import jax
import jax.numpy as jnp
import optax
import tjax.gradient as tg
params = {"w": jnp.array([1.0, -2.0])}
def loss(params):
return jnp.sum(params["w"] ** 2)
@jax.jit
def loss_after_step(transform, params):
gradient = jax.grad(loss)(params)
updates, _ = transform.update(gradient, transform.init(params), params)
return loss(optax.apply_updates(params, updates))
loss_after_step(tg.Adam(1e-2), params) # Compiles.
loss_after_step(tg.Adam(3e-2), params) # Reuses the compiled function.
# Differentiate with respect to the learning rate.
jax.grad(lambda lr: loss_after_step(tg.SGD(lr), params))(0.1)
# Take one step at each of three learning rates.
jax.vmap(lambda lr: loss_after_step(tg.SGD(lr), params))(jnp.array([0.01, 0.1, 0.4]))
The package also extends optax's interface:
HvpGradientTransformationandDiagHessianGradientTransformationdefine update rules that receive a Hessian-vector product or the Hessian's diagonal.SMDGradient(stochastic meta-descent) builds on them.- Combinators, such as
ChainedGradientTransformation, combine tjax transformations. to_optaxconverts a tjax transformation into an optax one.Schedulewraps an optax schedule so that it can be passed as a learning rate.
Minor components
Tjax also includes:
- Versions of
custom_vjpandcustom_jvpthat support being used on methods:custom_vjp_methodandcustom_jvp_method(See shims.) - Tools for working with cotangents. (See cotangent_tools.)
- JAX tree registration for NetworkX graph types. (See graph.)
- A hashable immutable mapping
frozendictthat is registered as a JAX pytree, so it can be passed through transforms likejitandvmap. (See frozendict.) - Leaky integration
leaky_integrateand Ornstein-Uhlenbeck process iterationdiffused_leaky_integrate. (See leaky_integral.) - A testing function
assert_tree_allclosethat automatically produces testing code. And, a related functiontree_allclose, which compares pytrees with matching structure. (See testing.) - Basic tools like
divide_or_zeroanddivide_where. (See tools.)
Contribution guidelines
The implementation should be consistent with the surrounding style, be type annotated, and pass the linters below.
To run tests: uv run pytest
There are a few tools to clean and check the source:
uv run ruff checkuv run ruff formatuv run ty check
Metadata
Release files for tjax 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tjax-2.0.1.tar.gz | 70.4 kB | With provenance | Details for tjax-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tjax-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for tjax-2.0.1-py3-none-any.whl |
Total release size: 153.5 kB
Release files / tjax-2.0.1.tar.gz
| Download URL | tjax-2.0.1.tar.gz |
|---|---|
| Size | 70.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bbe3ed749c4e1e5c76b546f40b488cd25067886b9fb5a9c37cb6e91971efaed
|
|
BLAKE2b-256 checksum How to use checksums |
0ae9309c13d225c6e73d874dd6eeaf2ae0fb5f5cb45d3d321d1fb32d906b7ce6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / tjax-2.0.1-py3-none-any.whl
| Download URL | tjax-2.0.1-py3-none-any.whl |
|---|---|
| Size | 83.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ddf1a38e9b27fb12d8c2e0d7c839f940b7239bb8f5c01782e866505a0d6e581c
|
|
BLAKE2b-256 checksum How to use checksums |
da217f942516e89099d86bbfe14355dd89c5dc277b5f27f6f01237a10d4a2365
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for tjax 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tjax-2.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.