stringjax_tools.pytrees.PytreePolicy#
- class PytreePolicy(static_keys=(), ignore_keys=(), ignore_defaults=None, static_types=(<class 'str'>, <class 'bool'>), validate_static=True)#
Bases:
objectShared pytree flattening policy for one package or model family.
A StringJAX package should define its domain-specific
static_keysand ignored-cache policy locally, then reuse one policy to register all classes that share the same state conventions.Warning
Ignored attributes are suitable for recomputable caches, scratch arrays and eager-only helpers, but not for semantic state such as user-supplied bounds, physical parameters or configuration values. Put such state in
static_keyswhen it is hashable and immutable, or keep it as a traced child when it is array-like. If an ignored cache may be read after reconstruction, declare anignore_defaultsentry so unflatten restores a safe value such asNoneor a freshdict.- __init__(static_keys=(), ignore_keys=(), ignore_defaults=None, static_types=(<class 'str'>, <class 'bool'>), validate_static=True)#
Methods
__init__([static_keys, ignore_keys, ...])flatten(obj)Flatten
objusing this policy.make_flatteners(myclass)Return class-specific
(flatten, unflatten)callables.register(myclass)Register
myclassas a JAX pytree node and return the class.unflatten(aux_data, children, myclass)Reconstruct
myclassfrom pytree data.Attributes
ignore_defaultsignore_keysstatic_keysstatic_typesvalidate_static- flatten(obj)#
Flatten
objusing this policy.- Return type:
tuple[tuple[Any,...],tuple[tuple[str,...],tuple[tuple[str,Any],...]]]
- make_flatteners(myclass)#
Return class-specific
(flatten, unflatten)callables.- Return type:
tuple[Callable[[Any],tuple[tuple[Any,...],tuple[tuple[str,...],tuple[tuple[str,Any],...]]]],Callable[[tuple[tuple[str,...],tuple[tuple[str,Any],...]],tuple[Any,...]],Any]]
- register(myclass)#
Register
myclassas a JAX pytree node and return the class.Returning the class lets this method be used either directly or as a decorator.
- Return type:
type
- unflatten(aux_data, children, myclass)#
Reconstruct
myclassfrom pytree data.- Return type:
Any