Skip to content
module

VeRA

4 members
lucid.peft.tuners.vera

lucid.peft.tuners.vera — VeRA: two learned vectors per layer over shared random projections.

VeRA (Kopiczko et al., 2023, arXiv:2310.11454 — Vector-based Random Matrix Adaptation) draws one random pair AA, BB once and shares it, frozen, across every adapted layer; a layer learns only a vector λd\lambda_d of length r and a vector λb\lambda_b of its output width, y=Wx+λb⊙B(λd⊙Ax)y = Wx + \lambda_b\odot B(\lambda_d\odot Ax). Far fewer parameters than LoRA at the same rank, so ranks run much higher; the projections can be regenerated from projection_prng_key (save_projection=False), so a file can hold only the vectors. Pick it for the smallest adapters, or many adapters on one base.

Where the reference library keeps them, so isinstance(m, VeraLayer) and from lucid.peft.tuners.vera import VeraConfig, Linear read as they do there. One layer type for the one module the method adapts, nn.Linear. VeraConfig and VeraModel (which holds the shared projections) are here and exported from lucid.peft. Importing the package registers the method (its config under PeftType.VERA, its tuner and layer), which is what makes get_peft_model and PeftModel.from_pretrained know it.

Paper

Kopiczko, Dawid J., et al. "VeRA: Vector-based Random Matrix Adaptation." [arXiv:2310.11454](https://arxiv.org/abs/2310.11454), 2023.

Overview

VeRA (Kopiczko et al., 2023, arXiv:2310.11454 — Vector-based Random Matrix Adaptation) freezes the model and the low-rank pair: one random matrix A∈Rr×dinA \in \mathbb{R}^{r \times d_{in}} and one B∈Rdout×rB \in \mathbb{R}^{d_{out} \times r} are drawn once and shared by every targeted layer (sliced to its size), and a layer learns only two vectors,

λd∈Rr,  λb∈Rdout.\qquad \lambda_d \in \mathbb{R}^{r},\; \lambda_b \in \mathbb{R}^{d_{out}}.

Classes