fn
save_safetensors
→Nonesave_safetensors(state_dict: dict[str, object], path: str, metadata: dict[str, str] | None = None)Save a flat state dict as a SafeTensors file.
SafeTensors is the recommended interchange format for sharing model weights: the file layout is a small JSON header followed by raw tensor bytes, so loading is fast, zero-copy where possible, and free of pickle's code-execution surface area. Use this whenever a checkpoint may be shared with untrusted parties.
Parameters
state_dictdict of str to TensorFlat mapping from parameter name to
Tensor. Nested
dicts or non-tensor values raise TypeError.pathstrDestination file path; use a
.safetensors suffix by
convention.metadatadict of str to str= NoneFree-form string metadata stored in the file header (model
version, training framework, etc.).
Notes
Every Lucid dtype is written as itself, bfloat16 included, so a
checkpoint round-trips bit for bit and other SafeTensors readers see
the dtype it was trained in. Zero-rank scalars are promoted to shape
(1,) on write and squeezed back to () on load via a private
metadata key.
Examples
>>> import lucid
>>> sd = {"w": lucid.randn(3, 3)}
>>> lucid.serialization.save_safetensors(sd, "/tmp/weights.safetensors")