pub struct LoraAdapter { /* private fields */ }Expand description
Manages LoRA adaptation for a collection of layers
Implementations§
Source§impl LoraAdapter
impl LoraAdapter
Sourcepub fn new(config: LoraConfig) -> Self
pub fn new(config: LoraConfig) -> Self
Create a new LoRA adapter with the given configuration
Sourcepub fn add_layer(
&mut self,
name: String,
weight: Array2<f32>,
) -> ModelResult<()>
pub fn add_layer( &mut self, name: String, weight: Array2<f32>, ) -> ModelResult<()>
Add a layer to the adapter with the given name and weight matrix
Sourcepub fn forward_layer(
&self,
name: &str,
input: &Array1<f32>,
) -> ModelResult<Array1<f32>>
pub fn forward_layer( &self, name: &str, input: &Array1<f32>, ) -> ModelResult<Array1<f32>>
Forward pass through a named layer
Sourcepub fn merge_all(&mut self) -> ModelResult<()>
pub fn merge_all(&mut self) -> ModelResult<()>
Merge all LoRA weights into the original weight matrices
Sourcepub fn unmerge_all(&mut self) -> ModelResult<()>
pub fn unmerge_all(&mut self) -> ModelResult<()>
Unmerge all LoRA weights from the original weight matrices
Sourcepub fn total_trainable_params(&self) -> usize
pub fn total_trainable_params(&self) -> usize
Total trainable parameters across all layers
Sourcepub fn total_original_params(&self) -> usize
pub fn total_original_params(&self) -> usize
Total original (frozen) parameters across all layers
Sourcepub fn overall_compression_ratio(&self) -> f32
pub fn overall_compression_ratio(&self) -> f32
Overall compression ratio
Sourcepub fn layer_names(&self) -> Vec<&str>
pub fn layer_names(&self) -> Vec<&str>
Get names of all layers
Sourcepub fn get_layer(&self, name: &str) -> Option<&LoraLinear>
pub fn get_layer(&self, name: &str) -> Option<&LoraLinear>
Get an immutable reference to a named layer
Sourcepub fn get_layer_mut(&mut self, name: &str) -> Option<&mut LoraLinear>
pub fn get_layer_mut(&mut self, name: &str) -> Option<&mut LoraLinear>
Get a mutable reference to a named layer
Sourcepub fn config(&self) -> &LoraConfig
pub fn config(&self) -> &LoraConfig
Get the adapter configuration
Sourcepub fn summary(&self) -> LoraAdapterSummary
pub fn summary(&self) -> LoraAdapterSummary
Get a summary of the adapter
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 UnsafeUnpin 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