pub enum KvBlockLayout {
UniversalTP,
UniversalPP,
OperationalHND,
OperationalNHD,
Custom([BlockDim; 4]),
Unknown,
}Expand description
Block layout defined by dimension ordering.
Describes how the 4 permutable dimensions (layer, outer, page, head) are ordered within a fully contiguous block. The head dimension (hd) is always innermost and implicit.
The order specifies outer-to-inner dimensions, with head_dim always last.
§Examples
UniversalTP:[nh, nl, no, nt, hd]- heads outermost for TP reshardingOperationalNHD:[nl, no, nt, nh, hd]- inner is[nt, nh, hd]
Variants§
UniversalTP
Universal format: [nh, nl, no, nt, hd]
Heads are outermost to enable tensor parallelism (TP) resharding. Cache saved from one TP configuration can be loaded into another by simply slicing the head dimension differently.
UniversalPP
Pipeline parallelism format: [nl, nh, no, nt, hd]
Layers are outermost for pipeline parallelism scenarios.
OperationalHND
Operational HND format: [nl, no, nh, nt, hd]
Inner tensor shape is [nh, nt, hd] (heads, tokens, head_dim).
OperationalNHD
Operational NHD format: [nl, no, nt, nh, hd]
Inner tensor shape is [nt, nh, hd] (tokens, heads, head_dim).
This is the most common format used by vLLM and other frameworks.
Custom([BlockDim; 4])
Custom ordering with explicit dimension list.
The array specifies dimensions from outermost to innermost, with head_dim always implicitly last.
Unknown
Unknown layout - fallback when format cannot be determined.
Operations involving Unknown layouts may fail or require explicit configuration.
Implementations§
Source§impl KvBlockLayout
impl KvBlockLayout
Sourcepub fn dim_order(&self) -> Option<[BlockDim; 4]>
pub fn dim_order(&self) -> Option<[BlockDim; 4]>
Get the dimension ordering as an array.
Returns the 4 dimensions from outermost to innermost. Head dimension (hd) is implicit as the innermost dimension.
§Returns
None for Unknown layout, Some([BlockDim; 4]) otherwise.
Sourcepub fn requires_transform(&self, other: &Self) -> bool
pub fn requires_transform(&self, other: &Self) -> bool
Check if two layouts require transformation (not just copy).
Returns true if the layouts have different dimension orderings,
meaning a transformation kernel is needed rather than a simple copy.
For Unknown→Unknown comparisons, returns false (compatible) but emits
a warning so these cases can be tracked and fixed.
Returns true if one is Unknown and the other is Known (conservative).
Sourcepub fn is_operational(&self) -> bool
pub fn is_operational(&self) -> bool
Check if this is an operational layout (NHD or HND).
Operational layouts are used for direct computation and have layer/outer as the outermost dimensions.
Sourcepub fn is_universal(&self) -> bool
pub fn is_universal(&self) -> bool
Check if this is a universal layout (TP or PP).
Universal layouts are optimized for storage and transfer, with different parallelism-friendly orderings.
Trait Implementations§
Source§impl Clone for KvBlockLayout
impl Clone for KvBlockLayout
Source§fn clone(&self) -> KvBlockLayout
fn clone(&self) -> KvBlockLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for KvBlockLayout
Source§impl Debug for KvBlockLayout
impl Debug for KvBlockLayout
Source§impl Default for KvBlockLayout
impl Default for KvBlockLayout
Source§fn default() -> KvBlockLayout
fn default() -> KvBlockLayout
Source§impl<'de> Deserialize<'de> for KvBlockLayout
impl<'de> Deserialize<'de> for KvBlockLayout
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>,
Source§impl Display for KvBlockLayout
impl Display for KvBlockLayout
impl Eq for KvBlockLayout
Source§impl Hash for KvBlockLayout
impl Hash for KvBlockLayout
Source§impl PartialEq for KvBlockLayout
impl PartialEq for KvBlockLayout
Source§impl Serialize for KvBlockLayout
impl Serialize for KvBlockLayout
impl StructuralPartialEq for KvBlockLayout
Auto Trait Implementations§
impl Freeze for KvBlockLayout
impl RefUnwindSafe for KvBlockLayout
impl Send for KvBlockLayout
impl Sync for KvBlockLayout
impl Unpin for KvBlockLayout
impl UnsafeUnpin for KvBlockLayout
impl UnwindSafe for KvBlockLayout
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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§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.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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request