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
impl KvShape
Sourcepub fn from_config(config: &ModelConfig, elem: KvElem, chunk: usize) -> Self
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.
Sourcepub 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
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.
Sourcepub fn sliding_layers(&self) -> usize
pub fn sliding_layers(&self) -> usize
How many layers slide, given the alternating pattern.
Sourcepub fn full_attention_layers(&self) -> usize
pub fn full_attention_layers(&self) -> usize
Layers that keep the full causal history.
Sourcepub fn per_token_kv_bytes(&self) -> u64
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.
Sourcepub fn marginal_per_token_bytes(&self) -> u64
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.
Sourcepub fn kv_bytes_for_tokens(&self, tokens: usize) -> u64
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.
Trait Implementations§
impl Copy for KvShape
impl Eq for KvShape
impl StructuralPartialEq for KvShape
Auto Trait Implementations§
impl Freeze for KvShape
impl RefUnwindSafe for KvShape
impl Send for KvShape
impl Sync for KvShape
impl Unpin for KvShape
impl UnsafeUnpin for KvShape
impl UnwindSafe for KvShape
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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