pub struct LoRAAdapter {
pub a: Tensor,
pub b: Tensor,
pub alpha: f32,
pub rank: usize,
}Expand description
Low-rank adapter added to a Linear: x @ a @ b * alpha / rank.
Fields§
§a: TensorDown projection [in, rank].
b: TensorUp projection [rank, out] (zero-initialised, so training starts
from the base model).
alpha: f32Scale numerator; the update is scaled by alpha / rank.
rank: usizeAdapter rank.
Implementations§
Source§impl LoRAAdapter
impl LoRAAdapter
Sourcepub fn new(
ctx: Arc<WgpuContext>,
in_dim: usize,
out_dim: usize,
rank: usize,
alpha: f32,
) -> Self
pub fn new( ctx: Arc<WgpuContext>, in_dim: usize, out_dim: usize, rank: usize, alpha: f32, ) -> Self
An adapter for an in_dim -> out_dim projection. a is drawn
uniformly from ±1/sqrt(in_dim) (Kaiming-uniform, as in PEFT) with a
deterministic generator seeded from the shape, and b is zero.
A constant a would make every rank component identical, so the
adapter could never learn more than a rank-1 update.
Sourcepub fn new_seeded(
ctx: Arc<WgpuContext>,
in_dim: usize,
out_dim: usize,
rank: usize,
alpha: f32,
seed: u64,
) -> Self
pub fn new_seeded( ctx: Arc<WgpuContext>, in_dim: usize, out_dim: usize, rank: usize, alpha: f32, seed: u64, ) -> Self
new with an extra seed, so adapters of equal shape
(e.g. every layer’s q_proj) start from different matrices.
Trait Implementations§
Source§impl Clone for LoRAAdapter
impl Clone for LoRAAdapter
Auto Trait Implementations§
impl !RefUnwindSafe for LoRAAdapter
impl !Send for LoRAAdapter
impl !Sync for LoRAAdapter
impl !UnwindSafe for LoRAAdapter
impl Freeze for LoRAAdapter
impl Unpin for LoRAAdapter
impl UnsafeUnpin for LoRAAdapter
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
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