Skip to main content

tensorlogic_train/lora/
config.rs

1//! LoRA configuration.
2
3/// Configuration for a LoRA adapter layer.
4///
5/// LoRA (Low-Rank Adaptation, Hu et al., 2021) decomposes weight updates as
6/// `dW = B @ A` where `B in R^{d x r}`, `A in R^{r x k}`, and `r << min(d, k)`.
7/// The effective scaling factor applied is `alpha / rank`.
8#[derive(Debug, Clone)]
9pub struct LoraConfig {
10    /// Low-rank dimension r.
11    pub rank: usize,
12    /// Scaling factor: effective scaling = alpha / rank.
13    pub alpha: f64,
14    /// Dropout probability for training regularisation (0.0 = no dropout).
15    pub dropout: f64,
16    /// Which weight matrices to adapt (matched by name).
17    pub target_modules: Vec<String>,
18    /// RNG seed for reproducible A-matrix initialisation.
19    pub seed: u64,
20}
21
22impl Default for LoraConfig {
23    fn default() -> Self {
24        Self {
25            rank: 8,
26            alpha: 8.0,
27            dropout: 0.0,
28            target_modules: Vec::new(),
29            seed: 42,
30        }
31    }
32}