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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.