asdex
Automatic Sparse Differentiation in JAX.
asdex exploits sparsity structure to efficiently materialize Jacobians and Hessians.
It implements a custom Jaxpr interpreter
that uses abstract interpretation
to detect sparsity patterns from the computation graph,
then uses graph coloring to minimize the number of AD passes needed.
Installation
pip install asdex
Or with uv:
uv add asdex
Example
import asdex
import jax
import jax.numpy as jnp
def f(x):
return (x[1:] - x[:-1]) ** 2
x_sample = jnp.zeros(50) # sample input for sparsity pattern detection
jac_fn = jax.jit(asdex.jacobian(f, x_sample))
# ColoredPattern(49×50, nnz=98, sparsity=96.0%, JVP, 2 colors)
# 2 JVPs (instead of 49 VJPs or 50 JVPs)
# ⎡⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎤ ⎡⣿⎤
# ⎢⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ → ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⎥ ⎢⣿⎥
# ⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⎦ ⎣⠉⎦
for x in inputs:
J = jac_fn(x)
Instead of 49 VJPs or 50 JVPs,
asdex computes the full sparse Jacobian with just 2 JVPs.
Since sparsity detection and coloring can be expensive on large problems, we recommend saving and reusing colored patterns:
import jax.numpy as jnp
from asdex import jacobian_coloring
from asdex import ColoredPattern, jacobian_from_coloring
# Compute coloring once...
x = jnp.zeros(1000)
coloring = jacobian_coloring(f, x)
coloring.save("colored.npz")
# ...load and reuse later
coloring = ColoredPattern.load("colored.npz")
jac_fn = jax.jit(jacobian_from_coloring(f, coloring))
Features
The full ASD pipeline:
- Sparse Jacobians and Hessians: one VJP/JVP/HVP per color, with automatic (or user-defined) mode selection.
- Sparsity detection: finds global sparsity patterns valid for all inputs.
- Graph coloring: row, column, and symmetric coloring minimize AD passes.
- Correctness verification against vanilla JAX.
You already know your sparsity pattern?
- Manually provide sparsity patterns: supply a known pattern from dense, COO, or BCOO formats.
- Precompute, save & load: reuse a colored pattern across inputs, or persist it by saving and loading.
An interface mirroring JAX:
- Multiple inputs and outputs: supports multi-argument functions via
argnums, as well as multiple return values. - PyTree inputs and outputs: sparse differentiation through arbitrary nested PyTrees.
- Auxiliary outputs: supports
has_aux=Truefor functions returning(output, aux). - Value and derivative:
value_and_jacobian/value_and_hessianreturn the primal valuef(x)without a redundant forward pass.
And more:
- Multiple output formats: decompression to BCOO, dense JAX arrays, NumPy, and SciPy (COO/CSR/CSC) arrays.
- Bounded memory:
chunk_sizecaps parallel AD passes for large color counts. - Visualizations:
spyplots and braille pattern previews.
Documentation
- Getting Started: step-by-step tutorial
- How-To Guides: task-oriented recipes
- Explanation: how and why it works
- API Reference: full API documentation
- Contributing: guidelines for collaborating on asdex
- AI Policy: guidelines for LLM contributions
Related work
Prior work on ASD by asdex's authors Adrian Hill (@adrhill) and Guillaume Dalle (@gdalle), as well as Alexis Montoison (@amontoison):
- An Illustrated Guide to Automatic Sparse Differentiation, Hill, Dalle, Montoison (2025)
- Sparser, Better, Faster, Stronger: Efficient Automatic Differentiation for Sparse Jacobians and Hessians, Hill & Dalle (2025)
- Revisiting Sparse Matrix Coloring and Bicoloring, Montoison, Dalle, Gebremedhin (2025)
SparseConnectivityTracer.jl, Hill & DalleSparseMatrixColorings.jl, Dalle & MontoisonDifferentiationInterface.jl, Dalle & Hill
Prior and concurrent (partial) attempts at ASD in JAX:
sparsejac: coloring and decompressionsparsediffax: coloring and decompression (by asdex's@gdalle)jax-nansparse: sparsity detection using NaN propagationJAX-AMG: specialized ASD module for algebraic multigrid methodstatva: specialized ASD module for FEM- See discussion in JAX issue #1032
Acknowledgements
Adrian Hill gratefully acknowledges funding from the German Federal Ministry of Education and Research under the grant BIFOLD26B.
This package is built with Claude Code, based on previous, hand-written work by the same authors in the Julia programming language, as noted above. These works in turn stand on the shoulders of giants, notably Andreas Griewank, Andrea Walther, and Assefaw Gebremedhin.
The asdex logo was designed by @overripemango.
Citation
If you use asdex in your research, please cite:
@software{asdex2026,
author = {Hill, Adrian and Dalle, Guillaume},
title = {asdex: Automatic Sparse Differentiation in JAX},
url = {https://github.com/adrhill/asdex},
doi = {10.5281/zenodo.18788242}
}
Metadata
Release files for asdex 0.5.2
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 | |
|---|---|---|---|---|
| asdex-0.5.2.tar.gz | 504.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asdex-0.5.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 649.2 kB
Release files / asdex-0.5.2.tar.gz
| Download URL | asdex-0.5.2.tar.gz |
|---|---|
| Size | 504.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73fc42e6a4109f922a94cdd1b1c3c8adab136cbbf60ae0d2678b1f1bf2277b23
|
|
BLAKE2b-256 checksum How to use checksums |
f5fc427adad6a857f495127bae6e636ccb7b9808eb1c56ec86b525ffd57ce0b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / asdex-0.5.2-py3-none-any.whl
| Download URL | asdex-0.5.2-py3-none-any.whl |
|---|---|
| Size | 145.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca96b85cecc7f927ed77467682b3e708378d944a7246e886b33a37ae42cab280
|
|
BLAKE2b-256 checksum How to use checksums |
5320d92d7d0a18052f083cdcb75c41c34a4cddcb01f746796fe9a1264b54ec73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for asdex 0.5.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.