Skip to main content

Adapter

Trait Adapter 

Source
pub trait Adapter: Send + Sync {
    type Config: AdapterConfig;

    // Required methods
    fn forward(
        &self,
        input: &Tensor,
        base_output: Option<&Tensor>,
    ) -> Result<Tensor, PeftError>;
    fn num_parameters(&self) -> usize;
    fn config(&self) -> &Self::Config;
}
Expand description

Core adapter trait for parameter-efficient fine-tuning.

Required Associated Types§

Source

type Config: AdapterConfig

The configuration type for this adapter.

Required Methods§

Source

fn forward( &self, input: &Tensor, base_output: Option<&Tensor>, ) -> Result<Tensor, PeftError>

Forward pass applying the adapter transformation.

§Arguments
  • input - Input tensor
  • base_output - Optional output from the base layer (for residual adapters)
§Returns

Transformed tensor

§Errors

Returns an error if the forward pass fails.

Source

fn num_parameters(&self) -> usize

Get the number of trainable parameters.

Source

fn config(&self) -> &Self::Config

Get the adapter’s configuration.

Implementors§