← Back to Leaderboard
Dgoogle-deepmind

google-deepmind/dm-haiku

Sonnet-style Python modules with pure JAX functions for model training and inference

AI FrameworkQuickstart ↓
Engineering Health (Methodology)
A · 78/100
Maintenance Activity
● Updated 1mo ago
Latest Release
v0.0.17
Commercial License Check
Apache-2.0 · Commercial Friendly

Automated SPDX check for reference only — not legal advice. Disclaimer

Maintenance26/35
Fork Adoption18/25
Release Cadence14/20
License Clarity20/20
GPU
Total Stars
★ 3,304
24h Growth
+0
7d Growth
+1
Forks
305

GitHub Star History

Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.

google-deepmind/dm-haiku Star History (2020-02-19 - 2026-12-03) ALL-TIME STAR HISTORY (2020-02 – 2026-12) +3.3k in 2479d · avg +1/day 3.5k 1.7k 0 2020-02-19: ★ 12020-07-25: ★ 6282020-12-26: ★ 8202021-05-29: ★ 1,0662021-10-30: ★ 1,3572022-04-02: ★ 1,7292022-09-03: ★ 2,0322023-02-04: ★ 2,2552023-07-08: ★ 2,4452023-12-09: ★ 2,5752024-05-11: ★ 2,7482024-10-12: ★ 2,8212025-03-15: ★ 2,9472025-08-16: ★ 3,0402026-01-17: ★ 3,1432026-06-20: ★ 3,2312026-12-03: ★ 3,304 ★ 3.3k 2020-02 2023-07 2026-12

Evidence-Backed Technical Brief

AI Deep Review

Architecture & Core Mechanics

Haiku is a Python model-definition library for JAX, not an inference server. An hk.Module subclass describes computation and requests named weights through hk.get_parameter. hk.transform converts that definition into init and apply: init runs the model to collect initial arrays into a nested mapping keyed by module and parameter name, while apply resolves those requests against caller-supplied weights. Custom modules extend the library through ordinary Python subclassing.

That boundary lets application code use JAX compilation, autodiff, and parallel transforms without threading parameters through each layer by hand. Haiku itself is pure Python; JAX supplies the compiled runtime and device backend. The base requirements list absl-py>=0.7.1, jmp>=0.0.2, numpy>=1.18.0, and tabulate>=0.8.9. JAX is installed separately, so choosing an accelerator backend is an environment decision.

Key Capabilities & Differentiators

Haiku works at the level of model components: hk.Linear and hk.Sequential assemble feed-forward networks, while hk.nets.ResNet50 illustrates a network with mutable state. hk.transform_with_state keeps values such as batch-normalization moving averages separate from trainable weights and returns updated state on each application. For dropout and other stochastic operations, hk.next_rng_key() derives keys deterministically from the caller's key; deterministic forward passes can omit the apply-time key via hk.without_apply_rng.

The transformed functions can be passed to jax.jit, jax.grad, and jax.pmap. In data-parallel training, the application handles parameter placement or replication and supplies a batch per device. This supports running a model's forward pass as part of a larger inference stack, but it does not provide a pretrained LLM catalog, a model-serving API, or a request scheduler.

Trade-offs & Limitations

The Sonnet-style interface offers named parameters and familiar module composition while keeping the public execution path functional. The cost is that purity is established at the transform boundary: hk.next_rng_key() consumes Haiku's internal RNG sequence, so placing raw JAX transformations around such code inside hk.transform can mis-handle that context. Prefer transforming the resulting apply function, or use the relevant Haiku wrapper for transforms inside the model.

Haiku does not prescribe optimizers, checkpoint formats, or replication APIs. That is an advantage if a team already owns those pieces, but it is additional integration work if the team expects a full training or serving stack. Google DeepMind recommends Flax for new projects because of its broader features, documentation, and ecosystem. Haiku is in best-effort maintenance focused on fixes and compatibility, so retaining it makes more sense for existing code than choosing it in anticipation of new features.

Hardware & Deployment Guide

Install a JAX build appropriate to the target environment before running Haiku, then install the dm-haiku package from PyPI or from Git. GPU and TPU support comes from JAX, not the Haiku wheel. Model execution stays in the application process and does not require a hosted API. For deployment sizing, test representative dtypes, input shapes, and batch sizes, separating steady-state execution from first-call compilation. Training also needs memory for gradients and any optimizer state.

