pub struct LoRAAdapter {
pub lora_a: Tensor,
pub lora_b: Tensor,
pub scaling: f32,
pub active: bool,
}Expand description
LoRA adapter containing the low-rank matrices.
Fields§
§lora_a: TensorLow-rank matrix A (input_dim x rank)
lora_b: TensorLow-rank matrix B (rank x output_dim)
scaling: f32Scaling factor
active: boolWhether this adapter is active
Implementations§
Source§impl LoRAAdapter
impl LoRAAdapter
Sourcepub fn new(
input_dim: usize,
output_dim: usize,
rank: usize,
alpha: f32,
) -> Result<Self>
pub fn new( input_dim: usize, output_dim: usize, rank: usize, alpha: f32, ) -> Result<Self>
Creates a new LoRA adapter with random initialization.
Sourcepub fn forward(&self, input: &Tensor) -> Result<Tensor>
pub fn forward(&self, input: &Tensor) -> Result<Tensor>
Compute the LoRA update: scaling * B @ A
Sourcepub fn get_delta_weight(&self) -> Result<Tensor>
pub fn get_delta_weight(&self) -> Result<Tensor>
Get the effective weight matrix ∆W = scaling * B @ A
Sourcepub fn merge_into_weight(&self, base_weight: &mut Tensor) -> Result<()>
pub fn merge_into_weight(&self, base_weight: &mut Tensor) -> Result<()>
Merge adapter weights into the base weight matrix
Sourcepub fn set_active(&mut self, active: bool)
pub fn set_active(&mut self, active: bool)
Enable or disable this adapter
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get the number of trainable parameters
Trait Implementations§
Source§impl Clone for LoRAAdapter
impl Clone for LoRAAdapter
Source§fn clone(&self) -> LoRAAdapter
fn clone(&self) -> LoRAAdapter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for LoRAAdapter
impl RefUnwindSafe for LoRAAdapter
impl Send for LoRAAdapter
impl Sync for LoRAAdapter
impl Unpin for LoRAAdapter
impl UnwindSafe 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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