fn

load

object
load(f: str | bytes | io.IOBase, map_location: str | Callable[[str, str], str] | dict[str, str] | None = None, weights_only: bool = True)
source

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, or file-like
Source path or open binary file handle. Paths ending in .safetensors are delegated to load_safetensors.
map_locationstr, dict, callable, or None= None
Device remapping applied to every loaded tensor. A bare string 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.
weights_onlybool= True
If True (default), restrict deserialisation to a safe type whitelist. Set to False only for fully trusted checkpoints.

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
>>> sd = lucid.serialization.load("ckpt.lucid")