ShardedSafetensorsSource
Models & Types · AiDotNet.ModelLoading.Pretrained
An INamedTensorSource over a Hugging Face model directory whose weights may be split
across several *.safetensors shards. Resolves the layout automatically:
a model.safetensors.index.json weight-map when present, otherwise a single
model.safetensors, otherwise every *.safetensors file in the directory.
Implements: IDisposable, INamedTensorSource
For Beginners
Big models are saved in several files. This class stitches those files back together and lets you ask for any weight by name without caring which file it lives in.
How It Works
Each shard is opened stream-backed (tensor bytes are read on demand, never copied wholesale), so an 8B-parameter multi-shard checkpoint is not materialized in memory. Dispose the source to close the underlying file handles.
Properties
| Property | Summary |
|---|---|
IReadOnlyCollection<string> TensorNames { get; } |
Methods
| Method | Summary |
|---|---|
ShardedSafetensorsSource Open(string directory) |
Opens the safetensors weights in directory as a single tensor source. |
double[] ReadAsDouble(string name) |
|
void Dispose() |