fn
load
→objectload(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-likeSource path or open binary file handle. Paths ending in
.safetensors are delegated to load_safetensors.map_ locationstr, device, dict, callable, or None= NoneDevice 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= NoneModule used for unpickling metadata and objects. Only the standard
pickle module is supported.weights_ onlybool= TrueIf
True (default), restrict deserialisation to a safe type
whitelist. Set to False only for fully trusted checkpoints.mmapbool= NoneCompatibility 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
objectThe 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]