pub struct Mamba2Cache {
pub conv_bvk: Tensor<3>,
pub ssm_bhpr: Tensor<4>,
}Expand description
The mutable state carried between decoding steps for a single Mamba-2 layer.
Both tensors are updated in-place (via Burn’s functional clone) at every
call to Mamba2::step.
Fields§
§conv_bvk: Tensor<3>Convolution rolling window.
Stores the last conv_kernel pre-activation feature vectors fed into
the depthwise Conv1d. At each step, the oldest column is discarded and
the new token’s projection is appended (a left-shift followed by an
insert into the rightmost column), maintaining strict causality.
Shape: [batch, conv_dim, conv_kernel]
conv_dim = d_inner + 2 · ngroups · state_rankconv_kernelis typically 4
ssm_bhpr: Tensor<4>SSM hidden state hₜ.
This is the O(per_head_dim·state_rank) compressed summary of all tokens seen so far.
Updated via hₜ = Āₜ hₜ₋₁ + B̄ₜ xₜ at each decoding step.
The tensor is indexed as [batch, nheads, per_head_dim, state_rank]
(i.e. [batch, nheads, per_head_dim, state_rank] in the paper’s notation), which is the transpose
of the mathematical hₜ ∈ ℝ^{state_rank×per_head_dim} but equivalent in content.
Shape: [batch, nheads, per_head_dim, state_rank]
Implementations§
Source§impl Mamba2Cache
impl Mamba2Cache
Sourcepub fn sanity(&self)
pub fn sanity(&self)
Run the NaN/Inf guards on every cached tensor.
Trait Implementations§
Source§impl AutodiffModule for Mamba2Cache
impl AutodiffModule for Mamba2Cache
Source§impl Clone for Mamba2Cache
impl Clone for Mamba2Cache
Source§impl Debug for Mamba2Cache
impl Debug for Mamba2Cache
Source§impl Display for Mamba2Cache
impl Display for Mamba2Cache
Source§impl Module for Mamba2Cache
impl Module for Mamba2Cache
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
Source§fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
Source§fn collect_devices(&self, devices: Devices) -> Devices
fn collect_devices(&self, devices: Devices) -> Devices
Source§fn to_device(self, device: &Device) -> Self
fn to_device(self, device: &Device) -> Self
Source§fn fork(self, device: &Device) -> Self
fn fork(self, device: &Device) -> Self
§fn devices(&self) -> Vec<Device>
fn devices(&self) -> Vec<Device>
§fn train(self) -> Selfwhere
Self: AutodiffModule,
fn train(self) -> Selfwhere
Self: AutodiffModule,
§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
§fn into_record(self) -> ModuleRecordwhere
Self: Sized,
fn into_record(self) -> ModuleRecordwhere
Self: Sized,
ModuleRecord. Read more§fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
ModuleRecord to this module, returning the loaded
module. Read more§fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
ModuleRecord to this module, consuming and returning
it. Read more