pub struct RotaryEmbedding<B: Backend> { /* private fields */ }Expand description
Precomputed RoPE cosine/sine tables.
Frequencies: inv_freq[i] = theta^(-2i / head_dim) for i in 0..head_dim/2.
Tables are [max_position, head_dim] with the half-dim frequencies
duplicated (cat([cos, cos])) to match the half-split convention
(config.rope_interleaved = false, the HF Llama default).
Implementations§
Source§impl<B: Backend> RotaryEmbedding<B>
impl<B: Backend> RotaryEmbedding<B>
Sourcepub fn new(
head_dim: usize,
theta: f64,
max_position: usize,
device: &Device<B>,
) -> Self
pub fn new( head_dim: usize, theta: f64, max_position: usize, device: &Device<B>, ) -> Self
Builds tables on device (no frequency scaling).
Sourcepub fn new_scaled(
head_dim: usize,
theta: f64,
max_position: usize,
scaling: &RopeScaling,
device: &Device<B>,
) -> Self
pub fn new_scaled( head_dim: usize, theta: f64, max_position: usize, scaling: &RopeScaling, device: &Device<B>, ) -> Self
Builds tables on device with RoPE frequency scaling applied.
Auto Trait Implementations§
impl<B> Freeze for RotaryEmbedding<B>where
<B as BackendTypes>::FloatTensorPrimitive: Freeze,
<B as BackendTypes>::QuantizedTensorPrimitive: Freeze,
impl<B> RefUnwindSafe for RotaryEmbedding<B>where
<B as BackendTypes>::FloatTensorPrimitive: RefUnwindSafe,
<B as BackendTypes>::QuantizedTensorPrimitive: RefUnwindSafe,
impl<B> Send for RotaryEmbedding<B>
impl<B> Sync for RotaryEmbedding<B>
impl<B> Unpin for RotaryEmbedding<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
impl<B> UnsafeUnpin for RotaryEmbedding<B>where
<B as BackendTypes>::FloatTensorPrimitive: UnsafeUnpin,
<B as BackendTypes>::QuantizedTensorPrimitive: UnsafeUnpin,
impl<B> UnwindSafe for RotaryEmbedding<B>where
<B as BackendTypes>::FloatTensorPrimitive: UnwindSafe,
<B as BackendTypes>::QuantizedTensorPrimitive: UnwindSafe,
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