#[non_exhaustive]pub enum SparsePattern {
LocalWindow,
GlobalLocal,
Random,
BlockSparse,
Sliding,
}Expand description
Sparse-attention pattern variants.
Controls which query–key pairs are evaluated during attention. All patterns give sub-quadratic complexity for long sequences.
use scirs2_neural::attention::sparse::SparsePattern;
let p = SparsePattern::LocalWindow;
assert_eq!(p, SparsePattern::LocalWindow);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
LocalWindow
Sliding-window local attention: each token attends to the window_size
tokens immediately before and after it (Longformer local attention).
GlobalLocal
Global + local attention: a set of designated global tokens attend to all positions and all positions attend to global tokens; non-global tokens additionally use a local window (Longformer full model).
Random
Uniform-random attention pattern: each token attends to n_random
randomly chosen positions in addition to its local window. Used in the
BigBird architecture.
BlockSparse
Block-sparse attention (BigBird): the sequence is divided into blocks of
size block_size and each block attends to: itself, n_random_blocks
randomly chosen blocks, and any designated global tokens.
Sliding
Alias for LocalWindow — a sliding window
with no global tokens.
Trait Implementations§
Source§impl Clone for SparsePattern
impl Clone for SparsePattern
Source§fn clone(&self) -> SparsePattern
fn clone(&self) -> SparsePattern
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SparsePattern
impl Debug for SparsePattern
Source§impl Display for SparsePattern
impl Display for SparsePattern
Source§impl PartialEq for SparsePattern
impl PartialEq for SparsePattern
impl Copy for SparsePattern
impl Eq for SparsePattern
impl StructuralPartialEq for SparsePattern
Auto Trait Implementations§
impl Freeze for SparsePattern
impl RefUnwindSafe for SparsePattern
impl Send for SparsePattern
impl Sync for SparsePattern
impl Unpin for SparsePattern
impl UnsafeUnpin for SparsePattern
impl UnwindSafe for SparsePattern
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.