gensbi.utils#
Utility functions for GenSBI.
This module provides general utility functions including mathematical operations, model wrapping utilities, plotting functions, and model serialization.
Submodules#
Functions#
|
Load weights from a |
|
Save |
Package Contents#
- gensbi.utils.load_safetensors(model, path, *, strict=True)[source]#
Load weights from a
.safetensorsfile intomodelin place.The caller must have reconstructed
modelfrom itsParamsfirst; that model is the structural schema.- Parameters:
model (nnx.Module) – Target model, rebuilt from its
Params.path (str | os.PathLike) – Source
.safetensorsfile.strict (bool, optional) – If True (default), the file’s key set must equal the model’s and every shared key must match shape (
ValueErrorotherwise). If False, only the intersection is loaded; model leaves absent from the file keep their current values and file keys absent from the model are ignored.
- Returns:
model – The same
modelobject, updated in place with the loaded weights.- Return type:
nnx.Module
- gensbi.utils.save_safetensors(model, path, *, metadata=None, wrt=None)[source]#
Save
model’s weights to a single.safetensorsfile.- Parameters:
model (nnx.Module) – Any flax nnx module.
path (str | os.PathLike) – Destination
.safetensorsfile.metadata (mapping, optional) – Extra provenance, stringified and merged over (overriding) the defaults
format/version/framework/model_class.wrt (nnx filter, optional) – Restrict the saved variable collections (e.g.
nnx.Param). Default saves the full state.
- Return type:
None