extropic-ai/thrml

Thermodynamic Hypergraphical Model Library in JAX

THRML – JAX‑powered sampling for probabilistic graphical models

What it is

  • A Python library (installable via pip install thrml) built on top of JAX.
  • Provides fast, GPU‑accelerated block Gibbs sampling for discrete probabilistic graphical models (PGMs) and energy‑based models (EBMs).
  • Designed to prototype the kind of sampling that Extropic plans to run on custom low‑power hardware, but works today on any JAX‑compatible device.

Key capabilities

  • Blocked Gibbs sampling – updates groups of variables (blocks) together, which is much more efficient on modern hardware than updating one node at a time.
  • Arbitrary PyTree node states – you can attach any JAX‑compatible data structure to a node, not just scalars.
  • Heterogeneous graphs – supports models where different nodes have different types or interaction patterns.
  • Discrete EBM utilities – helpers for building and training energy‑based models such as Ising models.
  • Backend‑agnostic execution – the core API works with the default JaxBackend, but you can plug in a custom backend that talks to external hardware or other accelerators.

Typical workflow

  1. Define nodes (e.g., SpinNode) and edges that describe the factor graph.
  2. Create a model (e.g., IsingEBM) by supplying biases, weights, temperature, etc.
  3. Group nodes into blocks (Block) that will be sampled together.
  4. Build a sampling program (IsingSamplingProgram) that ties the model to the block layout.
  5. Choose a schedule (SamplingSchedule) that specifies warm‑up steps, number of samples, and how many Gibbs steps to take per sample.
  6. Run sampling with sample_states, optionally passing a custom backend.

Quick example (sampling a 5‑node Ising chain)

import jax, jax.numpy as jnp
from thrml import SpinNode, Block, SamplingSchedule, sample_states
from thrml.models import IsingEBM, IsingSamplingProgram, hinton_init

# 1. Build graph
nodes = [SpinNode() for _ in range(5)]
edges = [(nodes[i], nodes[i+1]) for i in range(4)]

# 2. Model parameters
biases = jnp.zeros(5)
weights = jnp.full(4, 0.5)
beta = jnp.array(1.0)
model = IsingEBM(nodes, edges, biases, weights, beta)

# 3. Block layout (alternating colors)
free_blocks = [Block(nodes[::2]), Block(nodes[1::2])]
program = IsingSamplingProgram(model, free_blocks, clamped_blocks=[])

# 4. Initialise state
key = jax.random.key(0)
init_state = hinton_init(jax.random.split(key)[0], model, free_blocks, ())

# 5. Sampling schedule
schedule = SamplingSchedule(n_warmup=100, n_samples=1000, steps_per_sample=2)

# 6. Run sampler
samples = sample_states(jax.random.split(key)[1], program, schedule, init_state, [], [Block(nodes)])

The call returns a JAX array of sampled spin configurations.

Installation

pip install thrml          # or "uv pip install thrml" for the uv installer

Requires Python 3.10 or newer and a working JAX installation (CPU, GPU, or TPU).

Documentation & learning resources

When to use THRML

  • You need high‑throughput sampling of discrete PGMs (e.g., Ising, Potts, binary factor graphs).
  • You are experimenting with block‑wise Gibbs updates to speed up convergence.
  • You want a JAX‑native workflow that can later be swapped to custom hardware backends.
  • You are researching energy‑based models and need a library that treats the model as a factor graph rather than a neural net.

Citation If you publish work that relies on THRML, cite the accompanying arXiv paper:

@misc{jelinčič2025efficientprobabilistichardwarearchitecture,
  title={An efficient probabilistic hardware architecture for diffusion-like models},
  author={Andraž Jelinčič and Owen Lockwood and Akhil Garlapati and Guillaume Verdon and Trevor McCourt},
  year={2025},
  eprint={2510.23972},
  archivePrefix={arXiv},
  primaryClass={cs.LG},
  url={https://arxiv.org/abs/2510.23972}
}

Who should look at this

  • Researchers and engineers working on discrete probabilistic models, EBMs, or sampling algorithms.
  • Developers interested in prototyping algorithms that will eventually run on specialized low‑energy sampling chips.
  • Anyone already using JAX who wants a library that stays fully JIT‑compatible and avoids Python‑level loops.

Related

  • Project
  • Project
  • Project
  • Project
  • Project