module-and-trees
Use Equinox modules, fields, PyTree filtering, and tree surgery correctly.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- module-and-trees
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use Equinox modules, fields, PyTree filtering, and tree surgery correctly.
- disable-model-invocation
- true
02 资源文件 2
- 参考文档references/module-and-trees.md6.1 KB
- 参考文档references/troubleshooting.md3.9 KB
03 SKILL.md 正文
Module and Trees
Use this sub-skill for Equinox’s core model-as-PyTree abstraction and the utilities that manipulate mixed PyTrees.
Use when
- The user is defining or debugging an
eqx.Modulesubclass. - A model has JAX arrays plus Python functions, strings, booleans, or other non-array leaves.
- The task mentions
eqx.field, converters, static fields,AbstractVar,AbstractClassVar, or__check_init__. - The task asks for model surgery with
tree_at, trainable/static partitioning,tree_equal,tree_check,apply_updates, orPartial. - A task needs to prepare a model PyTree for Optax, JAX transforms, or serialization.
Route elsewhere
- Use
../filtered-transformations/when the main issue isfilter_jit,filter_grad,filter_vmap,filter_pmap, AD, callbacks, or sharding. - Use
../nn-and-state/for built-inequinox.nnlayers, stateful modules,Shared, and inference-mode behavior. - Use
../diagnostics-and-serialization/for saving/loading leaves, runtime errors, pretty printing, progress meters, or debug tools. - Use
../internal-advanced/only for semi-publicequinox.internalhelpers.
Read first
references/module-and-trees.mdfor module patterns, API decisions, and model-surgery recipes.references/troubleshooting.mdfor commoneqx.Module, static-field, converter, and mixed-leaf failures.../../references/api-reference.mdfor a cross-skill symbol index.
Core workflow
- Identify the PyTree boundary. Decide which values are array leaves, non-array dynamic objects, or static metadata.
- Define an
eqx.Modulesubclass with annotated fields. Use a custom__init__only when construction logic needs it; otherwise rely on dataclass initialization. - Mark metadata such as strings, booleans, shapes, or callables with
eqx.field(static=True)when it should not be a PyTree leaf. - Use
eqx.field(converter=...)for safe field normalization at initialization time. - Use
__check_init__for invariant checks; do not mutate fields inside it. - Split trainable and static leaves with
eqx.partitionoreqx.filter, using predicates such aseqx.is_inexact_array, before optimizers or raw JAX transforms. - Use
eqx.tree_atfor out-of-place surgery such as replacing a final layer, changing an initializer result, or toggling nested leaves. - Validate structure with
eqx.tree_checkand compare expected outputs witheqx.tree_equal.
Minimal validation
From the generated skill root (set EQUINOX_SKILL_ROOT to its absolute path),
run the bundled smoke helper after installing Equinox:
cd "$EQUINOX_SKILL_ROOT" && python scripts/smoke.py --mode module
This checks module construction, static-field preservation, partition/combine,
tree_at, and tree_check using only the installed package and bundled runtime
files.
Scope note
This sub-skill distills Equinox's public module, filter, tree-manipulation, and
training-update behavior into the bundled references. Future agents should use
references/module-and-trees.md, references/troubleshooting.md, and
scripts/smoke.py; the source repository was construction evidence only, not a
runtime dependency.
Key cautions
- An Equinox module is a frozen dataclass and a PyTree. Treat object identity as secondary to tree value and structure.
- Plain
jax.jitandjax.gradare valid only when their dynamic arguments are all JAX-compatible leaves. Use filtered transforms for mixed modules. - Do not store bound methods on a module field; use a property or wrapper.
- Do not mark trainable arrays static just to silence JAX errors; filter the model instead.
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).