pub trait MambaBlock: Module {
type Cache;
type Caches: CacheStack<Cache = Self::Cache>;
type SsdPath;
// Required methods
fn block_forward(
&self,
x: Tensor<3>,
cache: Option<Self::Cache>,
ssd_path: Self::SsdPath,
) -> (Tensor<3>, Self::Cache);
fn block_step(
&self,
x: Tensor<2>,
cache: Option<Self::Cache>,
) -> (Tensor<2>, Self::Cache);
fn zero_caches_3d(&self, x: &Tensor<3>, n_virtual: usize) -> Self::Caches;
fn zero_caches_2d(&self, x: &Tensor<2>, n_virtual: usize) -> Self::Caches;
// Provided methods
fn block_step_infinite(&self, x: Tensor<2>) -> Tensor<2> { ... }
fn block_step_n_approx(
&self,
x: Tensor<2>,
n: usize,
cache: Option<Self::Cache>,
) -> (Tensor<2>, Self::Cache) { ... }
}Required Associated Types§
Sourcetype Caches: CacheStack<Cache = Self::Cache>
type Caches: CacheStack<Cache = Self::Cache>
The per-network cache collection for this family.
Required Methods§
Sourcefn block_forward(
&self,
x: Tensor<3>,
cache: Option<Self::Cache>,
ssd_path: Self::SsdPath,
) -> (Tensor<3>, Self::Cache)
fn block_forward( &self, x: Tensor<3>, cache: Option<Self::Cache>, ssd_path: Self::SsdPath, ) -> (Tensor<3>, Self::Cache)
Full-sequence (chunked) pass — training / prefill.
Sourcefn block_step(
&self,
x: Tensor<2>,
cache: Option<Self::Cache>,
) -> (Tensor<2>, Self::Cache)
fn block_step( &self, x: Tensor<2>, cache: Option<Self::Cache>, ) -> (Tensor<2>, Self::Cache)
Single-token recurrent step — decoding.
Sourcefn zero_caches_3d(&self, x: &Tensor<3>, n_virtual: usize) -> Self::Caches
fn zero_caches_3d(&self, x: &Tensor<3>, n_virtual: usize) -> Self::Caches
Build n_virtual zero caches sized for a [batch, sequence, d_model] input.
Sourcefn zero_caches_2d(&self, x: &Tensor<2>, n_virtual: usize) -> Self::Caches
fn zero_caches_2d(&self, x: &Tensor<2>, n_virtual: usize) -> Self::Caches
Build n_virtual zero caches sized for a [batch, d_model] input.
Provided Methods§
Sourcefn block_step_infinite(&self, x: Tensor<2>) -> Tensor<2>
fn block_step_infinite(&self, x: Tensor<2>) -> Tensor<2>
Closed-form stationary fixed point: the limit of
Self::block_step outputs when the same constant token is stepped
forever. The limit forgets the starting state, so no cache is taken or
returned. The default implementation panics — only Mamba-3 currently
provides the closed form (see
Mamba3::step_infinite).
Sourcefn block_step_n_approx(
&self,
x: Tensor<2>,
n: usize,
cache: Option<Self::Cache>,
) -> (Tensor<2>, Self::Cache)
fn block_step_n_approx( &self, x: Tensor<2>, n: usize, cache: Option<Self::Cache>, ) -> (Tensor<2>, Self::Cache)
Closed-form jump equivalent to n consecutive Self::block_step
calls on the same constant token: the last step’s output and the final
cache, in O(1). The default implementation panics — only Mamba-3
currently provides it (see
Mamba3::step_n_approx).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".