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.json

  • Multiple 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()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The parsed index file

Link copied to clipboard

Whether all shards were loaded successfully

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val progress: Flow<LoadingProgress>
Link copied to clipboard
Link copied to clipboard

Total size from index metadata

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard

Load tensor data by name.

Load tensor data for a specific tensor.