pub struct QLoraConfig {
pub lora: LoraConfig,
pub quantization: QuantizationConfig,
pub target_modules: Vec<String>,
pub cache_dequantized: bool,
}Expand description
Configuration for QLoRA training and inference.
§Compute Dtype
CRITICAL: The compute_dtype field controls numerical precision during training.
BF16: Required for training - 100% stability rateFP16: Do NOT use for training - 20% failure rate due to numerical instabilityFP32: Stable but slower, useful for debugging
§Target Modules
The target_modules field controls which linear layers get LoRA adapters:
- Minimal:
["q_proj", "v_proj"]- 98% of full fine-tuning quality - Recommended:
["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]- Matches full fine-tuning quality (~99.3%)
§Example
use qlora_rs::QLoraConfig;
// Use preset for best stability
let config = QLoraConfig::preset_all_bf16(64, 16);
// Or customize
let config = QLoraConfig {
target_modules: vec!["q_proj".into(), "v_proj".into()],
..QLoraConfig::preset_all_bf16(32, 8)
};Fields§
§lora: LoraConfigLoRA configuration (rank, alpha, dropout).
quantization: QuantizationConfigQuantization configuration (block size, double quant).
target_modules: Vec<String>Target modules to apply LoRA to.
Default: all linear layers in transformer blocks.
cache_dequantized: boolWhether to cache dequantized weights (opt-in, for inference speedup). Default: false (on-the-fly dequantization saves memory).
Implementations§
Source§impl QLoraConfig
impl QLoraConfig
Sourcepub fn preset_all_bf16(r: usize, alpha: usize) -> QLoraConfig
pub fn preset_all_bf16(r: usize, alpha: usize) -> QLoraConfig
Create preset targeting all linear layers with BF16 compute.
Recommended for training. Matches QLoRA paper configuration.
§Arguments
r-LoRArank (typical: 8-64)alpha-LoRAscaling factor (typical: 16-32)
Sourcepub fn preset_qv_bf16(r: usize, alpha: usize) -> QLoraConfig
pub fn preset_qv_bf16(r: usize, alpha: usize) -> QLoraConfig
Create preset targeting only attention Q/V projections with BF16 compute.
Memory-optimal preset: fewer trainable parameters. Achieves ~98% of full fine-tuning quality.
Sourcepub fn preset_inference(r: usize, alpha: usize) -> QLoraConfig
pub fn preset_inference(r: usize, alpha: usize) -> QLoraConfig
Create preset for inference with weight caching enabled.
Uses cached dequantization for faster inference at cost of memory.
Sourcepub fn validate_for_training(&self) -> Result<(), QLoraError>
pub fn validate_for_training(&self) -> Result<(), QLoraError>
Validate configuration for training.
§Errors
Returns error if configuration is invalid for training.
Trait Implementations§
Source§impl Clone for QLoraConfig
impl Clone for QLoraConfig
Source§fn clone(&self) -> QLoraConfig
fn clone(&self) -> QLoraConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QLoraConfig
impl Debug for QLoraConfig
Source§impl Default for QLoraConfig
impl Default for QLoraConfig
Source§fn default() -> QLoraConfig
fn default() -> QLoraConfig
Default configuration: BF16 compute, all linear layers targeted.
Note: Default uses BF16 compute dtype for training stability.
Source§impl<'de> Deserialize<'de> for QLoraConfig
impl<'de> Deserialize<'de> for QLoraConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<QLoraConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<QLoraConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for QLoraConfig
impl Serialize for QLoraConfig
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for QLoraConfig
impl RefUnwindSafe for QLoraConfig
impl Send for QLoraConfig
impl Sync for QLoraConfig
impl Unpin for QLoraConfig
impl UnwindSafe for QLoraConfig
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