Skip to main content

PyPI - Version EffVer Versioning SPEC-0 Ruff ty PyPI - Python Version

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 dataclass that 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.
  • A gradient package that provides every transformation in optax as a pytree. (See Gradient transformations.)
  • A pretty printer print_generic for 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.grad differentiates through an update with respect to its hyperparameters, for example to tune a learning rate by gradient descent.
  • Vectorization. jax.vmap maps an update over hyperparameter values, for example to sweep learning rates in one call.
  • Static options. Structural arguments, such as nesterov and 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 to update.
  • 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:

  • HvpGradientTransformation and DiagHessianGradientTransformation define 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_optax converts a tjax transformation into an optax one.
  • Schedule wraps an optax schedule so that it can be passed as a learning rate.

Minor components

Tjax also includes:

  • Versions of custom_vjp and custom_jvp that support being used on methods: custom_vjp_method and custom_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 frozendict that is registered as a JAX pytree, so it can be passed through transforms like jit and vmap. (See frozendict.)
  • Leaky integration leaky_integrate and Ornstein-Uhlenbeck process iteration diffused_leaky_integrate. (See leaky_integral.)
  • A testing function assert_tree_allclose that automatically produces testing code. And, a related function tree_allclose, which compares pytrees with matching structure. (See testing.)
  • Basic tools like divide_or_zero and divide_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 check
  • uv run ruff format
  • uv 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)

Source distribution for tjax 2.0.1
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)

Table of built distributions (wheels) for tjax 2.0.1
File Interpreter ABI Platform Actions
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 log

Release 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 log

Security 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.

Select from 2 files

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 log

A 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.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files Full provenance

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