Skip to content
module

LoRA

30 members
lucid.peft.tuners.lora

lucid.peft.tuners.lora — LoRA: a low-rank update learned beside each frozen weight.

LoRA (Hu et al., 2021, arXiv:2106.09685) freezes a pretrained weight WW and learns a rank-rr update next to it, y=Wx+s BAxy = W x + s\,B A x with s=α/rs = \alpha / r. BB starts at zero, so the adapted model starts as the base, and the update folds into WW on merge. It is the method to start with: it has a layer for every common module type and the widest set of options — DoRA (use_dora), rsLoRA, PiSSA and OLoRA starts, per-module ranks and alphas, and combining adapters (add_weighted_adapter).

Where the reference library keeps them, so isinstance(m, LoraLayer) and from lucid.peft.tuners.lora import Linear read as they do there. One layer type per module the method adapts: Linear, Embedding, the convolutions Conv1d / Conv2d / Conv3d and their transposes ConvTranspose1d / ConvTranspose2d / ConvTranspose3d, MultiheadAttention, and ParamWrapper for a raw parameter. LoraRuntimeConfig is the type of LoraConfig.runtime_config (settings valid at runtime only), and ArrowConfig, BdLoraConfig, KasaConfig, MontecloraConfig and VeloraConfig hold the options of the extensions LoraConfig has a field for and refuses to apply. LoraConfig and LoraModel are defined here too and exported from lucid.peft, which is where get_peft_model is. Importing the package registers the method (its config under PeftType.LORA, its tuner and layers), which is what makes get_peft_model and PeftModel.from_pretrained know it.

Paper

Hu, Edward J., et al. "LoRA: Low-Rank Adaptation of Large Language Models." [arXiv:2106.09685](https://arxiv.org/abs/2106.09685), 2021.

Overview

EVA (Paischer et al., 2024, arXiv:2410.07170) runs an incremental SVD over calibration activations to redistribute the LoRA rank budget across layers according to their explained variance ratios and initialise AA from the top right-singular vectors.

Classes

classMultiheadAttention25 methods

An nn.MultiheadAttention with LoRA on its input and output projections.

dataLoraRuntimeConfig

Settings that are valid at runtime only and never written to an adapter file.

classConv1d24 methods

An nn.Conv1d with a LoRA update: lora_A (kernel kk, rr channels), then lora_B (1x1).

classConv2d24 methods

An nn.Conv2d with a LoRA update: lora_A (kernel kh×kwk_h \times k_w, rr channels), then lora_B (1x1).

classConv3d24 methods

An nn.Conv3d with a LoRA update: lora_A (a 3-D kernel, rr channels), then lora_B (1x1x1).

classConvTranspose1d24 methods

An nn.ConvTranspose1d with a LoRA update: lora_A (a transposed convolution to rr channels), then lora_B (1x1).

classConvTranspose2d24 methods

An nn.ConvTranspose2d with a LoRA update: lora_A (a transposed convolution to rr channels), then lora_B (1x1).

classConvTranspose3d24 methods

An nn.ConvTranspose3d with a LoRA update: lora_A (a 3-D transposed convolution to rr channels), then lora_B (1x1x1).

classEmbedding24 methods

An nn.Embedding with a LoRA update: y=E[x]+s (A⊤[x]) B⊤y = E[x] + s\,(A^\top[x])\,B^\top.

classLinear25 methods

An nn.Linear with a LoRA update: y=Wx+b+s BA drop(x)y = W x + b + s\,B A\,\mathrm{drop}(x).

abstractLoraLayer25 methods

Adapter bookkeeping shared by the LoRA layers.

classQuantizedLinear

A quantized linear module (QuantizedLinearMLX, nn.quantized.Linear, or dynamic.Linear) with a float LoRA update (QLoRA).

classParamWrapper25 methods

A LoRA update on one nn.Parameter of a module, for target_parameters.

dataEvaConfig

Configuration for Explained Variance Adaptation (EVA) data-driven LoRA initialisation.

dataLoftQConfig

Configuration stub for LoftQ quantisation-aware LoRA initialisation.

dataLoraConfig9 methods

How lucid.peft.get_peft_model adapts a model with LoRA.

dataLoraGAConfig

Configuration for LoRA-GA (Gradient Approximation) initialisation.

classLoraModel16 methods

A model with LoRA layers put into it, and the tools to take them out.

dataArrowConfig

Options of Arrow, which routes each token to the best few of several LoRA adapters.

dataBdLoraConfig

Options of block-diagonal LoRA, which makes chosen LoRA factors block-diagonal.

dataKasaConfig

Options of KaSA, which gives the LoRA update a learned singular-value diagonal.

dataMontecloraConfig

Options of MonteCLoRA, which averages the LoRA update over Monte Carlo samples.

dataVeloraConfig

Options of VeLoRA, which keeps a compressed copy of each activation for the backward pass.

Functions