Load a SafeTensors file into a flat state dict.
Reads the header and each tensor's bytes directly, builds a Lucid
Tensor of the stored dtype — bfloat16 included — optionally
relocates it to the requested device, and restores any zero-rank
scalars that were promoted to shape (1,) during
save_safetensors.
Parameters
pathstrPath to a
.safetensors file.devicestr= 'cpu'Target device for every loaded tensor:
"cpu" (default) or
"metal".Returns
dict of str to TensorFlat state dict suitable for model.load_state_dict().
Raises
ValueErrorIf the file is not a well-formed SafeTensors file, or stores a
dtype Lucid cannot represent (the 8-bit floats).
Notes
Unsigned integers have no Lucid dtype and widen losslessly: U8 to
int16, U16 to int32, U32 to int64 (U64 to int64, refused
past its range).
Examples
>>> import lucid
>>> sd = {"w": lucid.ones(3)}
>>> lucid.serialization.save_safetensors(sd, "/tmp/weights.safetensors")
>>> loaded = lucid.serialization.load_safetensors("/tmp/weights.safetensors")
>>> loaded["w"].tolist()
[1.0, 1.0, 1.0]