D
google-deepmind/dm-haiku★ 3,304 · Python
Sonnet-style Python modules with pure JAX functions for model training and inference
Apache-2.0 · Commercial Friendlyv0.0.17
Side-by-side 2026 comparison in LLMs & Inference: jax-ml/jax leads both total GitHub adoption (★ 36.7k) and recent 7-day momentum. Licensing: Apache-2.0 · Commercial Friendly vs Apache-2.0 · Commercial Friendly.
Sonnet-style Python modules with pure JAX functions for model training and inference
Python array SDK for composable autodiff, XLA compilation, and device sharding
Backed by independent 6-hour D1 snapshots. Embed in GitHub READMEs or technical blogs.
| Dimension | google-deepmind/dm-haiku | jax-ml/jax |
|---|---|---|
| Total GitHub Stars | ★ 3,304 | ★ 36,716 |
| 24h / 7d Velocity | +0 / +1 | +5 / +44 |
| 7-Day Trend Curve | ||
| Engineering Health | A · 78/100 | A+ · 98/100 |
| Deployment Signals | GPU | GPU |
| Primary Language | Python | Python |
| Commercial License | Apache-2.0 · Commercial Friendly | Apache-2.0 · Commercial Friendly |
| Activity | Updated 1mo ago | Updated today |
| Latest Release | v0.0.17 | jax-v0.12.1 |
| Best For | Maintaining existing Haiku models or porting Sonnet-style model code to a JAX stack that already handles training infrastructure and serving | Teams building custom numerical workloads or LLM execution paths that need compiled array computations and control over GPU or TPU sharding |
hk.transform exposes pure init and apply functions for JAX transformations.hk.get_parameter initializes or retrieves named arrays in a mapping keyed by module and parameter name.hk.transform_with_state separates trainable parameters from mutable state and returns updated state from apply.hk.next_rng_key() derives per-call keys from the top-level seed; use Haiku-aware wrappers when transforming code that consumes keys inside the model.import haiku as hk import jax.numpy as jnp def softmax_cross_entropy(logits, labels): one_hot = jax.nn.one_hot(labels, logits.shape[-1]) return -jnp.sum(jax.nn.log_softmax(logits) * one_hot, axis=-1) def loss_fn(images, labels): mlp = hk.Sequential([ hk.Linear(300), jax.nn.relu, hk.Linear(100), jax.nn.relu, hk.Linear(10), ]) logits = mlp(images) return jnp.mean(softmax_cross_entropy(logits, labels)) loss_fn_t = hk.transform(loss_fn) loss_fn_t = hk.without_apply_rng(loss_fn_t) rng = jax.random.PRNGKey(42) dummy_images, dummy_labels = next(input_dataset) params = loss_fn_t.init(rng, dummy_images, dummy_labels) def update_rule(param, update): return param - 0.01 * update for images, labels in input_dataset: grads = jax.grad(loss_fn_t.apply)(params, images, labels) params = jax.tree.map(update_rule, params, grads)
jax.jit(jax.vmap(jax.grad(loss), in_axes=(None, 0, 0))) compiles per-example gradients while sharing parameters across the batch.vmap applies batching rules to primitives, allowing batched matrix-vector work to become a matrix-matrix operation.PartitionSpec describe placement; jax.typeof exposes sharding in array types.shard_map provides a per-device view with explicit collectives when automatic partitioning is not enough.import jax import jax.numpy as jnp def predict(params, inputs): for W, b in params: outputs = jnp.dot(inputs, W) + b inputs = jnp.tanh(outputs) # inputs to the next layer return outputs # no activation on last layer def loss(params, inputs, targets): preds = predict(params, inputs) return jnp.sum((preds - targets)**2) grad_loss = jax.jit(jax.grad(loss)) # compiled gradient evaluation function perex_grads = jax.jit(jax.vmap(grad_loss, in_axes=(None, 0, 0))) # fast per-example grads
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy