dm-haiku
Use DeepMind dm-haiku as a JAX neural-network library for transforms, modules, state/RNG, layers, advanced JAX interop, and optional Flax interop.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- dm-haiku
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use DeepMind dm-haiku as a JAX neural-network library for transforms, modules, state/RNG, layers, advanced JAX interop, and optional Flax interop.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/repo-provenance.md2.5 KB
- 参考文档references/repo-routing-metadata.json341 B
- 参考文档references/troubleshooting.md4.0 KB
- 脚本scripts/check_haiku_env.py4.2 KB
03 SKILL.md 正文
dm-haiku
Use this repo skill when a task involves the dm-haiku Python package, usually imported as import haiku as hk, or when a JAX neural-network workflow needs Haiku's object-oriented modules plus pure init/apply functions.
Haiku is in maintenance mode: it remains useful for existing Haiku code and research checkouts, but new greenfield projects may be better served by Flax. Do not present Haiku as a full training framework: it provides module, parameter, state, RNG, transform, and model-building utilities that compose with JAX, optimizers, datasets, checkpointing, and accelerators from other libraries.
Quick install and smoke check
-
Install a JAX build that matches the target machine first. CPU JAX is enough for API work; GPU/TPU execution requires the appropriate JAX backend package for that machine.
-
Install Haiku:
python -m pip install -U dm-haiku -
For optional Flax interop, also install Flax:
python -m pip install -U flax -
Run the bundled checker from this skill directory if import or backend state is uncertain:
python scripts/check_haiku_env.py python scripts/check_haiku_env.py --require-flax
The checker imports haiku, jax, and optionally flax, runs a tiny hk.Linear transform, reports JAX backend/devices, and does not download data or train.
Route by task
- Use sub-skills/core-transforms/SKILL.md when choosing
hk.transform,hk.transform_with_state,hk.without_apply_rng,hk.multi_transform, or diagnosinginit/applysignatures. - Use sub-skills/params-state-rng/SKILL.md when writing
hk.Modulesubclasses, directhk.get_parameter/hk.get_state/hk.set_statecode, RNG flows, module naming, or creators/getters/interceptors. - Use sub-skills/modules-and-networks/SKILL.md when building or debugging Haiku layers, normalization, attention, recurrent cores,
hk.netsmodels, or no-download model smoke tests. - Use sub-skills/jax-interop-and-advanced/SKILL.md when Haiku code interacts with
vmap,scan,grad, control flow, nested transforms/lifting, parameter tree utilities, mixed precision, summaries, or visualization. - Use sub-skills/flax-interop/SKILL.md when mixing Haiku with Flax through
hk.experimental.flaxAPIs.
Root references and helper
- Read references/troubleshooting.md for install/import, JAX backend, optional dependency, version, example dependency, and maintenance-mode issues that cut across sub-skills.
- Read references/repo-provenance.md before deciding whether this skill is current for a checkout or should be refreshed.
references/repo-routing-metadata.jsoncontains structured router metadata for managed repo-skill import.- Run scripts/check_haiku_env.py as the shared environment/import checker before deeper sub-skill smoke scripts.
Operating pattern
For most Haiku tasks, work in this order:
- Pick the transform boundary first: stateless
hk.transform, statefulhk.transform_with_state, or multi-transform. Seecore-transforms. - Build module code inside the transformed function. Keep
hk.Moduleconstruction,hk.get_parameter,hk.get_state, andhk.next_rng_keyinside Haiku contexts. Seeparams-state-rng. - Choose modules/networks and validate with synthetic arrays before adding optimizers, datasets, large examples, or distributed JAX. See
modules-and-networks. - If raw JAX transforms appear inside a Haiku-transformed function, switch to Haiku wrappers or lift nested transforms deliberately. See
jax-interop-and-advanced. - Treat Flax interop as optional and explicit. Verify the
flaxdependency and variable collection mapping before mixing codebases. Seeflax-interop.
Common boundaries
- Haiku does not own optimizers, checkpoint formats, dataset loaders, training launchers, or accelerator installation. Bring those from JAX/Optax/Orbax/TFDS or the user's own stack.
- Full public examples often require external datasets, TensorFlow/TFDS, Optax, RL libraries, or long training. This skill distills their Haiku model patterns into bundled no-download scripts and references; do not require the original checkout for runtime use.
- GPU warnings from JAX usually mean the installed JAX backend is CPU-only. That does not invalidate Haiku API work, but it does mean accelerator performance has not been verified.
- If a task is about editing the
dm-haikurepository source itself rather than using Haiku as a package, first decide whether a maintainer/repository-development skill is more appropriate; this skill is optimized for package usage.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).