Skip to content
Back to skills

Flax Interop

ASecurity

"Use Haiku's optional experimental Flax interop APIs to embed Haiku

  • 247 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
developmentpythonapi

Works with

  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill flax-interop --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Flax Interop?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Flax Interop
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-flax-interop/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-flax-interop)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: flax-interop
description: "Use Haiku's optional experimental Flax interop APIs to embed Haiku
  modules in Flax or lift Flax modules inside Haiku."
disable-model-invocation: true
metadata:
  disco-role: operating
license: Apache 2.0
---

# Flax Interop

Use this sub-skill when a task specifically mixes Haiku with Flax and needs `haiku.experimental.flax` behavior. Treat the APIs here as optional, experimental interop helpers: they are useful for preserving existing Haiku code inside a Flax program, or for calling a Flax `linen.Module` inside a Haiku transform.

## Route by direction

- **Haiku inside Flax:** use `hk.experimental.flax.Module(transformed)` for an `hk.transform`/`hk.transform_with_state` result, or `hk.experimental.flax.Module.create(hk.ModuleClass, *args, **kwargs)` for a Haiku module class.
- **Flax inside Haiku:** call `hk.experimental.flax.lift(flax_module, name="...")` inside an outer `hk.transform` or `hk.transform_with_state` function.
- **Variable inspection/conversion:** use `hk.experimental.flax.flatten_flax_to_haiku(collection)` on one Flax collection such as `variables["params"]`, not on the whole variables dictionary.
- **Generic Flax work:** route out of this sub-skill for ordinary Flax training loops, non-Haiku Flax APIs, or broad migration planning.

## Read or run these bundled files

- Read [references/api-reference.md](references/api-reference.md) for a compact API table, signature shapes, collection mapping rules, and state/RNG semantics.
- Read [references/flax-interop.md](references/flax-interop.md) for copyable recipes that choose between Haiku-in-Flax and Flax-in-Haiku workflows.
- Read [references/troubleshooting.md](references/troubleshooting.md) when optional `flax` imports fail, variable trees look surprising, state does not update, RNG streams fail, or versions are incompatible.
- Run [scripts/haiku_flax_smoke.py](scripts/haiku_flax_smoke.py) to verify the optional Flax dependency and a `Module.create(hk.Linear, ...)` init/apply smoke path on synthetic data.

## Minimal working checks

1. Confirm the dependency path first: `python scripts/haiku_flax_smoke.py --mode module-create`.
2. For Haiku-in-Flax, inspect `variables.keys()` after `mod.init(...)`; expect Flax collections such as `"params"` and, for stateful Haiku, `"state"`.
3. For Flax-in-Haiku, inspect the outer Haiku `params` and `state` returned by `init`; lifted Flax params appear under the explicit `name`, and non-param Flax collections become Haiku state prefixes.
4. If exact initialized values differ between a direct Haiku init path and a Flax-wrapped init path, treat that as expected RNG-splitting behavior unless the same variables are being shared explicitly.

Files in this skill

  • SKILL.md2.7 KB
  • references/api-reference.md5.8 KB
  • references/flax-interop.md6.3 KB
  • references/troubleshooting.md6.3 KB
  • scripts/haiku_flax_smoke.py4.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.