SafetensorsFile
Models & Types · AiDotNet.Agentic.Models.Local
A parsed safetensors file: the tensor table of contents plus access to each tensor’s raw bytes and a
conversion to Double values. This is the format-level loading primitive; mapping the loaded
tensors onto a specific network’s layers is architecture-specific.
Implements: INamedTensorSource
For Beginners
The opened file. Ask it which tensors it has, get their shapes, and read any one as an array of numbers — the raw material for loading pretrained weights into a model.
How It Works
Supports the common float dtypes F64, F32, and F16 for value conversion; other dtypes
are still listed and their raw bytes are accessible. Values are read little-endian (the safetensors
convention).
The file may be backed by an in-memory byte array or by a seekable stream
(see Read). When stream-backed, tensor bytes are read on demand —
the stream must remain open for the lifetime of this instance, and concurrent reads are serialized
internally.
Properties
| Property | Summary |
|---|---|
IReadOnlyCollection<string> Names { get; } |
Gets the names of all tensors. |
IReadOnlyCollection<string> TensorNames { get; } |
|
IReadOnlyList<SafetensorsTensor> Tensors { get; } |
Gets the tensors in the file. |
Methods
| Method | Summary |
|---|---|
SafetensorsTensor Get(string name) |
Returns the descriptor for a tensor, or null when not present. |
byte[] GetRawBytes(string name) |
Copies a tensor’s raw bytes. |
double[] ReadAsDouble(string name) |
Reads a tensor’s values as Double (supports F64, F32, F16). |