Skip to content
fn

load

→object
load(f: str | bytes | os.PathLike[str] | os.PathLike[bytes] | io.IOBase, map_location: str | Callable[[str, str], str] | dict[str, str] | object | None = None, pickle_module: object = None, weights_only: bool | None = True, mmap: bool | None = None, pickle_load_args: Any = {})

Load an object saved by save or save_safetensors.

By default uses a restricted unpickler that only permits a small whitelist of safe primitive types — sufficient for state dicts but not for arbitrary objects. Disable this with weights_only=False only for trusted files; arbitrary pickle deserialisation can execute code.

Parameters

fstr, bytes, os.PathLike, or file-like
Source path or open binary file handle. Paths ending in .safetensors are delegated to load_safetensors.
map_locationstr, device, dict, callable, or None= None
Device remapping applied to every loaded tensor. A bare string or device moves all tensors to that device; a dict maps source device names to targets; a callable receives (tensor, source_device) and returns the relocated tensor.
pickle_modulemodule= None
Module used for unpickling metadata and objects. Only the standard pickle module is supported.
weights_onlybool= True
If True (default), restrict deserialisation to a safe type whitelist. Set to False only for fully trusted checkpoints.
mmapbool= None
Compatibility flag with the reference signature. mmap=True is refused with NotImplementedError.
**pickle_load_argsAny= {}
Additional keyword arguments forwarded to pickle.Unpickler when weights_only=False.

Returns

object

The deserialised object, with _metadata reattached for state-dict round-trips.

Notes

Implements two formats: the current persistent-id format ("tensor_v3") plus a backward-compatible path for v1/v2 checkpoints that previously round-tripped through numpy.

Examples

>>> import lucid
>>> lucid.serialization.save({"w": lucid.ones(3)}, "/tmp/ckpt.lucid")
>>> sd = lucid.serialization.load("/tmp/ckpt.lucid")
>>> sd["w"].tolist()
[1.0, 1.0, 1.0]