Skip to content

feat: DrawNNXModule wrt filter for the drawn state - #33

Merged
jlperla merged 1 commit into
mainfrom
feat/draw-nnx-module-wrt
Aug 27, 2026
Merged

feat: DrawNNXModule wrt filter for the drawn state#33
jlperla merged 1 commit into
mainfrom
feat/draw-nnx-module-wrt

Conversation

@jlperla

@jlperla jlperla commented Aug 27, 2026

Copy link
Copy Markdown
Member

DrawNNXModule gains a keyword-only wrt argument (default nnx.Param, expressed as None resolved at draw time so the flax import stays lazy) selecting the state split out of each redrawn module.

Motivation: a solver whose x0 was split with a filter narrower than nnx.Param — e.g. nnx.All(nnx.Param, nnx.Not(nnx.PathContains("g"))) to freeze a trend Param into the nondiff state — previously could not use DrawNNXModule: redrawn states included the frozen Param and mismatched x0's pytree structure. Passing the same filter as wrt makes drawn states type-stable against x0.

wrt joins the value-hash spec (module_cls, wrt, args, kwargs), so equal specs still share one compilation and differing filters key distinct ones. Not forwarded to module_cls.

Includes a unit test (test_draw_nnx_module_wrt_filter) covering the drawn-structure contract and the hash/eq semantics, and bumps the version to 2.9.0. Full suite: 217 passed, 12 skipped locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JqaCzfRpewquuigfnNkP4n

DrawNNXModule(module_cls, *args, wrt=None, **kwargs): wrt is a
keyword-only nnx filter selecting the state drawn from each redrawn
module, defaulting to nnx.Param (None resolves at draw time so the flax
import stays lazy). Pass the same filter used to split the solver's x0
when some Params are frozen into the nondiff state -- e.g.
nnx.All(nnx.Param, nnx.Not(nnx.PathContains("g"))) -- so drawn states
match x0's pytree structure. wrt joins the value-hash spec alongside
(module_cls, args, kwargs). Version 2.9.0.

Co-Authored-By: Mecha Perla (Claude) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JqaCzfRpewquuigfnNkP4n
@jlperla
jlperla merged commit 2ec56b9 into main Aug 27, 2026
2 checks passed
@jlperla
jlperla deleted the feat/draw-nnx-module-wrt branch August 27, 2026 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant