Struct QkvBase

Source
pub struct QkvBase<S = OwnedRepr<f64>, D = Ix2>
where D: Dimension, S: RawData,
{ /* private fields */ }
Expand description

QkvBase is a container for the query, key, and value arrays used in the attention mechanism of the transformer model.

Implementations§

Source§

impl<A, S, D> QkvBase<S, D>
where D: Dimension, S: RawData<Elem = A>,

Source

pub fn builder<Sh, F>(shape: Sh, builder: F) -> Self
where F: Fn(D) -> ArrayBase<S, D>, Sh: ShapeBuilder<Dim = D>,

Source

pub fn from_elem<Sh>(shape: Sh, value: A) -> Self
where Sh: ShapeBuilder<Dim = D>, A: Clone, S: DataOwned,

Source

pub fn as_qkv( &self, ) -> (ArrayView<'_, A, D>, ArrayView<'_, A, D>, ArrayView<'_, A, D>)
where S: Data,

Source

pub fn into_qkv(self) -> (ArrayBase<S, D>, ArrayBase<S, D>, ArrayBase<S, D>)

Consumes the store and returns a three-tuple consisting of the query, key, and value arrays respectively.

Source

pub fn qkv(&self) -> (&ArrayBase<S, D>, &ArrayBase<S, D>, &ArrayBase<S, D>)

Source

pub fn new<Sh: ShapeBuilder<Dim = D>>(shape: Sh) -> Self
where A: Default, S: DataOwned,

Source

pub fn ones<Sh: ShapeBuilder<Dim = D>>(shape: Sh) -> Self
where A: Clone + One, S: DataOwned,

Source

pub fn zeros<Sh: ShapeBuilder<Dim = D>>(shape: Sh) -> Self
where A: Clone + Zero, S: DataOwned,

Source

pub fn q(&self) -> &ArrayBase<S, D>

Source

pub fn q_mut(&mut self) -> &mut ArrayBase<S, D>

Source

pub fn k(&self) -> &ArrayBase<S, D>

Source

pub fn k_mut(&mut self) -> &mut ArrayBase<S, D>

Source

pub fn v(&self) -> &ArrayBase<S, D>

Source

pub fn v_mut(&mut self) -> &mut ArrayBase<S, D>

Source

pub fn dim(&self) -> D::Pattern

Return the pattern of the dimension

Source

pub fn ndim(&self) -> usize

Returns rank (ndim) of the dimension

Source

pub fn raw_dim(&self) -> D

Returns the raw dimension D

Source

pub fn shape(&self) -> &[usize]

Returns a reference to the current dimension, as a slice.

Source

pub fn into_owned(self) -> QkvBase<OwnedRepr<A>, D>
where A: Clone, S: Data,

Source

pub fn to_owned(&self) -> QkvBase<OwnedRepr<A>, D>
where A: Clone, S: Data,

Source

pub fn into_shared(self) -> QkvBase<OwnedArcRepr<A>, D>
where A: Clone, S: DataOwned,

Source

pub fn to_shared(&self) -> QkvBase<OwnedArcRepr<A>, D>
where A: Clone, S: DataShared,

Source

pub fn view(&self) -> QkvBase<ViewRepr<&A>, D>
where S: Data,

Source

pub fn view_mut(&mut self) -> QkvBase<ViewRepr<&mut A>, D>
where S: DataMut,

Source§

impl<A, S, D> QkvBase<S, D>
where D: Dimension, S: RawData<Elem = A>, A: Clone,

Source

pub fn attention( &self, dropout: Option<f64>, mask: Option<&Array<bool, D>>, ) -> Score<A, D>
where A: ComplexFloat + ScalarOperand, S: Data, ArrayBase<S, D>: for<'a> Dot<ArrayView<'a, A, D>, Output = Array<A, D>>, Array<A, D>: Dot<ArrayBase<S, D>, Output = Array<A, D>>,

Computes the Score using scaled dot-product attention.

Trait Implementations§

Source§

impl<A, S, D> Borrow<QkvBase<S, D>> for AttentionHead<A, D, S>
where D: Dimension, S: RawData<Elem = A>,

Source§

fn borrow(&self) -> &QkvBase<S, D>

Immutably borrows from an owned value. Read more
Source§

impl<A, S, D> BorrowMut<QkvBase<S, D>> for AttentionHead<A, D, S>
where D: Dimension, S: RawData<Elem = A>,

Source§

fn borrow_mut(&mut self) -> &mut QkvBase<S, D>

Mutably borrows from an owned value. Read more
Source§

impl<A, S, D> Clone for QkvBase<S, D>
where D: Dimension, S: RawDataClone<Elem = A>,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A, S, D> Default for QkvBase<S, D>
where A: Default, D: Dimension, S: DataOwned<Elem = A>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A, S, D> From<QkvBase<S, D>> for AttentionHead<A, D, S>
where D: Dimension, S: RawData<Elem = A>,

Source§

fn from(params: QkvBase<S, D>) -> Self

Converts to this type from the input type.
Source§

impl<A, S, T, D, E, F> Matmul<ArrayBase<T, E>> for QkvBase<S, D>
where A: LinalgScalar, D: Dimension, E: Dimension, F: Dimension, S: Data<Elem = A>, T: Data<Elem = A>, ArrayBase<S, D>: Dot<ArrayBase<T, E>, Output = Array<A, F>>,

Source§

type Output = QkvBase<OwnedRepr<A>, F>

Source§

fn matmul(&self, rhs: &ArrayBase<T, E>) -> Self::Output

Source§

impl<A, S, T, D, E, F> Matmul<QkvBase<T, E>> for QkvBase<S, D>
where A: LinalgScalar, D: Dimension, E: Dimension, F: Dimension, S: Data<Elem = A>, T: Data<Elem = A>, ArrayBase<S, D>: Dot<ArrayBase<T, E>, Output = Array<A, F>>,

Source§

type Output = QkvBase<OwnedRepr<A>, F>

Source§

fn matmul(&self, rhs: &QkvBase<T, E>) -> Self::Output

Source§

impl<A, B, S, D, S2, D2> PartialEq<(ArrayBase<S2, D2>, ArrayBase<S2, D2>, ArrayBase<S2, D2>)> for QkvBase<S, D>
where A: PartialEq, B: PartialEq, D: Dimension, S: Data<Elem = A>, S2: Data<Elem = B>, D2: Dimension, ArrayBase<S, D>: PartialEq<ArrayBase<S2, D2>>,

Source§

fn eq(&self, (q, k, v): &(ArrayBase<S2, D2>, A, B)) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, B, S, D, S2, D2> PartialEq<ArrayBase<S2, D2>> for QkvBase<S, D>
where A: PartialEq, B: PartialEq, D: Dimension, S: Data<Elem = A>, S2: Data<Elem = B>, D2: Dimension, ArrayBase<S, D>: PartialEq<ArrayBase<S2, D2>>,

Source§

fn eq(&self, other: &ArrayBase<S2, D2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> PartialEq for QkvBase<S, D>
where A: PartialEq, D: Dimension, S: Data<Elem = A>,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> Copy for QkvBase<S, D>
where D: Copy + Dimension, S: Copy + RawDataClone<Elem = A>,

Auto Trait Implementations§

§

impl<S, D> Freeze for QkvBase<S, D>
where S: Freeze, D: Freeze,

§

impl<S, D> RefUnwindSafe for QkvBase<S, D>

§

impl<S, D> Send for QkvBase<S, D>
where S: Send + Data,

§

impl<S, D> Sync for QkvBase<S, D>
where S: Sync + Data,

§

impl<S, D> Unpin for QkvBase<S, D>
where S: Unpin, D: Unpin,

§

impl<S, D> UnwindSafe for QkvBase<S, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<K, S> Id<K> for S
where S: Borrow<K>, K: Identifier,

Source§

type Item = S

Source§

fn get(&self) -> &<S as Id<K>>::Item

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IsBiased for T
where T: 'static,

Source§

fn is_biased(&self) -> bool

Source§

impl<T> IsType for T
where T: 'static,

Source§

fn of<T>() -> bool
where T: 'static,

Source§

fn is<T>(&self) -> bool
where T: 'static,

Source§

impl<T> OfType for T

Source§

fn of<T>() -> bool
where T: 'static, Self: 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more