Skip to main content

RotaryEmbedding

Struct RotaryEmbedding 

Source
pub struct RotaryEmbedding { /* private fields */ }

Implementations§

Source§

impl RotaryEmbedding

Source

pub fn new( rope_dim: usize, theta: f32, max_position: usize, kind: RopeKind, ) -> Self

Precomputes rotation tables for every position in 0..max_position.

rope_dim must be even (each pair needs two dimensions; see crate::config::QwenConfig::from_metadata, which rejects an odd rope_dimension_count before a RotaryEmbedding is ever built).

Source

pub fn apply(&self, x: &Tensor, positions: &[usize]) -> Result<Tensor>

Rotates x, shaped [n_heads, seq, head_dim], in place per position. positions[s] is the absolute sequence position of x’s s-th row — not necessarily s itself, since a KV-cache decode step’s single query token sits at cache_len, not at 0 (see crate::kv_cache::KvCache).

Only the leading rope_dim elements of each head are rotated; head_dim - rope_dim trailing elements (when rope_dim < head_dim) pass through unchanged, matching llama.cpp’s partial-rotary support.

§Errors

Error::ShapeMismatch if x is not rank 3, if its last dimension is smaller than rope_dim, or if positions.len() does not match x’s sequence dimension.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,