pub struct LoRAAdapterManager {
pub detector: ContextDetector,
pub expected_n_in: Option<usize>,
pub expected_n_out: Option<usize>,
/* private fields */
}Expand description
Manages LoRA adapter loading, caching, and active-adapter switching.
The manager maintains:
- A filesystem directory for
.lorafiles - An LRU cache of up to 10 loaded adapters (≈150 MB at 15 MB each)
- The currently active adapter (fast path for repeated calls)
Fields§
§detector: ContextDetector§expected_n_in: Option<usize>Expected embedding dimension — used for dim-check at apply time.
expected_n_out: Option<usize>Expected hidden/output dimension — used for dim-check at apply time.
Implementations§
Source§impl LoRAAdapterManager
impl LoRAAdapterManager
Sourcepub fn new(adapter_dir: impl Into<PathBuf>) -> Self
pub fn new(adapter_dir: impl Into<PathBuf>) -> Self
Create a manager pointing at adapter_dir.
The directory does not need to exist at construction time; adapters
are loaded lazily on first switch_to.
Sourcepub fn default_path() -> PathBuf
pub fn default_path() -> PathBuf
Standard location: ~/.qualia/lora_adapters/
Sourcepub fn set_expected_dims(&mut self, n_in: usize, n_out: usize)
pub fn set_expected_dims(&mut self, n_in: usize, n_out: usize)
Hint the expected input/output dimensions so that mis-shaped adapters
are rejected early rather than causing panic in apply_cpu.
Sourcepub fn detect_context(&self, prompt: &str) -> (ContextType, f32)
pub fn detect_context(&self, prompt: &str) -> (ContextType, f32)
Detect ContextType from prompt text.
LoRA context is no longer encoded in NQuin metadata bits (§4.1 migration);
use active_adapter_for_hash() to look up the adapter for a specific quin.
Sourcepub fn active_adapter_for_hash(&self, content_hash: u64) -> Option<u64>
pub fn active_adapter_for_hash(&self, content_hash: u64) -> Option<u64>
Look up the active adapter ID for a given NQuin content-hash.
Returns None if no adapter has been associated with that quin.
Sourcepub fn set_adapter_for_hash(&mut self, content_hash: u64, adapter_id: u64)
pub fn set_adapter_for_hash(&mut self, content_hash: u64, adapter_id: u64)
Associate an adapter ID with a NQuin content-hash in the side-table.
Sourcepub fn clear_hash_associations(&mut self)
pub fn clear_hash_associations(&mut self)
Remove all side-table associations (e.g. at end of an inference batch).
Sourcepub fn switch_to(&mut self, target: ContextType) -> Result<bool, LoRAError>
pub fn switch_to(&mut self, target: ContextType) -> Result<bool, LoRAError>
Ensure the adapter for target is loaded and set as active.
Returns Ok(true) if a switch occurred, Ok(false) if already active.
Sourcepub fn auto_switch(
&mut self,
prompt: &str,
threshold: f32,
) -> (ContextType, f32, bool)
pub fn auto_switch( &mut self, prompt: &str, threshold: f32, ) -> (ContextType, f32, bool)
Detect context from prompt and switch adapter if confidence exceeds threshold.
Returns (context_type, confidence, switched).
Sourcepub fn apply_active(
&self,
input: &[f32],
output: &mut [f32],
) -> Result<(), LoRAError>
pub fn apply_active( &self, input: &[f32], output: &mut [f32], ) -> Result<(), LoRAError>
Apply the active adapter’s delta to output (if any adapter is loaded).
input is the current hidden-state vector before the LoRA correction.
output is incremented in-place: output += B @ (A @ input) * scaling.
Sourcepub fn active(&self) -> Option<&LoRAAdapter>
pub fn active(&self) -> Option<&LoRAAdapter>
Return a reference to the active adapter, if any.
Sourcepub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Clear the active adapter (revert to base model behaviour).
Sourcepub fn available_adapters(&self) -> Vec<ContextType>
pub fn available_adapters(&self) -> Vec<ContextType>
Check which adapters exist on disk (for UI / resource catalog).
Sourcepub fn save_adapter(
&self,
ctx: ContextType,
adapter: &LoRAAdapter,
) -> Result<PathBuf, LoRAError>
pub fn save_adapter( &self, ctx: ContextType, adapter: &LoRAAdapter, ) -> Result<PathBuf, LoRAError>
Persist an adapter to disk in the .lora binary format.
Sourcepub fn build_synthetic(
ctx: ContextType,
rank: u32,
alpha: f32,
n_in: usize,
n_out: usize,
adapter_id: u8,
) -> LoRAAdapter
pub fn build_synthetic( ctx: ContextType, rank: u32, alpha: f32, n_in: usize, n_out: usize, adapter_id: u8, ) -> LoRAAdapter
Build a synthetic adapter populated with Kaiming-uniform A / zero B weights. Used for fine-tuning initialisation and test harness.
Auto Trait Implementations§
impl Freeze for LoRAAdapterManager
impl RefUnwindSafe for LoRAAdapterManager
impl Send for LoRAAdapterManager
impl Sync for LoRAAdapterManager
impl Unpin for LoRAAdapterManager
impl UnsafeUnpin for LoRAAdapterManager
impl UnwindSafe for LoRAAdapterManager
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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