fn

save

None
save(obj: object, f: str | bytes | io.IOBase, pickle_protocol: int = 4)
source

Serialise obj to a Lucid-format checkpoint file.

Writes a pickle stream augmented with a custom persistent-id protocol that captures every embedded Tensor as a typed byte blob rather than a numpy array. The resulting .lucid file can be reloaded in environments without numpy installed.

Parameters

objobject
Object graph to serialise. dict / OrderedDict state dicts are the primary use case; arbitrary picklable objects are also supported.
fstr, bytes, or file-like
Destination path or open binary file handle.
pickle_protocolint= 4
Pickle protocol version forwarded to the underlying pickle.Pickler. Default 4.

Notes

State dicts produced by Module.state_dict() carry a hidden _metadata attribute storing version information per submodule. That attribute is detected, packed alongside obj in the container, and reattached on load.

Examples

>>> import lucid
>>> sd = {"w": lucid.randn(3, 3)}
>>> lucid.serialization.save(sd, "ckpt.lucid")