StreamingShardedSafeTensorsReader
Streaming reader for sharded/multi-file SafeTensors models.
Reads metadata from all shards without loading tensor data into memory. Emits progress events via progress flow during loading.
Sharded SafeTensors models consist of:
An index file:
model.safetensors.index.jsonMultiple shard files:
model-00001-of-00003.safetensors, etc.
Usage:
// Collect progress in a coroutine
val progressJob = scope.launch {
StreamingShardedSafeTensorsReader.progress.collect { progress ->
updateUI(progress)
}
}
// Open from index file
val reader = StreamingShardedSafeTensorsReader.openFromIndex("/path/to/model.safetensors.index.json")
// Use reader
println("Total tensors: ${reader.tensors.size}")
println("Shards loaded: ${reader.loadedShards.size}/${reader.index.shardCount}")
progressJob.cancel()Content copied to clipboard