Package-level declarations

Types

Link copied to clipboard

A ModelByteSource over an in-memory byte array (for example a header prefix or a test fixture).

Link copied to clipboard
class ChecksumMismatchException(val expectedSha256: String, val actualSha256: String) : ModelDownloadException

The SHA-256 of the downloaded file differs from the expected digest. The partial file has been deleted.

Link copied to clipboard
sealed interface DownloadEvent

Events emitted by ModelDownloader.download.

Link copied to clipboard
class DownloadHttpException(val statusCode: Int, val url: String) : ModelDownloadException

The server answered with an HTTP status that cannot be retried (for example 403 or 404).

Link copied to clipboard

The server answered in a way that breaks the HTTP Range protocol (for example a Content-Range at the wrong offset).

Link copied to clipboard
data class DownloadRequest(val url: String, val destination: String, val expectedSha256: String? = null, val expectedSizeBytes: Long? = null, val headers: Map<String, String> = emptyMap())

A model to download.

Link copied to clipboard
class DownloadSizeMismatchException(val expectedBytes: Long, val actualBytes: Long) : ModelDownloadException

The downloaded size differs from the expected size or from the size the server announced.

Link copied to clipboard

A network-level failure (connection reset, timeout, server error) that ModelDownloader retries, resuming from the bytes already written. HttpTransport implementations throw it for I/O errors.

Link copied to clipboard

Append-only output file.

Link copied to clipboard
enum class GgmlType : Enum<GgmlType>

ggml_type tensor element types with their block layout, as defined by the pinned ggml (ggml/include/ggml.h, block structs in ggml/src/ggml-common.h).

Link copied to clipboard

Parsed GGUF header: metadata key/values and tensor descriptors. Tensor data is never read.

Link copied to clipboard
data class GgufTensorInfo(val name: String, val dimensions: List<Long>, val typeId: Int, val offset: Long)

One tensor descriptor from the GGUF header.

Link copied to clipboard
sealed interface GgufValue

A GGUF metadata value.

Link copied to clipboard

GGUF metadata value types (gguf_type).

Link copied to clipboard
interface HttpResponse

A response passed to the HttpTransport.get handler.

Link copied to clipboard
interface HttpTransport

Minimal HTTP GET client used by ModelDownloader. Kept small so apps can plug in their own stack (OkHttp, Ktor, a corporate proxy) and tests can use a fake server.

Link copied to clipboard

ModelFileSystem backed by java.io / java.nio (Android API 26+ and JVM desktop).

Link copied to clipboard
data class LlmRamEstimateOptions(val contextLength: Long? = null, val batchSize: Long = 512, val kvCacheElementBytes: Double = 2.0, val flashAttention: Boolean = false)

Options for estimateLlmPeakRam.

Link copied to clipboard

Random-access, read-only bytes of a model file, used by the header parsers.

Link copied to clipboard
class ModelCache(val directory: String, fileSystem: ModelFileSystem = defaultModelFileSystem(), val maxBytes: Long = Long.MAX_VALUE, clock: () -> Long = { currentTimeMillis() })

On-disk model cache: a directory of downloaded model files with a size budget and least-recently-used eviction.

Link copied to clipboard
data class ModelCacheEntry(val fileName: String, val path: String, val sizeBytes: Long, val lastAccessMillis: Long, val pinned: Boolean)

One model file in a ModelCache.

Link copied to clipboard
class ModelDownloader(transport: HttpTransport = defaultHttpTransport(), fileSystem: ModelFileSystem = defaultModelFileSystem(), chunkSizeBytes: Long = DEFAULT_CHUNK_SIZE, maxRetries: Int = 5, initialRetryDelay: Duration = 500.milliseconds, ioDispatcher: CoroutineDispatcher = modelIoDispatcher(), readBufferSize: Int = 64 * 1024)

Resumable, chunked model downloader using HTTP Range requests.

Link copied to clipboard
open class ModelDownloadException(message: String, cause: Throwable? = null) : ModelManagerException

Base class of download failures raised by ModelDownloader.

Link copied to clipboard
interface ModelFileSystem

Minimal blocking file-system API used by the model manager. Paths are platform paths: / separated on every supported platform, and \ separated too on Windows. Call it from an I/O dispatcher.

Link copied to clipboard

A file-system operation of a ModelFileSystem failed.

Link copied to clipboard

Container format of a model file.

Link copied to clipboard

A model file is not a valid GGUF / Whisper ggml file, or its header is truncated or corrupt.

Link copied to clipboard
sealed class ModelHeaderInfo

Summary of a model file from its header, without loading weights.

Link copied to clipboard

Detects the model format from the magic number and parses the header.

Link copied to clipboard

A borrowed resident model. While at least one lease is open the model is never evicted. Closing a lease twice is a no-op.

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

Base class of every error raised by :kggml-model-manager.

Link copied to clipboard
data class PeakRamEstimate(val weightsBytes: Long, val kvCacheBytes: Long, val computeBytes: Long, val overheadBytes: Long)

Pre-load estimate of the peak memory an engine needs for a model, computed from the header only.

Link copied to clipboard
class ResidentModelCache(val budgetBytes: Long = Long.MAX_VALUE) : AutoCloseable

In-memory cache of loaded models (engines or other AutoCloseable resources) with a RAM budget and OS low-memory eviction.

Link copied to clipboard
class Sha256

Incremental SHA-256 (FIPS 180-4) in pure Kotlin. Not thread-safe.

Link copied to clipboard
class UrlConnectionHttpTransport(connectTimeoutMillis: Int, readTimeoutMillis: Int) : HttpTransport

HttpTransport on java.net.HttpURLConnection (no third-party HTTP stack). Blocking; ModelDownloader calls it on modelIoDispatcher. Redirects are followed within the same protocol.

Link copied to clipboard
data class WhisperHyperParameters(val vocabularySize: Int, val audioContext: Int, val audioState: Int, val audioHeads: Int, val audioLayers: Int, val textContext: Int, val textState: Int, val textHeads: Int, val textLayers: Int, val melBands: Int, val fileTypeId: Int, val quantizationVersion: Int)

Hyper-parameters of a whisper.cpp ggml model file (whisper_hparams, in file order).

Link copied to clipboard

Parsed whisper.cpp ggml model header (legacy, non-GGUF format): hyper-parameters, mel filter shape, vocabulary size and tensor descriptors. Tensor data is skipped, never read.

Link copied to clipboard
data class WhisperTensorInfo(val name: String, val dimensions: List<Long>, val typeId: Int, val dataOffset: Long)

One tensor descriptor of a Whisper ggml file.

Functions

Link copied to clipboard

The platform HttpTransport (HttpURLConnection on Android and JVM, NSURLSession on iOS).

The platform HttpTransport (HttpURLConnection on Android and JVM, NSURLSession on iOS).

Link copied to clipboard
Link copied to clipboard
fun estimateLlmPeakRam(header: GgufModelHeader, options: LlmRamEstimateOptions = LlmRamEstimateOptions()): PeakRamEstimate

Estimates the peak RAM needed to run the LLM described by header with llama.cpp.

Link copied to clipboard

Estimates the peak RAM needed to run the Whisper model described by header with whisper.cpp (one state).

Link copied to clipboard
expect fun modelIoDispatcher(): CoroutineDispatcher

The dispatcher blocking model-manager I/O runs on (Dispatchers.IO).

actual fun modelIoDispatcher(): CoroutineDispatcher

The dispatcher blocking model-manager I/O runs on (Dispatchers.IO).