feat: DrawNNXModule wrt filter for the drawn state - #33
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DrawNNXModulegains a keyword-onlywrtargument (defaultnnx.Param, expressed asNoneresolved at draw time so the flax import stays lazy) selecting the state split out of each redrawn module.Motivation: a solver whose
x0was split with a filter narrower thannnx.Param— e.g.nnx.All(nnx.Param, nnx.Not(nnx.PathContains("g")))to freeze a trend Param into the nondiff state — previously could not useDrawNNXModule: redrawn states included the frozen Param and mismatchedx0's pytree structure. Passing the same filter aswrtmakes drawn states type-stable againstx0.wrtjoins the value-hash spec(module_cls, wrt, args, kwargs), so equal specs still share one compilation and differing filters key distinct ones. Not forwarded tomodule_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