save
→Nonesave(obj: object, f: str | bytes | os.PathLike[str] | os.PathLike[bytes] | io.IOBase, pickle_protocol: int = 4)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
objobjectdict / OrderedDict state
dicts are the primary use case; arbitrary picklable objects are
also supported.fstr, bytes, os.PathLike, or file-likepickle_protocolint= 4pickle.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.
Every tensor comes back with exactly the values it held. Tensors
saved together that share a storage — a tensor and its views, or
overlapping views — are written once and share it again after
load; a tensor that shares with nothing else saved is written
dense, so a view saved alone does not carry the rest of its base. On
Metal only the views taken through Lucid's view ops are known to
share; two tensors that merely read the same buffer are saved apart.
Examples
>>> import lucid
>>> sd = {"w": lucid.randn(3, 3)}
>>> lucid.serialization.save(sd, "/tmp/ckpt.lucid")