Package-level declarations

Types

Link copied to clipboard

Maps between SafeTensors dtype strings and unified DataType enum.

Link copied to clipboard

SafeTensors data types as strings (as they appear in JSON).

Link copied to clipboard
data class SafeTensorsIndex(val metadata: SafeTensorsIndexMetadata, val weightMap: Map<String, String>)

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

Link copied to clipboard
data class SafeTensorsIndexMetadata(val totalSize: Long?, val additionalFields: Map<String, String> = emptyMap())

Represents the metadata from a SafeTensors index file.

Link copied to clipboard
class SafeTensorsIndexParseException(message: String, cause: Throwable? = null) : Exception

Exception thrown when parsing a SafeTensors index file fails.

Link copied to clipboard

Parser for model.safetensors.index.json files.

Link copied to clipboard
class SafeTensorsParametersLoader(sourceProvider: () -> RandomAccessSource, onProgress: (current: Long, total: Long, message: String?) -> Unit = { _, _, _ -> }) : ParametersLoader

ParametersLoader implementation for SafeTensors format using streaming.

Link copied to clipboard

Exceptions specific to sharded SafeTensors operations.

Link copied to clipboard

Writer for creating SafeTensors format files.

Link copied to clipboard
data class ShardedTensorInfo(base: StreamingSafeTensorInfo, val shardFilename: String, val shardIndex: Int, val totalShards: Int)

Tensor info with shard location information.

Link copied to clipboard
data class StreamingSafeTensorInfo(val name: String, val dtype: String, val dataType: DataType, val shape: List<Long>, val elementCount: Long, val dataOffsetStart: Long, val dataOffsetEnd: Long, val sizeInBytes: Int, val absoluteDataOffset: Long)

Tensor metadata for streaming access.

Link copied to clipboard

Streaming SafeTensors reader that parses metadata without loading tensor data.

Link copied to clipboard

Streaming reader for sharded/multi-file SafeTensors models.

Properties

Link copied to clipboard
const val HEADER_SIZE_BYTES: Int = 8

Size of the header length field in bytes

Link copied to clipboard
const val MAX_HEADER_SIZE: Int

Maximum allowed header size (100 MB) - safety limit

Link copied to clipboard
const val METADATA_KEY: String

Key for custom metadata in the JSON header

Functions

Link copied to clipboard

Android implementation of createRandomAccessSource.

Platform-specific factory for creating RandomAccessSource instances.

JS implementation of createRandomAccessSource.

JVM implementation of createRandomAccessSource.

Native implementation of createRandomAccessSource.

WASM/JS implementation of createRandomAccessSource.

WASM/WASI implementation of createRandomAccessSource.

Link copied to clipboard
actual fun readTextFile(path: String): String?

Android implementation: Read a text file.

expect fun readTextFile(path: String): String?

Read a text file. Platform-specific implementation.

actual fun readTextFile(path: String): String?

JS implementation: Read a text file. Note: Browser JS cannot read local files directly. For sharded models, the index should be fetched via HTTP.

actual fun readTextFile(path: String): String?

JVM implementation: Read a text file.

actual fun readTextFile(path: String): String?

Native implementation: Read a text file. Note: Full implementation requires platform-specific file I/O. For sharded models, the index file reading should be done through the existing RandomAccessSource mechanism.

actual fun readTextFile(path: String): String?

WASM JS implementation: Read a text file. Note: WASM/Browser cannot read local files directly.

actual fun readTextFile(path: String): String?

WASM WASI implementation: Read a text file. Note: WASM/WASI cannot read local files directly via this API.