fn

load_sharded

OrderedDict or object
load_sharded(path: str | bytes, map_location: str | Callable[[str, str], str] | dict[str, str] | None = None, weights_only: bool = True)
source

Load a sharded checkpoint directory written by save_sharded.

Reads index.json, then deserialises each shard with load and merges the results into a single OrderedDict preserving key order. The _metadata attribute, if stored in the index, is reattached to the merged dictionary.

Parameters

pathstr or bytes
Directory containing index.json and the per-shard files.
map_locationstr, dict, callable, or None= None
Device remapping forwarded to each per-shard load call.
weights_onlybool= True
If True (default), restrict deserialisation to a safe type whitelist.

Returns

OrderedDict or object

The merged state dict; for single-shard non-dict objects, the underlying object as written.

Notes

Shard order is taken from the index file — the function does not rely on filesystem listing order, so reproducibility is preserved across hosts.

Examples

>>> import lucid
>>> sd = lucid.serialization.load_sharded("ckpt_dir")