pub struct MaskPlan { /* private fields */ }Expand description
Per-layer attention-mask variation — the axis GAP-029 measured across increment 3’s families and the earlier six-axis check could not see, every one of its axes being model-scalar.
Note the axis is named for the behaviour that varies, not the first
mechanism found: three families vary by sliding window, SmolLm3 varies by
skipping RoPE entirely, and a checklist keyed on sliding_window would have
cleared SmolLm3 outright.
§Shape in the graph
The mask Const is [n_variants, 1, seq, max_seq_len]; the build path hoists
n_variants width-1 slices once, before the layer loop, and layer i
takes variant_for_layer(i). DecodeTokenData, DecodeSession and the
rebind driver are untouched — still one mask Arc, one mask_node.
n_variants == 1 mints [1, 1, seq, max_seq_len] and emits no slice node
at all, so a uniform family’s graph is byte-identical to the pre-GAP-029
one. That is asserted, not claimed: see mask_variants_are_byte_identical_ to_the_dense_builder_when_uniform.
Implementations§
Source§impl MaskPlan
impl MaskPlan
Sourcepub fn dense(n_layers: usize) -> Self
pub fn dense(n_layers: usize) -> Self
The uniform dense plan — every layer attends causally to the whole
prefix. What LlamaModel and every other non-varying family use, and
byte-identical to the pre-GAP-029 single-mask decode path.
Sourcepub fn new(windows: Vec<Option<usize>>, per_layer: Vec<usize>) -> Result<Self>
pub fn new(windows: Vec<Option<usize>>, per_layer: Vec<usize>) -> Result<Self>
Validated at construction, per the build-time-validation rule: an out-of-range variant index would otherwise surface as a panic deep in the layer loop, or — worse — as a silently mis-masked layer.
Sourcepub fn split_window(n_layers: usize, split: usize, window: usize) -> Self
pub fn split_window(n_layers: usize, split: usize, window: usize) -> Self
The layer_idx < split plan: the first split layers attend
through a window, the rest densely. This is exactly the predicate
Qwen2, Qwen3 and Qwen3Moe share (use_sliding_window && layer_idx < max_window_layers), so all three express their variation by calling
this rather than hand-rolling a variant table.
Total by construction — no Result, no panic. Both degenerate
splits collapse to a single variant, so a model that is entirely dense
or entirely windowed emits no slice node and pays nothing:
split == 0 is Self::dense, split >= n_layers is one windowed
variant.
Sourcepub fn per_layer_window(
n_layers: usize,
window: usize,
uses_window: impl Fn(usize) -> bool,
) -> Self
pub fn per_layer_window( n_layers: usize, window: usize, uses_window: impl Fn(usize) -> bool, ) -> Self
Arbitrary per-layer window selection, TOTAL by construction.
Self::split_window covers the prefix predicate Qwen2/Qwen3/Qwen3Moe
share. Gemma3’s is modular ((i + 1) % sliding_window_pattern > 0),
so it needs a free selector — and it cannot use Self::new, because
decode_mask_plan is infallible and expect-ing a Result on a
production path is exactly the never-panic violation this project bans.
A closure returning bool over exactly two defined variants cannot
produce an out-of-range index, so this needs no Result at all.
Collapses to a single variant when the selector is constant, so a config that happens to window every layer (or none) still emits no slice.
pub fn n_variants(&self) -> usize
pub fn n_layers(&self) -> usize
pub fn variant_for_layer(&self, layer_idx: usize) -> usize
Sourcepub fn window_for_layer(&self, layer_idx: usize) -> Option<usize>
pub fn window_for_layer(&self, layer_idx: usize) -> Option<usize>
This layer’s window width, or None if it attends densely.
The single source shared with the mask bytes — the CUDA flash arm’s
window_size_* and the mask Const come from the same plan entry, so
they cannot disagree. A family deriving the window separately for the arm
would be free to drift from the mask it actually applies, and “arm says
dense, mask says windowed” is precisely the silent defect GAP-194 was
filed about.
Sourcepub fn mix_into(&self, h: &mut ShapeKeyHasher)
pub fn mix_into(&self, h: &mut ShapeKeyHasher)
Mix the plan’s structural content into a decode shape key.
The variant count and the per-layer assignment change the graph’s shape
and wiring, so a session built under one plan must not be reused under
another. The window widths are deliberately excluded: they are data,
rebound per token like the RoPE tables, and baking them would forfeit
plan reuse across a change that is already handled correctly — the same
argument decode_shape_key’s own doc makes for rope_base.
Trait Implementations§
impl Eq for MaskPlan
impl StructuralPartialEq for MaskPlan
Auto Trait Implementations§
impl Freeze for MaskPlan
impl RefUnwindSafe for MaskPlan
impl Send for MaskPlan
impl Sync for MaskPlan
impl Unpin for MaskPlan
impl UnsafeUnpin for MaskPlan
impl UnwindSafe for MaskPlan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more