SafetensorsLoader class

Utility class for reading and deserializing model weights from Hugging Face Safetensors files into GPUTensor instances. Parses the 8-byte header length, extracts the JSON metadata header, slices binary tensor chunks, handles matrix transpositions between coordinate standards, and pushes data directly into VRAM.

Constructors

SafetensorsLoader(String filePath)
Reads a Safetensors file synchronously from filePath, decodes the 8-byte header size prefix, parses the JSON metadata header, and determines bufferOffset.

Properties

bufferOffset ↔ int
Byte index where raw tensor binary data begins following the 8-byte length prefix and JSON header.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
Parsed JSON metadata header mapping tensor names to data types, shapes, and binary byte offsets.
getter/setter pair
rawBytes ↔ Uint8List
Raw byte buffer of the entire loaded Safetensors file.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

getAvailableTensors() → List<String>
Returns a list of all tensor keys available in the parsed header, excluding the __metadata__ block.
loadIntoTensors(Map<String, GPUTensor> modelTensors) → void
Extracts binary float values from the buffer for all matching keys in modelTensors, automatically transposes 2D matrices if row and column dimensions are inverted, and uploads the resulting values directly to VRAM via GPUTensor.pushData.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited