SafeTensorsIndex

data class SafeTensorsIndex(val metadata: SafeTensorsIndexMetadata, val weightMap: Map<String, String>)(source)

Represents a parsed model.safetensors.index.json file for sharded SafeTensors models.

The index file maps tensor names to their containing shard files:

{
"metadata": { "total_size": 14483464192 },
"weight_map": {
"model.embed_tokens.weight": "model-00001-of-00003.safetensors",
"model.layers.0.self_attn.q_proj.weight": "model-00001-of-00003.safetensors",
...
}
}

Constructors

Link copied to clipboard
constructor(metadata: SafeTensorsIndexMetadata, weightMap: Map<String, String>)

Properties

Link copied to clipboard

Index metadata (total_size, etc.)

Link copied to clipboard

Number of shards in this model.

Link copied to clipboard

Unique shard filenames derived from the weight map, sorted alphabetically.

Link copied to clipboard

Total number of tensors in this model.

Link copied to clipboard

Mapping from tensor name to shard filename

Functions

Link copied to clipboard
fun getShardForTensor(tensorName: String): String?

Get the shard filename containing a specific tensor.

Link copied to clipboard

Get tensor count per shard as a map.

Link copied to clipboard
fun getTensorsInShard(shardFilename: String): List<String>

Get all tensor names contained in a specific shard.