pub struct SlidingWindowMaskCache { /* private fields */ }Expand description
Precomputed sliding window attention mask
Each position can only attend to the previous window_size positions.
Used by Mistral, Mixtral, and other sliding window attention models.
Implementations§
Source§impl SlidingWindowMaskCache
impl SlidingWindowMaskCache
Sourcepub fn new(
max_seq_len: usize,
window_size: usize,
device: &Device,
) -> Result<Self>
pub fn new( max_seq_len: usize, window_size: usize, device: &Device, ) -> Result<Self>
Create a new sliding window mask cache
§Arguments
max_seq_len- Maximum sequence length to precomputewindow_size- Number of positions to attend todevice- Device to store the mask on
Sourcepub fn get(&self, seq_len: usize) -> Result<Tensor>
pub fn get(&self, seq_len: usize) -> Result<Tensor>
Get sliding window mask for a specific sequence length
Sourcepub fn get_broadcast(&self, seq_len: usize) -> Result<Tensor>
pub fn get_broadcast(&self, seq_len: usize) -> Result<Tensor>
Get sliding window mask reshaped for attention broadcasting
Sourcepub fn window_size(&self) -> usize
pub fn window_size(&self) -> usize
Get the window size
Sourcepub fn max_seq_len(&self) -> usize
pub fn max_seq_len(&self) -> usize
Get the maximum sequence length
Auto Trait Implementations§
impl !RefUnwindSafe for SlidingWindowMaskCache
impl !UnwindSafe for SlidingWindowMaskCache
impl Freeze for SlidingWindowMaskCache
impl Send for SlidingWindowMaskCache
impl Sync for SlidingWindowMaskCache
impl Unpin for SlidingWindowMaskCache
impl UnsafeUnpin for SlidingWindowMaskCache
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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