pub struct LoraLinear {
pub base: LoraBase,
pub lora_a: Array,
pub lora_b: Array,
pub scale: f32,
}Expand description
A frozen linear layer plus a trainable low-rank update (mlx-lm’s LoRALinear):
y = base(x) + scale · (x A) B, with A of shape [input, r] and B of shape
[r, output] (zeros at first, so the layer starts as its base).
Fields§
§base: LoraBaseThe adapted layer (frozen).
lora_a: Array[input_dims, r].
lora_b: Array[r, output_dims].
scale: f32The update’s scale (mlx-lm’s default 20).
Implementations§
Source§impl LoraLinear
impl LoraLinear
Sourcepub fn from_base(base: LoraBase, r: usize, scale: f32) -> Result<Self>
pub fn from_base(base: LoraBase, r: usize, scale: f32) -> Result<Self>
Adapts base with rank r, as mlx-lm’s LoRALinear.from_base (including its
random draws: A is uniform in [-1/√input, 1/√input)).
Trait Implementations§
Source§impl Clone for LoraLinear
impl Clone for LoraLinear
Source§impl Debug for LoraLinear
impl Debug for LoraLinear
Source§impl Module for LoraLinear
impl Module for LoraLinear
Source§fn visit(&mut self, p: &mut Parameters<'_>)
fn visit(&mut self, p: &mut Parameters<'_>)
Reports every parameter and submodule to
p, frozen ones included.Source§fn parameters(&self) -> Vec<(String, Array)>
fn parameters(&self) -> Vec<(String, Array)>
Every parameter with its path (
layers.0.weight), in visiting order.Source§fn trainable_parameters(&self) -> Vec<(String, Array)>
fn trainable_parameters(&self) -> Vec<(String, Array)>
The parameters that are trained (not frozen), with their paths.
Source§fn update_trainable(&mut self, values: &[Array]) -> Result<()>
fn update_trainable(&mut self, values: &[Array]) -> Result<()>
Replaces the trainable parameters, given in the order of
Module::trainable_parameters (as optimizers return them).Source§fn load_weights(
&mut self,
weights: impl IntoIterator<Item = (String, Array)>,
strict: bool,
) -> Result<()>
fn load_weights( &mut self, weights: impl IntoIterator<Item = (String, Array)>, strict: bool, ) -> Result<()>
Replaces parameters by path, as MLX’s
load_weights: each weight must have its
parameter’s shape (the dtype is kept as loaded). With strict, every parameter
must be given and no unknown names are allowed.Auto Trait Implementations§
impl Freeze for LoraLinear
impl RefUnwindSafe for LoraLinear
impl Send for LoraLinear
impl Sync for LoraLinear
impl Unpin for LoraLinear
impl UnsafeUnpin for LoraLinear
impl UnwindSafe for LoraLinear
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
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> ⓘ
Converts
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> ⓘ
Converts
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