1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// RLX — versatile ML compiler + runtime.
// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
// SPDX-License-Identifier: MIT OR Apache-2.0
//! # rlx-peft — parameter-efficient adaptation on rlx graphs
//!
//! LoRA, IA3, AdaLoRA, DoRA and OFT, implemented as operations on an rlx graph
//! rather than as wrappers around another framework.
//!
//! ## Why here and not in a benchmark crate
//!
//! These are model transformations, not evaluation code. `W' = W + (α/r)·BA`
//! applies to any rlx model that has a linear layer — the fact that
//! OpenEEGBench happens to benchmark them is incidental. Putting them in rlx
//! makes them usable for adaptation, not just for reproducing someone's table.
//!
//! ## Semantics
//!
//! Each adapter here reproduces HuggingFace PEFT's definition, which is what
//! published results are measured under:
//!
//! | adapter | update | trainable |
//! |---|---|---|
//! | [`lora_delta`] | `W + (α/r)·B A` | `A ∈ ℝ^{r×in}`, `B ∈ ℝ^{out×r}` |
//! | [`ia3_apply`] | `(x Wᵀ) ⊙ l` | `l ∈ ℝ^{out}` |
//! | [`adalora_delta`] | `W + (α/r)·P diag(Λ) Q` | `P`, `Λ`, `Q`, with rank annealing |
//! | [`dora_weight`] | `m ⊙ (W + BA) / ‖W + BA‖_col` | `m ∈ ℝ^{out}` plus LoRA's `A`, `B` |
//! | [`oft`] | `R W`, `R` block-diagonal orthogonal | skew-symmetric `Q` per block |
//!
//! Two initialisation conventions matter and are reproduced rather than chosen:
//! **`B` starts at zero** so the adapted model is identical to the base model
//! at step 0 — a nonzero `B` perturbs a pretrained network before any training
//! and is a common source of "PEFT hurt my model" reports. And **IA3's `l`
//! starts at one**, for the same reason.
pub use ;
pub use ;
/// Trainable / total parameter accounting for an adapted model.
///
/// The denominator of every PEFT claim: "LoRA matches full fine-tuning" means
/// nothing without it.
/// Parameters a LoRA-style adapter adds to one `[out, in]` layer.
///
/// `r(in + out)` — the reason LoRA is cheap, and why the saving vanishes as `r`
/// approaches `min(in, out)`: at that point the factorisation costs more than
/// the matrix it is approximating.
/// Whether a rank is actually saving anything on this layer.
/// Row-major matmul helper shared by the adapters: `[m, k] × [k, n]`.
pub