msgpack_load#
- class braintools.file.msgpack_load(filename, target=None, parallel=True, mismatch='error', max_size=None, verbose=False)[source]#
Load the checkpoint from the given path using the
msgpacklibrary.This function is rewritten from the Flax APIs (google/flax).
- Parameters:
filename (
str|PathLike) – checkpoint file to restore from.target (
Any|None) – the object to restore the state into. If None, the state is returned as a nested dict (with all dict keys as strings; see Notes).parallel (
bool) – whether to read large seekable checkpoints with multiple threads.mismatch (
Literal['error','warn','ignore']) – How to handle mismatches between target and state dict (dict keys, list/tuple length, namedtuple fields, unit, and array shape). ‘error’ (default): raise ValueError on mismatch ‘warn’: issue warning and keep the target’s value for the mismatch ‘ignore’: silently keep the target’s value for the mismatchmax_size (
int|None) – Maximum decoded checkpoint size in bytes (None= no limit).verbose (
bool) – Whether to print progress information (default: False).
- Returns:
out – If
targetis given, a structure isomorphic totargetwith the restored leaf data (Stateleaves are restored in place). Iftargetis None, the raw nested state dict read from the file.- Return type:
PyTree- Raises:
ValueError – If
filenamedoes not exist, or on a mismatch whenmismatch='error'.InvalidCheckpointPath – If the checkpoint data is corrupt or cannot be decoded.
Notes
Without a
target, dict keys come back as strings and dict subclasses (e.g.OrderedDict) become plain dicts, because keys are stringified on save. Provide atargetto recover the original key types and structure.