Lfm3Model class final

Properties

config → Lfm3Config
final
controlVector → ControlVector?
The control vector steering the forward pass, or null.
no setter
executorStats → ExecutorStats
Timing of the shard calls, for profiling (empty on the GPU).
latefinal
gpu → GpuForward?
no setter
hashCode → int
The hash code for this object.
no setterinherited
history → List<int>
The tokens processed so far, by position. A -1 marks a position supplied through an embedding override; text prefix reuse must stop before it, including after saving/restoring state.
no setter
isClosed → bool
Whether close has run.
no setter
lastHiddenState → Float32List
Final-normalized state of the last forward/logitsOf computation. A borrowed view, valid until the next computation or close. TTS uses this rather than logits to condition its depth decoder.
no setter
length ↔ int
Number of tokens processed so far, i.e. the position of the next one.
getter/setter pair
logits → Float32List
The logits of the last token fed with logits. On the GPU this is a view of GPU memory: do not read it after close.
no setter
maxChunk → int
Largest number of tokens forward pushes through the layers at once.
final
maxSeq → int
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkpoint() → Future<void>
Saves the state at the current position, for prefill to return to. Costs a copy of the conv histories (640 KB for LFM3-1.7B); a no-op with worker isolates.
close() → Future<void>
Frees what the model holds: its GPU buffers, its worker isolates and its mappings of the weight cache and model.safetensors, in that order (the GPU wraps the cache). Afterwards the model throws StateError. Matrices quantized at load time, without a cache, stay allocated: only the command-line tool loads that way, and it exits.
forward(List<int> tokens, {void capture(int slot, int first, Float32List rows, int count)?, bool computeLogits = true, Map<int, Float32List> embeddingOverrides = const {}, Map<int, Object> embeddingKeys = const {}, void meanwhile()?}) → Future<void>
Feeds tokens at positions length, length + 1, ... and advances.
loadState(String path) → Future<bool>
Restores a state written by saveState for this model, weights and backend, and checkpoints it. Returns false, with the model reset, if path is missing, malformed or written for anything else.
logitsOf(Float32List residual) → Future<Float32List>
Applies the final norm and the tied LM head to one residual vector, leaving the result in logits.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prefill(List<int> ids, {Iterable<int> checkpoints = const [], Map<int, Float32List> embeddingOverrides = const {}, Map<int, Object> embeddingKeys = const {}}) → Future<int>
Feeds the prompt ids for a new reply, reusing what the model has already computed: the longest common prefix of ids and history if history does not go past it, else the state at the latest checkpoint inside it, else nothing. At least the last token is always fed, so logits are the prompt's. Saves checkpoints at checkpoints (positions in ids, such as the end of the system prompt) and at the end of the prompt. Returns how many tokens were reused.
reset() → Future<void>
Clears all state so the next call starts a new sequence.
restorePromptPrefix(List<int> ids, {Map<int, Float32List> embeddingOverrides = const {}, Map<int, Object> embeddingKeys = const {}}) → Future<int>
Keeps a matching prompt prefix or rewinds to a matching checkpoint for callers that feed the rest themselves. Leaves at least the last token to be fed. The embedding arguments follow prefill's key rules.
saveState(String path) → Future<void>
Writes the state at the current position to path: the tokens, the KV rows before it and the conv histories, about 45 KB per token for LFM3-1.7B (34 MB for a 761-token system prompt with tools). A later process on the same model, weights and backend can loadState it instead of computing those tokens. Written through a temporary file and a rename, so a reader never sees half a state.
setControlVector(ControlVector? vector) → void
Steers every following forward pass with vector (experimental), or stops steering with null. See control_vector.dart.
step(int token, {bool computeLogits = true}) → Future<void>
Feeds one token at position length and advances.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

load(String modelDir, {int maxSeq = 4096, int maxChunk = 64, int workers = 0, WeightFormat weights = WeightFormat.f32, List<String> keepF32 = const [], String? q8CachePath, bool gpu = false, String? gpuLib}) → Future<Lfm3Model>
Loads the model.

Constants

maxCheckpoints → const int
How many checkpoints checkpoint keeps: the earliest (usually the end of the system prompt) and the latest others.