The release history is useful when pinning an environment: v0.0.15 enabled use without Flax on Python 3.13 and later; v0.0.16 fixed a no_flax shim error involving inspect.stack(). v0.0.17 exposed spmd_axis_name on hk.vmap, improved the slicing path for static_unroll's reverse-mode pass using jnp.unstack, and included JAX compatibility changes. Test the exact Python/JAX/Haiku combination the application will ship.

Execution boundary: hk.transform exposes pure init and apply functions for JAX transformations.
Parameter structure: hk.get_parameter initializes or retrieves named arrays in a mapping keyed by module and parameter name.
State threading: hk.transform_with_state separates trainable parameters from mutable state and returns updated state from apply.
Randomness: 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.
Parallel execution: Use JAX pmap on transformed functions; v0.0.17 exposes spmd_axis_name in hk.vmap.
Runtime ownership: Install the JAX backend separately; Haiku does not prescribe an optimizer, checkpoint format, or serving layer.
Best For

Maintaining existing Haiku models or porting Sonnet-style model code to a JAX stack that already handles training infrastructure and serving.

Skip If

You need a turnkey LLM server, or you are starting a new JAX project where broader framework features and ecosystem support matter more than Haiku compatibility.

Reviewed on 2026-12-02 · Grounded in GitHub README, root file tree & releasesMethodology

Quick Start & Installation

GPU
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)

Comparison vs. Top LLMs & Inference Alternatives

Full comparison →
RepositoryStars7d TrendStackLicenseCore Positioning
dm-haiku ★3.3k+1PythonApache-2.0Sonnet-style Python modules with pure JAX functions for model training and infer
keras64.5k+24PythonApache-2.0Multi-backend Python SDK for building, training, and running deep learning model
annotated_deep_learning_paper_implementations67.8k+43PythonMITAnnotated PyTorch references for understanding and adapting deep learning algori
jax36.7k+44PythonApache-2.0Python array SDK for composable autodiff, XLA compilation, and device sharding

AI Context Briefing (for Claude / Cursor / Windsurf)

Standardized architecture summary & quickstart commands ready to paste into coding agents.

Raw .md ↗
curl -sL https://repoforai.com/repo/google-deepmind/dm-haiku.md

Embed Star History Chart & Badges in README.md

Full-history Star History SVGs and velocity cards on GitHub Camo: drop-in replacement for OSSInsight and Star History widgets.

google-deepmind/dm-haiku Star History on RepoForAI

Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).

Frequently Asked Questions about dm-haiku

Where should I put the JIT boundary, and how do I handle model state?

Use hk.transform for models without mutable state and hk.transform_with_state for models with state such as batch-normalization statistics. Initialize with representative inputs, then pass the parameters, state if applicable, and any required RNG key to the resulting apply function. Apply jax.jit to that function rather than directly to model code that uses Haiku's implicit context.

Do I need a GPU, and how should I estimate VRAM and startup overhead?

No. GPU and TPU execution depend on your JAX installation. Size accelerator memory for the intended model, dtype, input shapes, and batch size; for training, budget separately for gradients and optimizer state. Profile the first compiled call separately from steady-state execution because JAX compilation can affect startup measurements.

Can I self-host Haiku in a commercial product?

Yes. Apache-2.0 permits commercial use and self-hosting. When redistributing the software, include the license, retain applicable notices, and identify modified files as required. Review the licenses of any bundled dependencies and model weights separately.

Should I choose Haiku or Flax for a new JAX project?

Flax is Google DeepMind's recommendation for new projects and has broader feature coverage and more ecosystem examples. Haiku remains a practical choice when you already maintain Haiku models or want to preserve a Sonnet-style module interface without taking on a rewrite.

Upstream README & Documentation

This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.

Maintaining google-deepmind/dm-haiku? Pin to Homepage + competitor /alternatives pages with a custom Cloud/Demo CTA.Feature google-deepmind/dm-haiku on Homepage & Alternatives ($19)
WEEKLY BREAKOUT DIGEST

Top 10 Breakout Open-Source AI Repos, Every Thursday

Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.

Zero spam · 1-click unsubscribe · Privacy Policy

Saved in your browser · Export Markdown RFC tables or jump into /vs compare