LoRA
30 memberslucid.peft.tuners.loralucid.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 and learns a
rank- update next to it, with .
starts at zero, so the adapted model starts as the base, and the update folds into 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.
Hu, Edward J., et al. "LoRA: Low-Rank Adaptation of Large Language Models." [arXiv:2106.09685](https://arxiv.org/abs/2106.09685), 2021.
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 from the top right-singular vectors.
Classes
MultiheadAttention25 methodsAn nn.MultiheadAttention with LoRA on its input and output projections.
LoraRuntimeConfigSettings that are valid at runtime only and never written to an adapter file.
Conv1d24 methodsAn nn.Conv1d with a LoRA update: lora_A (kernel , channels), then lora_B (1x1).
Conv2d24 methodsAn nn.Conv2d with a LoRA update: lora_A (kernel , channels), then lora_B (1x1).
Conv3d24 methodsAn nn.Conv3d with a LoRA update: lora_A (a 3-D kernel, channels), then lora_B (1x1x1).
ConvTranspose1d24 methodsAn nn.ConvTranspose1d with a LoRA update: lora_A (a transposed convolution to channels), then lora_B (1x1).
ConvTranspose2d24 methodsAn nn.ConvTranspose2d with a LoRA update: lora_A (a transposed convolution to channels), then lora_B (1x1).
ConvTranspose3d24 methodsAn nn.ConvTranspose3d with a LoRA update: lora_A (a 3-D transposed convolution to channels), then lora_B (1x1x1).
Embedding24 methodsAn nn.Embedding with a LoRA update: .
Linear25 methodsAn nn.Linear with a LoRA update: .
LoraLayer25 methodsAdapter bookkeeping shared by the LoRA layers.
QuantizedLinearA quantized linear module (QuantizedLinearMLX, nn.quantized.Linear, or dynamic.Linear) with a float LoRA update (QLoRA).
ParamWrapper25 methodsA LoRA update on one nn.Parameter of a module, for target_parameters.
EvaConfigConfiguration for Explained Variance Adaptation (EVA) data-driven LoRA initialisation.
LoftQConfigConfiguration stub for LoftQ quantisation-aware LoRA initialisation.
LoraConfig9 methodsHow lucid.peft.get_peft_model adapts a model with LoRA.
LoraGAConfigConfiguration for LoRA-GA (Gradient Approximation) initialisation.
LoraModel16 methodsA model with LoRA layers put into it, and the tools to take them out.
ArrowConfigOptions of Arrow, which routes each token to the best few of several LoRA adapters.
BdLoraConfigOptions of block-diagonal LoRA, which makes chosen LoRA factors block-diagonal.
KasaConfigOptions of KaSA, which gives the LoRA update a learned singular-value diagonal.
MontecloraConfigOptions of MonteCLoRA, which averages the LoRA update over Monte Carlo samples.
VeloraConfigOptions of VeLoRA, which keeps a compressed copy of each activation for the backward pass.
Functions
create_arrow_model→ PeftModelLoad saved LoRA adapters into base_model and add an Arrow router over them.
replace_lora_weights_loftq→ NoneRefused with NotImplementedError: 4-bit quantised LoRA layers are not implemented yet.
convert_to_lora→ tuple of (LoraConfig, dict of str to Tensor)Convert an additive PEFT adapter on model into a LoRA config and state dictionary.
save_as_lora→ NoneConvert an additive PEFT adapter on model into LoRA and save it to path.
get_eva_state_dict→ dict[str, Tensor]Compute top right singular vectors and redistributed ranks for EVA LoRA initialisation.
initialize_lora_eva_weights→ NoneInitialise LoRA layers of model in place with EVA singular vectors and redistributed ranks.
preprocess_loraga→ NoneEstimate and attach per-layer weight gradients on model before get_peft_model(..., LoraConfig(init_lora_weights='lora_ga')).