pub struct AttentionMask {
pub indices: Vec<(usize, usize)>,
pub shape: (usize, usize),
/* private fields */
}Expand description
Sparse mask for attention patterns
Fields§
§indices: Vec<(usize, usize)>Sparse indices as (row, col) pairs
shape: (usize, usize)Shape of the full attention matrix
Implementations§
Source§impl AttentionMask
impl AttentionMask
Sourcepub fn new(indices: Vec<(usize, usize)>, shape: (usize, usize)) -> Self
pub fn new(indices: Vec<(usize, usize)>, shape: (usize, usize)) -> Self
Create a new sparse mask from indices
Sourcepub fn is_attended(&self, row: usize, col: usize) -> bool
pub fn is_attended(&self, row: usize, col: usize) -> bool
Check if position is masked (should attend)
Sourcepub fn apply(&self, scores: &mut [f32], seq_len: usize)
pub fn apply(&self, scores: &mut [f32], seq_len: usize)
Apply mask to attention scores (set non-attended to -inf)
Sourcepub fn local_window(n: usize, window_size: usize) -> Self
pub fn local_window(n: usize, window_size: usize) -> Self
Create a local window mask
Trait Implementations§
Source§impl Clone for AttentionMask
impl Clone for AttentionMask
Source§fn clone(&self) -> AttentionMask
fn clone(&self) -> AttentionMask
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AttentionMask
impl RefUnwindSafe for AttentionMask
impl Send for AttentionMask
impl Sync for AttentionMask
impl Unpin for AttentionMask
impl UnsafeUnpin for AttentionMask
impl UnwindSafe for AttentionMask
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