LlamaEngine

suspend fun LlamaEngine(modelPath: String, backendConfig: BackendConfig = BackendConfig.DEFAULT, contextConfig: LlamaContextConfig = LlamaContextConfig.DEFAULT, options: LlamaEngineOptions = LlamaEngineOptions()): LlamaEngine(source)

Loads a GGUF model with llama.cpp and returns a ready LlamaEngine.

The model and its KV-cache context are created on the new engine's own dedicated thread. backendConfig is enforced at load time:

BackendConfig.cpuThreads sets the generation and prompt threads (BackendConfig.AUTO_THREADS = performance cores), BackendConfig.useFlashAttention llama.cpp's flash attention (null: llama.cpp's automatic choice, LLAMA_FLASH_ATTN_TYPE_AUTO), and BackendConfig.useMmap whether the GGUF file is memory-mapped.

With LlamaEngineOptions.projectorPath a multimodal projector (libmtmd) is loaded as well, on the backend the model runs on, enabling image prompts (see LlamaEngine.generate with images). If the GPU refuses the projector weights, the load fails with com.donfuldauer.kggml.core.BackendUnavailableException, or, with LlamaEngineOptions.allowBackendFallback, the model and projector are loaded again on the next backend (the CPU).

Throws

if the file is missing or not a loadable GGUF model, or the projector is missing or does not match the model.

if the backend is unavailable and fallback is off.

if the weights, the projector weights or the KV cache cannot be allocated.

if the native libraries cannot be loaded.