Module mtp_carry

Module mtp_carry 

Source
Expand description

2026-09-25: Carry the MTP drafter’s KV from one turn of a session to the next, so a warm turn adopts the previous turn’s drafter rows and appends only the new span, plus the SSM snapshot restore threshold.

On a warm turn the reused prefix is not recomputed, so the whole-prompt hidden capture does not cover the prompt and the drafter’s prompt prefill does not run (the model’s ensure_drafter_context). Rebuilding it instead was measured 2026-07-21 on GB10 at 1136 ms for 11,947 rows, about as long as the warm TTFT of 1134 ms.

Conventions:

  • Drafter row r holds a pair key k: (embed(t_{k+1}), hidden_k) at RoPE k + 1. Rows are compacted while RoPE stays in sequence space, so a skipped key leaves no hole.
  • mtp_prefill_hidden row i holds hidden_i, by absolute position.

Owner: model-layers (MTP drafter). Invariants:

Structs§

AppendPlan
CarriedDrafter
2026-09-25: The drafter KV of a finished turn, held in the model’s single carry slot for the next turn of the same session.
StoreRange
2026-09-25: The interval of mtp_prefill_hidden rows written, and the sequence ticket that wrote them. The buffer is model-level and indexed by absolute position, so the interval alone cannot say whose rows it holds.

Enums§

CarryOutcome
2026-09-25: Result of a carry attempt, for logging and tests.

Constants§

DEFAULT_MARCONI_MIN_TOKENS
2026-09-25: The default of --marconi-min-tokens and of the env fallback.

Functions§

carry_armed
2026-09-25: carry_armed_with against the live dispatch cap.
carry_armed_with
2026-09-25: Whether the carry is armed: configured on (cfg.carry) and MTP not in multi-sequence mode. It takes multi_seq as an argument so tests can set it; crate::speculative::mtp_max_seqs caches its env read.
hidden_row_offset
2026-09-25: Address of hidden row pos in a [capacity, hidden_size] BF16 store starting at base.
marconi_min_tokens
2026-09-25: Minimum snapshot depth, in matched tokens, for restoring an SSM snapshot; a shallower snapshot is not restored. 0 removes the floor.
merge_interval
2026-09-25: Merge a write of [start, start + count) into the interval [lo, hi). An overlapping or abutting write extends it; a disjoint write replaces it, because one interval cannot describe two runs and claiming the gap would mark unwritten rows valid.
mtp_carry_debug
2026-09-25: METRALE_MTP_CARRY_DEBUG=1 logs one line per carry store and per adopt decision.
mtp_carry_drafter_enabled
plan_append
2026-09-25: The warm-turn append after last_pair_key for a prompt of prompt_len tokens, reading hidden rows [hidden_lo, hidden_hi).
set_marconi_min_tokens
2026-09-25: Pin the restore threshold. The first write or read fixes it for the process; a later call changes nothing and returns false, so the caller can warn that its value was not applied.
stamped_merge
2026-09-25: Record a write of [start, start + count) by writer_gen. The same non-zero owner merges it with merge_interval; any other owner, or an unclaimed range, is replaced by the write. Merging across owners would leave another sequence’s rows inside the interval.