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.
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.
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.
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.
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.
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.
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.
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.