pub struct SelectiveSSM { /* private fields */ }alloc only.Expand description
Mamba-style selective state space model.
The selective mechanism computes input-dependent B, C, and Delta at each timestep, enabling the model to dynamically control what information is stored in and retrieved from the hidden state.
§Dimensions
d_in– input/output dimension (number of channels)n_state– hidden state dimension per channel (N)- Total hidden state size:
d_in * n_state
§Weight Shapes
| Weight | Shape | Purpose |
|---|---|---|
w_delta | d_in | Projects input to scalar step size |
w_b | N x d_in | Projects input to state-input coupling |
w_c | N x d_in | Projects input to state-output coupling |
d_skip | d_in | Skip connection weights |
log_a | N | Fixed state transition (always negative after exp) |
§Example
use irithyll_core::ssm::selective::SelectiveSSM;
use irithyll_core::ssm::SSMLayer;
let mut ssm = SelectiveSSM::new(4, 8, 42);
let output = ssm.forward(&[1.0, 2.0, 3.0, 4.0]);
assert_eq!(output.len(), 4);Implementations§
Source§impl SelectiveSSM
impl SelectiveSSM
Sourcepub fn new(d_in: usize, n_state: usize, seed: u64) -> Self
pub fn new(d_in: usize, n_state: usize, seed: u64) -> Self
Create a new selective SSM with random weight initialization.
Weights are initialized from a small normal distribution (scale 0.1)
using the provided seed for reproducibility. A is initialized via the
S4D-Inv (HiPPO-inspired) strategy: A_n = -(0.5 + n/N), which gives
a bounded spectrum of decay rates that remain meaningful at all state
sizes. Skip connections (D) are initialized to 1.0 to enable input
passthrough by default.
§Arguments
d_in– input/output dimension (number of channels)n_state– hidden state dimension per channel (N)seed– random seed for weight initialization
§Example
use irithyll_core::ssm::selective::SelectiveSSM;
let ssm = SelectiveSSM::new(4, 16, 42);Sourcepub fn reinitialize_channel(&mut self, d: usize, rng: &mut u64)
pub fn reinitialize_channel(&mut self, d: usize, rng: &mut u64)
Surgically reinitialize a single channel, preserving all other channels.
Resets channel d’s hidden state to zero across all state dimensions,
reinitializes its weight column in w_b and w_c, its w_delta entry,
and its skip connection d_skip to the default (1.0). All other channels
are left untouched.
§Arguments
d— channel index to reinitialize (must be <d_in)rng— mutable RNG state for generating fresh weights
§Panics
Panics if d >= d_in.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SelectiveSSM
impl RefUnwindSafe for SelectiveSSM
impl Send for SelectiveSSM
impl Sync for SelectiveSSM
impl Unpin for SelectiveSSM
impl UnsafeUnpin for SelectiveSSM
impl UnwindSafe for SelectiveSSM
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> 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