pub struct PeftModel<A>where
A: Adapter,{ /* private fields */ }Expand description
PEFT model wrapper for managing adapters across modules.
Provides module-level adapter management with pattern-based targeting.
Implementations§
Source§impl<A> PeftModel<A>where
A: Adapter,
impl<A> PeftModel<A>where
A: Adapter,
Sourcepub fn add_adapter<F>(
&mut self,
adapter_name: impl Into<String>,
pattern: &str,
module_names: &[&str],
adapter_factory: F,
) -> Result<usize, PeftError>
pub fn add_adapter<F>( &mut self, adapter_name: impl Into<String>, pattern: &str, module_names: &[&str], adapter_factory: F, ) -> Result<usize, PeftError>
Add an adapter to modules matching the given pattern.
§Arguments
adapter_name- Unique name for the adapterpattern- Pattern to match module namesmodule_names- List of all module names in the modeladapter_factory- Function to create adapter instances
§Errors
Returns an error if adapter creation fails
Sourcepub fn set_adapter(
&mut self,
module_name: &str,
adapter_name: &str,
) -> Result<(), PeftError>
pub fn set_adapter( &mut self, module_name: &str, adapter_name: &str, ) -> Result<(), PeftError>
Set the active adapter for a specific module.
§Errors
Returns an error if the module or adapter doesn’t exist
Sourcepub fn set_adapter_all(
&mut self,
adapter_name: impl Into<String>,
) -> Result<(), PeftError>
pub fn set_adapter_all( &mut self, adapter_name: impl Into<String>, ) -> Result<(), PeftError>
Set the active adapter for all modules.
§Errors
Returns an error if the adapter doesn’t exist in any module
Sourcepub fn active_adapter_name(&self) -> Option<&str>
pub fn active_adapter_name(&self) -> Option<&str>
Get the active adapter name.
Sourcepub fn adapter_names(&self) -> &[String]
pub fn adapter_names(&self) -> &[String]
Get all registered adapter names.
Sourcepub fn module_names(&self) -> Vec<&str>
pub fn module_names(&self) -> Vec<&str>
Get module names that have adapters.
Sourcepub fn has_adapter(&self, module_name: &str) -> bool
pub fn has_adapter(&self, module_name: &str) -> bool
Check if a module has any adapters.
Sourcepub fn forward_module(
&self,
module_name: &str,
input: &Tensor,
base_output: Option<&Tensor>,
) -> Result<Tensor, PeftError>
pub fn forward_module( &self, module_name: &str, input: &Tensor, base_output: Option<&Tensor>, ) -> Result<Tensor, PeftError>
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get the total number of trainable parameters across all active adapters.
Sourcepub fn num_modules(&self) -> usize
pub fn num_modules(&self) -> usize
Get the number of modules with adapters.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for PeftModel<A>
impl<A> RefUnwindSafe for PeftModel<A>where
A: RefUnwindSafe,
impl<A> Send for PeftModel<A>
impl<A> Sync for PeftModel<A>
impl<A> Unpin for PeftModel<A>where
A: Unpin,
impl<A> UnwindSafe for PeftModel<A>where
A: UnwindSafe,
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