brainstate.interop module#
Convert standard-layer models between brainstate.nn and flax.nnx / flax.linen /
equinox.
The public functions construct an architecturally-equivalent model in the target framework and
transfer weights, guaranteeing numerical output-equivalence for everything that converts (single
layers and Sequential stacks of registered layers). Unsupported layers / structures raise
informative errors rather than producing a silently-wrong model.
See also
register_layer_mappingadd a conversion for a custom layer type.
supported_layerslist the layers convertible for each framework.
Interoperability utilities for converting models between brainstate.nn and other
JAX-based frameworks (Flax NNX, Flax Linen, and Equinox). The module also exposes the
layer-mapping registry used to extend conversion support and a hierarchy of errors
raised during conversion.
Conversion Functions#
Convert models in either direction between brainstate.nn and a target framework.
The from_* functions import an external model into brainstate.nn; the to_*
functions export a brainstate.nn model to the target framework.
|
Convert a |
|
Convert a |
|
Convert a |
|
Convert a |
|
Convert an |
|
Convert a |
Layer Mapping Registry#
Register and inspect the layer mappings that drive conversion. register_layer_mapping
adds support for a new layer type, supported_layers lists the currently supported
layers, and LayerMapping describes an individual mapping entry.
A bidirectional conversion mapping for one layer type. |
Register (or override) a |
|
List the brainstate layer types with registered conversions. |
Errors#
Exceptions raised when a conversion cannot be completed, e.g. a missing optional dependency, an unmapped or unsupported layer, an unsupported model structure, or a missing input shape.
Base class for all |
|
Raised when an optional framework ( |
|
Raised when no conversion mapping is registered for a leaf layer type. |
|
Raised for a known layer type that is deliberately unsupported in this version. |
|
Raised when a container's forward logic cannot be reconstructed. |
|
Raised when importing a spatial layer ( |
|
Raised when a weight transfer fails (shape/dtype/unit mismatch). |