GenerationConfig

data class GenerationConfig(val topK: Int? = null, val topP: Float? = null, val temperature: Float? = null, val maxTokens: Int? = null, val accelerator: Accelerator? = null)(source)

Optional load-time tuning for an on-device LLM. Every field is nullable — null means "leave the backend's own default alone". Backends apply what their engine exposes and ignore the rest:

  • MediaPipe (Gemma) — maxTokens + accelerator + the topK ceiling are load-time options; the topK/topP/temperature sampler is applied per inference session.

  • ML Kit GenAI (Gemini Nano) — topK/temperature/maxTokens are wired per-request (MlKitGenAiOnDeviceLlm's buildRequest); topP/accelerator have no equivalent on this API and are ignored.

  • Foundation Models (iOS) — FoundationModelsOnDeviceLlm's Swift bridge (ai/ios-bridge/) calls LanguageModelSession through a completion-handler shape that carries no topK/topP/temperature/maxTokens knobs, so every field is ignored here too. Kept uniform so a caller wires one config regardless of backend.

Constructors

Link copied to clipboard
constructor(topK: Int? = null, topP: Float? = null, temperature: Float? = null, maxTokens: Int? = null, accelerator: Accelerator? = null)

Properties

Link copied to clipboard
Link copied to clipboard

True when any sampler field is set — i.e. the backend must override its default decoding.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val topK: Int?
Link copied to clipboard
val topP: Float?