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.
Summary of Changes
This PR introduces significant refactoring to
flax.nnxto standardize variable metadata, improve Hijax support, and consolidate APIs. It also includes fixes for type hinting and documentation.Key Changes
Variable Metadata Standardization:
is_hijax→hijaxhas_ref→refis_mutable→mutableNew
var_defaultsAPI:nnx.var_defaults()to replacennx.use_hijax()andnnx.using_hijax().with nnx.var_defaults(hijax=True): ...@nnx.var_defaults(hijax=True)defaults = nnx.var_defaults()Unified Variable Conversion API:
nnx.vars_as()function:nnx.as_ref_vars(...)→nnx.vars_as(..., ref=True)nnx.as_immutable_vars(...)→nnx.vars_as(..., mutable=False)nnx.as_mutable_vars(...)→nnx.vars_as(..., mutable=True)nnx.as_hijax_vars(...)→nnx.vars_as(..., hijax=True)Fixes & Improvements
Refredefinition errors inflax/nnx/variablelib.py.@tp.overloadvalue shadowing forvar_defaults.propertyusage on non-method attributes.recursive_mapdocstring inflax/nnx/graph.py.docs_nnx/hijax/index.rst.Testing
integration_test.py,mutable_array_test.py,spmd_test.py,variable_test.py) to utilize the newvars_asandvar_defaultsAPIs.var_defaultscontext manager, including nesting behavior../tests/run_all_tests.sh --only-mypyand./tests/run_all_tests.sh --only-doctest.