#[non_exhaustive]pub enum RopeScaling {
None,
Linear {
factor: f32,
},
Llama3(Llama3),
Yarn(Yarn),
LongRope(LongRope),
Proportional {
rotated_dims: i32,
factor: f32,
},
}Expand description
How a rotary embedding’s frequencies (or positions) are scaled, as mlx-lm’s RoPE classes. Frequencies are computed in float32 with mlx-lm’s formulas.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
None
The plain base^(-2i/dims) frequencies (default).
Linear
Positions divided by factor (linear).
Llama3(Llama3)
Llama 3’s frequency-dependent scaling (Llama3RoPE).
Yarn(Yarn)
YaRN (YarnRoPE): interpolated frequencies and an input scale (mscale).
LongRope(LongRope)
LongRoPE (SuScaledRoPE): per-pair long factors and an input scale.
Proportional
Gemma 4’s proportional RoPE (ProportionalRoPE): the first rotated_dims of the
head’s features rotate with exponents over the whole head, scaled by factor; the
rest keep their values (infinite wavelength).
Implementations§
Source§impl RopeScaling
impl RopeScaling
Sourcepub fn frequencies(&self, dims: i32, base: f32) -> Option<Array>
pub fn frequencies(&self, dims: i32, base: f32) -> Option<Array>
The per-pair frequencies ([dims / 2], float32) for dims rotated features and
base, or None when the plain base (and RopeScaling::position_scale)
applies.
Sourcepub fn mscale(&self) -> f32
pub fn mscale(&self) -> f32
The scale mlx-lm applies to the rotated features before the rotation (YaRN’s
mscale, LongRoPE’s; 1 otherwise).
Sourcepub fn position_scale(&self) -> f32
pub fn position_scale(&self) -> f32
The scale of positions (1 / factor for RopeScaling::Linear; 1 otherwise).
Trait Implementations§
Source§impl Clone for RopeScaling
impl Clone for RopeScaling
Source§impl Debug for RopeScaling
impl Debug for RopeScaling
Source§impl PartialEq for RopeScaling
impl PartialEq for RopeScaling
Source§impl Static for RopeScaling
impl Static for RopeScaling
Source§fn hash_static(&self, __h: &mut dyn Hasher)
fn hash_static(&self, __h: &mut dyn Hasher)
h.impl StructuralPartialEq for RopeScaling
Auto Trait Implementations§
impl Freeze for RopeScaling
impl RefUnwindSafe for RopeScaling
impl Send for RopeScaling
impl Sync for RopeScaling
impl Unpin for RopeScaling
impl UnsafeUnpin for RopeScaling
impl UnwindSafe for RopeScaling
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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