pub struct AdaLoraLayer { /* private fields */ }Expand description
AdaLoRA layer using SVD-based parameterization.
Uses W = W0 + P * Λ * Q where:
- P: Left singular vectors (out_features × r)
- Λ: Diagonal singular values (r)
- Q: Right singular vectors (r × in_features)
This allows for dynamic rank allocation by zeroing out singular values.
Implementations§
Source§impl AdaLoraLayer
impl AdaLoraLayer
Sourcepub fn new(
in_features: usize,
out_features: usize,
config: AdaLoraConfig,
device: &Device,
) -> Result<AdaLoraLayer, PeftError>
pub fn new( in_features: usize, out_features: usize, config: AdaLoraConfig, device: &Device, ) -> Result<AdaLoraLayer, PeftError>
Sourcepub fn current_rank(&self) -> usize
pub fn current_rank(&self) -> usize
Get the current active rank.
Sourcepub fn target_rank(&self) -> usize
pub fn target_rank(&self) -> usize
Get the target rank.
Sourcepub fn update_rank_mask(
&mut self,
importance_scores: &Tensor,
budget: usize,
) -> Result<(), PeftError>
pub fn update_rank_mask( &mut self, importance_scores: &Tensor, budget: usize, ) -> Result<(), PeftError>
Trait Implementations§
Source§impl Adapter for AdaLoraLayer
impl Adapter for AdaLoraLayer
Source§type Config = AdaLoraConfig
type Config = AdaLoraConfig
The configuration type for this adapter.
Source§fn forward(
&self,
input: &Tensor,
base_output: Option<&Tensor>,
) -> Result<Tensor, PeftError>
fn forward( &self, input: &Tensor, base_output: Option<&Tensor>, ) -> Result<Tensor, PeftError>
Forward pass applying the adapter transformation. Read more
Source§fn num_parameters(&self) -> usize
fn num_parameters(&self) -> usize
Get the number of trainable parameters.
Source§impl Mergeable for AdaLoraLayer
impl Mergeable for AdaLoraLayer
Auto Trait Implementations§
impl Freeze for AdaLoraLayer
impl !RefUnwindSafe for AdaLoraLayer
impl Send for AdaLoraLayer
impl Sync for AdaLoraLayer
impl Unpin for AdaLoraLayer
impl !UnwindSafe for AdaLoraLayer
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> 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