Flax NNX¶
tinax.nnx captures independent graph snapshots, restores them with explicit copy policy, and clones mutable variables while preserving graph aliases and concrete module types.
from tinax.nnx import clone_graph, restore_graph, snapshot_graph
snapshot = snapshot_graph(model)
independent_model = restore_graph(snapshot, copy=True)
clone = clone_graph(model)
snapshot_graph
¶
Capture independent variable state while preserving the module's internal graph aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
T
|
Flax NNX module to snapshot. |
required |
Returns:
| Type | Description |
|---|---|
GraphState[T]
|
A |
GraphState[T]
|
module's internal aliases preserved. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
restore_graph
¶
Instantiate a graph snapshot with explicit NNX graph-copy policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
GraphState[T]
|
Graph state previously produced by |
required |
copy
|
bool
|
If |
required |
Returns:
| Type | Description |
|---|---|
T
|
A reconstructed Flax NNX module of the snapshot's concrete type. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
clone_graph
¶
Clone mutable variables while preserving aliases and the concrete NNX module type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
T
|
Flax NNX module to clone. |
required |
Returns:
| Type | Description |
|---|---|
T
|
An independent clone of |
T
|
internal aliases. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |