pub struct Sdpa;
Implementations§
source§impl Sdpa
impl Sdpa
sourcepub fn run_attention(
&self,
q: &Tensor,
k: &Tensor,
v: &Tensor,
mask: Option<&Tensor>,
flash_params: Option<&FlashParams>,
sdpa_params: &SdpaParams,
) -> Result<Tensor, Error>
pub fn run_attention( &self, q: &Tensor, k: &Tensor, v: &Tensor, mask: Option<&Tensor>, flash_params: Option<&FlashParams>, sdpa_params: &SdpaParams, ) -> Result<Tensor, Error>
Computes softmax(QK^T*sqrt(d_k))V
Inputs:
- q: (b_sz, n_attn_heads, q_len, head_dim)
- k: (b_sz, n_kv_heads, q_len, head_dim)
- v: (b_sz, n_kv_heads, q_len, head_dim)
The attention implementation is dispatched as follows:
- If
use_flash_attn == true
, use a flash attention V2 kernel - If using CUDA and the cuBLASLt kernel is initialized, then it will use an optimized version.
- Otherwise, use the “naive” SDPA implementation.
Auto Trait Implementations§
impl Freeze for Sdpa
impl RefUnwindSafe for Sdpa
impl Send for Sdpa
impl Sync for Sdpa
impl Unpin for Sdpa
impl UnwindSafe for Sdpa
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> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Forward to the method defined on the type
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Forward to the method defined on the type
Any
.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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