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

WindowPlan(index, start, end, cond_units)

One window's slice of a windowed generation.

WindowSchedule(total_units, window_units[, ...])

Window arithmetic for one request.

class mstar.engine.windowing.WindowPlan(index, start, end, cond_units)[source]#

Bases: object

One window’s slice of a windowed generation.

Unit indices are absolute within the full sequence. The leading cond_units of 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_end is 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).

Parameters:
property commit_end: int#
property commit_start: int#
cond_units: int#
end: int#
index: int#
start: int#
property units: int#
class mstar.engine.windowing.WindowSchedule(total_units, window_units, context_units=0, overlap_units=0)[source]#

Bases: object

Window arithmetic for one request.

total_units are generated in windows of window_units advancing by window_units - overlap_units; the final window may be short, and every unit is generated exactly once (commit spans partition [0, total)). context_units bounds the committed history retained in the cache after each commit; 0 means retain everything (no release).

Parameters:
  • total_units (int)

  • window_units (int)

  • context_units (int)

  • overlap_units (int)

released_end(index)[source]#

Units released from the front of the committed stream once window index has committed: everything older than context_units behind the commit frontier. 0 when context is unbounded.

Parameters:

index (int)

Return type:

int

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_tokens of protected head (the text prefix, say). None when 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:
  • tokens_per_unit (int)

  • prefix_tokens (int)

Return type:

RetentionPolicy | None

window(index)[source]#
Parameters:

index (int)

Return type:

WindowPlan

windows()[source]#