torch.serialization.deserialize_from_safetensors
function deserialize_from_safetensors(data: Uint8Array): Promise<{ tensors: Record<string, Tensor>; metadata?: Record<string, string> }>Deserialize safetensors format to tensors.
Loads tensors from a safetensors file, which is the recommended format for sharing models due to its safety and wide ecosystem support.
Parameters
dataUint8Array- Uint8Array containing the safetensors file data
Returns
Promise<{ tensors: Record<string, Tensor>; metadata?: Record<string, string> }>– Promise resolving to object with tensors and optional metadataExamples
// Load from fetch
const response = await fetch('model.safetensors');
const data = new Uint8Array(await response.arrayBuffer());
const { tensors, metadata } = await torch.deserialize_from_safetensors(data);
// Access tensors by name
const weight = tensors['model.layer.weight'];See Also
- serialize_to_safetensors for saving