pub struct KvTensorShape {
pub attention_type: AttentionType,
pub num_layers: u32,
pub num_heads: u32,
pub num_kv_heads: u32,
pub head_dim: usize,
pub hidden_size: usize,
}Expand description
Describes the tensor shape of a KV cache for a specific model family.
This is the logical layout, not the physical memory layout.
Fields§
§attention_type: AttentionTypeThe attention mechanism type.
num_layers: u32Number of transformer layers.
num_heads: u32Number of attention heads.
num_kv_heads: u32Number of key/value heads (for GQA: smaller than num_heads).
head_dim: usizeDimension of each attention head (usually 64 or 128).
Hidden size / model dimension (d_model).
Implementations§
Source§impl KvTensorShape
impl KvTensorShape
Sourcepub fn kv_elements_per_token_per_layer(&self) -> usize
pub fn kv_elements_per_token_per_layer(&self) -> usize
Total KV elements per token (key + value) for one layer.
Sourcepub fn kv_bytes_per_token_per_layer(&self) -> usize
pub fn kv_bytes_per_token_per_layer(&self) -> usize
Total KV bytes per token (f32) for one layer.
Sourcepub fn total_kv_elements(&self, num_tokens: usize) -> usize
pub fn total_kv_elements(&self, num_tokens: usize) -> usize
Total KV elements for N tokens across all layers.
Sourcepub fn total_kv_bytes(&self, num_tokens: usize) -> usize
pub fn total_kv_bytes(&self, num_tokens: usize) -> usize
Total raw bytes for N tokens across all layers.
Sourcepub fn head_vector_dim(&self) -> usize
pub fn head_vector_dim(&self) -> usize
Dimension for a single key or value vector for one KV head.
Sourcepub fn kv_vectors_per_token_per_layer(&self) -> usize
pub fn kv_vectors_per_token_per_layer(&self) -> usize
Number of KV head vectors per token per layer.
Trait Implementations§
Source§impl Clone for KvTensorShape
impl Clone for KvTensorShape
Source§fn clone(&self) -> KvTensorShape
fn clone(&self) -> KvTensorShape
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KvTensorShape
impl Debug for KvTensorShape
Source§impl<'de> Deserialize<'de> for KvTensorShape
impl<'de> Deserialize<'de> for KvTensorShape
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for KvTensorShape
Source§impl PartialEq for KvTensorShape
impl PartialEq for KvTensorShape
Source§impl Serialize for KvTensorShape
impl Serialize for KvTensorShape
impl StructuralPartialEq for KvTensorShape
Auto Trait Implementations§
impl Freeze for KvTensorShape
impl RefUnwindSafe for KvTensorShape
impl Send for KvTensorShape
impl Sync for KvTensorShape
impl Unpin for KvTensorShape
impl UnsafeUnpin for KvTensorShape
impl UnwindSafe for KvTensorShape
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.