pub struct CausalSoftmaxInplace {
pub offset: usize,
}Expand description
The same causal softmax, written in place.
§Why this exists beside [CausalSoftmax]
The score tensor is (1, 9, 1142, 1142) — 47 MB. apply_op1_no_bwd
allocates a second one and writes the result there, so every layer
allocates 47 MB, writes 47 MB, and drops 47 MB. Over 30 layers that is
1.4 GB of allocation churn and an extra 1.4 GB of writes, and it was
the largest part of the 18 % of prefill that per-op timing could not
account for (examples/text_inline_prof).
The scores come straight out of q.matmul(k.t()) and nothing else holds a
reference, so the buffer is ours to overwrite. Softmax is row-local — each
row’s max, sum and normalisation touch only that row — so writing over the
input as we go is safe and produces identical values.
Fields§
§offset: usizeWhere this query block starts in the full sequence.
Trait Implementations§
Source§impl InplaceOp1 for CausalSoftmaxInplace
impl InplaceOp1 for CausalSoftmaxInplace
fn name(&self) -> &'static str
Source§fn cpu_fwd(&self, storage: &mut CpuStorage, layout: &Layout) -> CandleResult<()>
fn cpu_fwd(&self, storage: &mut CpuStorage, layout: &Layout) -> CandleResult<()>
Auto Trait Implementations§
impl Freeze for CausalSoftmaxInplace
impl RefUnwindSafe for CausalSoftmaxInplace
impl Send for CausalSoftmaxInplace
impl Sync for CausalSoftmaxInplace
impl Unpin for CausalSoftmaxInplace
impl UnsafeUnpin for CausalSoftmaxInplace
impl UnwindSafe for CausalSoftmaxInplace
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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 more