pub struct LoraStack { /* private fields */ }Expand description
A stack of LoRA adapters applied in order.
Adapters are applied additively:
output += scale_0 · LoRA_0(x) + scale_1 · LoRA_1(x) + ...
Each adapter’s intrinsic alpha/rank scale is multiplied by the per-entry stack_scale.
The stack supports two independent adapter lists:
entries: legacyLoadedLoraadapters (GGUF-loaded, keyed by tensor name).adapter_list: trait-object adapters implementingLoraAdapterTrait.
Both lists are consulted by the respective dispatch methods.
Implementations§
Source§impl LoraStack
impl LoraStack
Sourcepub fn push(&mut self, adapter: Arc<LoadedLora>, scale: f32)
pub fn push(&mut self, adapter: Arc<LoadedLora>, scale: f32)
Push a new GGUF-loaded adapter onto the stack with a given scale multiplier.
scale multiplies the adapter’s intrinsic alpha/rank scale factor.
Sourcepub fn pop(&mut self) -> Option<(Arc<LoadedLora>, f32)>
pub fn pop(&mut self) -> Option<(Arc<LoadedLora>, f32)>
Remove the last GGUF-loaded adapter from the stack.
Returns None if the entries list is empty.
Sourcepub fn entries(&self) -> &[(Arc<LoadedLora>, f32)]
pub fn entries(&self) -> &[(Arc<LoadedLora>, f32)]
Immutable view of the (LoadedLora, scale) entries.
Sourcepub fn adapters(&self) -> &[Arc<dyn LoraAdapterTrait>]
pub fn adapters(&self) -> &[Arc<dyn LoraAdapterTrait>]
Immutable view of the trait-object adapter list.
Sourcepub fn apply(
&self,
tensor_name: &str,
input: &[f32],
out_features: usize,
) -> Result<Vec<f32>, ArchError>
pub fn apply( &self, tensor_name: &str, input: &[f32], out_features: usize, ) -> Result<Vec<f32>, ArchError>
Apply the entire legacy stack to compute the additive LoRA delta for
tensor_name.
Returns Ok(delta) where delta is a Vec<f32> of length
out_features representing Σ_i stack_scale_i · (alpha_i/rank_i) · B_i @ A_i @ input.
Adapters that do not define tensor_name are silently skipped.
The caller is responsible for adding delta to the base linear output.
§Errors
Returns crate::error::ArchError::Quant if a matching adapter’s dimension checks fail.
Sourcepub fn push_adapter(&mut self, adapter: Arc<dyn LoraAdapterTrait>)
pub fn push_adapter(&mut self, adapter: Arc<dyn LoraAdapterTrait>)
Push a trait-object adapter onto the new adapter list.
Sourcepub fn applied_delta(
&self,
target: TargetModule,
layer: usize,
input: &[f32],
) -> Option<Vec<f32>>
pub fn applied_delta( &self, target: TargetModule, layer: usize, input: &[f32], ) -> Option<Vec<f32>>
Compute the combined delta for (target, layer) across all
trait-object adapters, applied to input vector input.
Returns None if no adapter in the list covers this (target, layer).
Formula: Δ_total = Σᵢ (αᵢ / rᵢ) * Bᵢ @ Aᵢ @ input.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LoraStack
impl !RefUnwindSafe for LoraStack
impl Send for LoraStack
impl Sync for LoraStack
impl Unpin for LoraStack
impl UnsafeUnpin for LoraStack
impl !UnwindSafe for LoraStack
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
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>
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>
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