torch.serialization.load_safetensors
function load_safetensors(f: string | File | Blob): Promise<{ tensors: Record<string, Tensor>; metadata?: Record<string, string> }>Load tensors from safetensors format with metadata.
Unlike load(), this function returns both tensors and any metadata
stored in the safetensors file.
Parameters
fstring | File | Blob- URL string, File, or Blob to load from
Returns
Promise<{ tensors: Record<string, Tensor>; metadata?: Record<string, string> }>– Promise resolving to object with tensors and optional metadataExamples
const { tensors, metadata } = await torch.load_safetensors('model.safetensors');
console.log('Model version:', metadata?.version);
model.load_state_dict(tensors);