LocalModel class final
A language model on this device: its weights mapped, the native kernels and, where possible, the GPU ready. Conversations come from chat.
Conversations share the model's state: switching between two costs the prompt tokens they do not have in common, and only one may generate at a time.
- Available extensions
Properties
- backend → InferenceBackend
-
Where the model runs: InferenceBackend.gpu or InferenceBackend.cpu.
final
- contextLength → int
-
The most tokens a conversation can hold, prompt and replies together.
no setter
- controlVector → ControlVector?
-
Available on LocalModel, provided by the LocalModelControlVector extension
The control vector steering this model's replies, or null.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether close has run.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
chat(
{String? system, List< Map< ? tools, int maxNewTokens = 512}) → ChatSessionString, Object?> > -
A new conversation with
systemas its system prompt andtools(OpenAI-style function definitions) offered to the model. Replies stop aftermaxNewTokens. -
close(
) → Future< void> - Frees the model: its GPU memory and its mappings of the bundle's files. Its conversations stop working: a reply being generated fails at its next token, and ChatSession.send throws StateError. Closing twice does nothing.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setControlVector(
ControlVector? vector) → Future< void> -
Available on LocalModel, provided by the LocalModelControlVector extension
Steers every following reply of every conversation of this model withvector, or stops steering with null. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- isSupported → bool
-
Whether models can run here: the native kernels were built for this
platform and the CPU has what they need (the int8 dot product on
arm64, AVX2 on x86-64). An app should check it before offering
on-device models at all.
no setter
Static Methods
-
load(
String dir, {InferenceBackend backend = InferenceBackend.auto, int contextLength = 2048, int threads = 4}) → Future< LocalModel> -
Loads the model bundle in
dir:config.json,tokenizer.json,model.safetensorsand the quantized weights,lfm3-q4.cache(fromdianoia import-gguf) orlfm3-q8.cache(fromdianoia pack).