module
context.state
Functions
M.save_state
Save the full context state to a file. The optional `tokens` cdata is embedded so a downstream `load_state` can recover the original prompt alongside the KV cache.
M.load_state
Restore the full context state from a file written by `save_state`. When `token_buf` is provided we also recover the embedded prompt token sequence ; the Lua-side `n_past` mirror is updated to match the restored fill position.
M.snapshot
Serialise the full state into a Lua string (zero file I/O). Returns nil if `llama_state_get_size` reports 0 bytes.
M.restore
Restore state from a `snapshot` blob. Does NOT update the Lua-side `n_past` mirror (the snapshot does not carry it) — call `Context:set_n_past(n)` after if you need to resume position-aware decoding.
M.seq_state_size
Byte size of the state for a single sequence — useful to pre-size caller-side buffers before `seq_snapshot`.
M.seq_save_state
Save a single sequence's KV state to a file.
M.seq_load_state
Load a sequence's KV state from a file into `dst_seq_id`.
M.seq_snapshot
Serialise a single sequence's KV state into a Lua string.
M.seq_restore
Restore a sequence's KV state from a `seq_snapshot` blob.