pub struct StochasticAttention {
pub dim_k: usize,
pub temperature: f64,
}Fields§
§dim_k: usize§temperature: f64Softmax temperature. Default: sqrt(dim_k) (Vaswani et al. 2017).
Implementations§
Source§impl StochasticAttention
impl StochasticAttention
pub fn new(dim_k: usize) -> Self
pub fn with_temperature(dim_k: usize, temperature: f64) -> Self
Sourcepub fn forward_softmax(
&self,
q: &[f64],
q_rows: usize,
q_cols: usize,
k: &[f64],
k_rows: usize,
k_cols: usize,
v: &[f64],
v_rows: usize,
v_cols: usize,
) -> Result<Vec<f64>, String>
pub fn forward_softmax( &self, q: &[f64], q_rows: usize, q_cols: usize, k: &[f64], k_rows: usize, k_cols: usize, v: &[f64], v_rows: usize, v_cols: usize, ) -> Result<Vec<f64>, String>
Softmax attention: Q·K^T / temperature → softmax → · V.
Numerically stable: subtract row max before exp().
Sourcepub fn forward_multihead_softmax(
&self,
q: &[f64],
q_rows: usize,
q_total_cols: usize,
k: &[f64],
k_rows: usize,
k_total_cols: usize,
v: &[f64],
v_rows: usize,
v_total_cols: usize,
n_heads: usize,
) -> Result<Vec<f64>, String>
pub fn forward_multihead_softmax( &self, q: &[f64], q_rows: usize, q_total_cols: usize, k: &[f64], k_rows: usize, k_total_cols: usize, v: &[f64], v_rows: usize, v_total_cols: usize, n_heads: usize, ) -> Result<Vec<f64>, String>
Multi-head softmax attention.
Sourcepub fn forward(
&self,
q: &[f64],
q_rows: usize,
q_cols: usize,
k: &[f64],
k_rows: usize,
k_cols: usize,
v: &[f64],
v_rows: usize,
v_cols: usize,
) -> Result<Vec<f64>, String>
pub fn forward( &self, q: &[f64], q_rows: usize, q_cols: usize, k: &[f64], k_rows: usize, k_cols: usize, v: &[f64], v_rows: usize, v_cols: usize, ) -> Result<Vec<f64>, String>
Rate-mode attention forward pass.
Shapes:
q:(q_rows, q_cols)k:(k_rows, k_cols)v:(v_rows, v_cols)
Auto Trait Implementations§
impl Freeze for StochasticAttention
impl RefUnwindSafe for StochasticAttention
impl Send for StochasticAttention
impl Sync for StochasticAttention
impl Unpin for StochasticAttention
impl UnsafeUnpin for StochasticAttention
impl UnwindSafe for StochasticAttention
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> 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 more