Skip to main content

KvShape

Struct KvShape 

Source
pub struct KvShape {
    pub n_layers: usize,
    pub layout: KvLayout,
    pub elem: KvElem,
    pub sliding: Option<SlidingWindow>,
}
Expand description

The KV shape of a whole model: enough to price any context length.

Fields§

§n_layers: usize§layout: KvLayout§elem: KvElem§sliding: Option<SlidingWindow>

None = every layer keeps the full causal history.

Implementations§

Source§

impl KvShape

Source

pub fn from_config(config: &ModelConfig, elem: KvElem, chunk: usize) -> Self

Reads the shape off a config. chunk is the prefill chunk size the run will use (FERROX_CHUNKED_PREFILL, or 1 when prefill is token-at-a-time); it only ever matters for sliding layers.

Always produces a KvLayout::Gqa layout, because ModelConfig describes the generic GQA decoder – the MLA stacks carry their own hyperparameters (Deepseek2Hparams, MlaConfig) and should build their shape with KvShape::mla_expanded.

Source

pub fn mla_expanded( n_layers: usize, n_heads: usize, qk_nope_head_dim: usize, qk_rope_head_dim: usize, v_head_dim: usize, elem: KvElem, ) -> Self

The shape a ferrox MLA decoder really allocates – see KvLayout::MlaExpanded.

Source

pub fn sliding_layers(&self) -> usize

How many layers slide, given the alternating pattern.

Source

pub fn full_attention_layers(&self) -> usize

Layers that keep the full causal history.

Source

pub fn per_token_kv_bytes(&self) -> u64

The plan’s headline number: bytes one token costs across every layer, ignoring any sliding-window cap. Exact for f32/f16; for the block-quantized wires it is exact whenever a layer’s per-token element count is a multiple of the 32-element block (true for every real head-dim/kv-head combination), and rounds up otherwise.

Source

pub fn marginal_per_token_bytes(&self) -> u64

Bytes each additional context token costs once the sliding layers have saturated: only the full-attention layers keep growing. This is the divisor KvBudget::max_context uses, and it is 0 for a model whose every layer slides – such a model’s KV is bounded no matter how long the context is.

Source

pub fn kv_bytes_for_tokens(&self, tokens: usize) -> u64

Bytes one request’s KV costs at tokens of context, applying the sliding-window cap per layer class.

Source

pub fn describe(&self) -> String

The sentence a user should be able to read and reproduce with a calculator.

Trait Implementations§

Source§

impl Clone for KvShape

Source§

fn clone(&self) -> KvShape

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 Copy for KvShape

Source§

impl Debug for KvShape

Source§

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

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

impl Eq for KvShape

Source§

impl PartialEq for KvShape

Source§

fn eq(&self, other: &KvShape) -> 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 KvShape

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.