SafeTensorsWriter
Writer for creating SafeTensors format files.
SafeTensors format:
8 bytes: header size (little-endian u64)
N bytes: JSON header with tensor metadata
Remaining: raw tensor data at specified offsets
Usage:
SafeTensorsWriter.write(sink) {
metadata("format", "pt")
metadata("framework_version", "2.0.0")
tensor("layer1.weight", "F32", listOf(10, 20)) { floatArrayToBytes(weights) }
tensor("layer1.bias", "F32", listOf(20)) { floatArrayToBytes(bias) }
}Content copied to clipboard