Skip to main content

RopePlan

Struct RopePlan 

Source
pub struct RopePlan { /* private fields */ }
Expand description

Per-layer RoPE-BASE variation — the sibling axis to MaskPlan, and the one Gemma3 forced.

A family with two RoPE bases (Gemma3: rope_theta for global layers, rope_local_base_freq for sliding ones) produces different table bytes per variant, so — exactly like the mask — the Const must physically carry N of them and the layer loop must select.

This is the criterion that separates it from SmolLm3’s per-layer RoPE gating, which needs nothing: variation in DATA needs a variant axis; variation in WHETHER-TO-APPLY does not. A skipping layer simply does not consume the shared tables; a differently-based layer needs different bytes.

§Shape, and an honest asymmetry with MaskPlan

n_variants == 1 mints [seq, rope_width] — exactly today’s shape, with no slice and no reshape — so every single-base family’s graph is unchanged (pinned by the *_held_decode_graph_has_not_grown node-count tests).

n_variants > 1 mints [n, seq, rope_width] and hoists the per-variant views once before the layer loop. Unlike the mask — whose Const is already rank-4, so a width-1 slice is directly usable — RoPE tables are rank-2, so each variant costs a slice and a reshape. That cost is real and is named here rather than presented as symmetric.

Implementations§

Source§

impl RopePlan

Source

pub fn single(base: f64, n_layers: usize) -> Self

The single-base plan — what every family except Gemma3 uses.

Source

pub fn new(bases: Vec<f64>, per_layer: Vec<usize>) -> Result<Self>

Validated at construction, like MaskPlan::new: an out-of-range variant index would otherwise be a panic in the layer loop or, worse, a layer silently roped at the wrong frequency.

Source

pub fn per_layer_base( n_layers: usize, base_when_true: f64, base_when_false: f64, uses_first: impl Fn(usize) -> bool, ) -> Self

Two-base per-layer selection, TOTAL by construction — the sibling of MaskPlan::per_layer_window, and what Gemma3 uses: base_when_true is its rope_local_base_freq (sliding layers), base_when_false its rope_theta (full-causal layers).

Infallible for the same reason: a bool selector over exactly two defined bases cannot index out of range, so decode_rope_plan needs no Result and no expect.

⚠️ Collapses to a single base when the two are EQUAL — which is not a micro-optimisation but a correctness-of-measurement matter: Gemma3’s shipped fixtures set rope_local_base_freq == rope_theta, and a plan that still reported 2 variants there would make the graph look dual-base while every layer read identical bytes. Collapsing makes the degeneracy visible in n_variants(), which is what the non-vacuity assertions in Gemma3’s tests key on.

Source

pub fn n_variants(&self) -> usize

Source

pub fn n_layers(&self) -> usize

Source

pub fn variant_for_layer(&self, layer_idx: usize) -> usize

Source

pub fn mix_into(&self, h: &mut ShapeKeyHasher)

Mix the plan’s structural content into a decode shape key: the variant count and per-layer assignment wire the graph. The base values are excluded for the same reason rope_base always was — they are data, recomputed and rebound every token, so baking them would forfeit plan reuse across a change already handled correctly.

Trait Implementations§

Source§

impl Clone for RopePlan

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RopePlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RopePlan

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RopePlan

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more