pub struct CausalMaskCache { /* private fields */ }Expand description
Precomputed causal attention mask
Causal masks ensure that position i can only attend to positions <= i. We precompute a mask for max_seq_len and slice as needed.
Implementations§
Source§impl CausalMaskCache
impl CausalMaskCache
Sourcepub fn new(max_seq_len: usize, device: &Device) -> Result<Self>
pub fn new(max_seq_len: usize, device: &Device) -> Result<Self>
Create a new causal mask cache
§Arguments
max_seq_len- Maximum sequence length to precomputedevice- 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 causal mask for a specific sequence length
Returns a [seq_len, seq_len] mask
Sourcepub fn get_broadcast(&self, seq_len: usize) -> Result<Tensor>
pub fn get_broadcast(&self, seq_len: usize) -> Result<Tensor>
Get causal mask reshaped for attention broadcasting
Returns mask with shape [1, 1, seq_len, seq_len] for broadcasting over [batch, heads, seq, seq] attention scores
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 CausalMaskCache
impl !UnwindSafe for CausalMaskCache
impl Freeze for CausalMaskCache
impl Send for CausalMaskCache
impl Sync for CausalMaskCache
impl Unpin for CausalMaskCache
impl UnsafeUnpin for CausalMaskCache
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