mstar.engine.windowing#
Windowed (sliding-window) autoregressive generation support.
WindowSchedule is pure window arithmetic over abstract sequence units
(latent frames for video models), and turns its context horizon into the KV
cache’s RetentionPolicy for a stream (WindowSchedule.retention): the
immutable prefix protected, everything older than the horizon released as
each window commits. The model puts that policy on the KVStep of each
window commit and the pool applies it inside the commit, which is what makes
the release safe under the engine’s step pre-planning. Models own their walk,
conditioning math and step declarations; this module owns the schedule and
the retention arithmetic.
Ported from #198 (merceod) onto the resource-pool engine.
Classes
|
One window's slice of a windowed generation. |
|
Window arithmetic for one request. |
- class mstar.engine.windowing.WindowPlan(index, start, end, cond_units)[source]#
Bases:
objectOne window’s slice of a windowed generation.
Unit indices are absolute within the full sequence. The leading
cond_unitsof the window re-pin the tail of the previous window as clean conditioning (the chained-mode overlap; 0 when there is no overlap).commit_start:commit_endis the span this window newly generates — the span a kv-mode commit pass appends to the cache (overlap units were already committed by the previous window).
- class mstar.engine.windowing.WindowSchedule(total_units, window_units, context_units=0, overlap_units=0)[source]#
Bases:
objectWindow arithmetic for one request.
total_unitsare generated in windows ofwindow_unitsadvancing bywindow_units - overlap_units; the final window may be short, and every unit is generated exactly once (commit spans partition[0, total)).context_unitsbounds the committed history retained in the cache after each commit; 0 means retain everything (no release).- released_end(index)[source]#
Units released from the front of the committed stream once window
indexhas committed: everything older thancontext_unitsbehind the commit frontier. 0 when context is unbounded.
- retention(tokens_per_unit, prefix_tokens)[source]#
The KV retention a window commit declares for its stream: the context horizon in cache tokens behind
prefix_tokensof protected head (the text prefix, say).Nonewhen the schedule retains everything, since there is never a release. Releases are page-floored by the pool and the shortfall re-offered at the next commit, so the realized context tracks the nominal one within a page.- Parameters:
- Return type:
RetentionPolicy | None