A LoRA adapter has no container of its own: it is usually a
safetensors file whose tensor names and
shapes follow the conventions of the program that trained it. This page follows the
code of the two most common writers, Hugging Face
PEFT (tuners/lora/layer.py,
tuners/lora/config.py, config.py,
utils/constants.py, utils/save_and_load.py) and kohya-ss
sd-scripts/networks/lora.py,
all read 2026-11-12.
The two matrices
For an adapted linear layer with k inputs and d outputs,
PEFT creates lora_A as a linear layer from k to r
and lora_B from r to d, so the stored weights
are r × k and d × r. The layer’s output
gains B(A(x)) × scaling, where scaling is
lora_alpha / r, or lora_alpha / √r with
use_rslora. kohya-ss calls the same pair lora_down (A) and
lora_up (B), uses alpha / lora_dim as the scale, and
multiplies by a user multiplier as well. By default both start B at zero, so a fresh
adapter changes nothing. kohya-ss gives convolution layers a pair of convolutions
instead.
Hugging Face PEFT
| File | Holds |
|---|---|
adapter_model.safetensors | The adapter tensors (or adapter_model.bin, a PyTorch file, when not saved as safetensors). |
adapter_config.json | The LoraConfig as JSON. |
Tensor names are the model’s module path with lora_A or
lora_B inserted, such as
….q_proj.lora_A.weight. In memory the adapter’s name sits after it
(lora_A.default.weight); PEFT removes it when saving. On saving it warns
if a lora_A or lora_B tensor is empty or has fewer than two
dimensions, a sign of an unsharded save.
adapter_config.json key | Meaning |
|---|---|
peft_type | The method, LORA; the one key PEFT expects every config to have. |
task_type | The kind of task, or none. |
base_model_name_or_path, revision | The base model the adapter was trained on. |
r | The rank, default 8. |
lora_alpha | Alpha, default 8. |
lora_dropout | Dropout, default 0. |
target_modules | The module names or pattern adapted; all-linear is a shorthand. |
bias | none, all or lora_only. |
use_rslora | Use lora_alpha / √r as the scale. |
modules_to_save | Other modules saved in full with the adapter. |
rank_pattern, alpha_pattern | Per-module overrides of r and lora_alpha. |
use_dora | Weight-decomposed LoRA (DoRA). |
kohya-ss sd-scripts
- One file holds everything. Each adapted module’s name is a prefix, a dot, the module path, a dot and the child name, with every dot then replaced by an underscore.
- Prefixes:
lora_unetfor the image model andlora_tefor the text encoder; SDXL useslora_te1andlora_te2for its two text encoders. - Each module has
.lora_down.weight,.lora_up.weightand.alpha, a single-number tensor. - When saving as safetensors, the training metadata goes in the safetensors
__metadata__, withsshs_model_hashandsshs_legacy_hashadded; other extensions are saved withtorch.save.
All LoraConfig keys and PEFT tensor names
From PEFT config.py, tuners/lora/config.py,
tuners/lora/layer.py and utils/save_and_load.py (huggingface/peft
main, read 2026-11-13).
- File:
adapter_config.jsonis written withjson.dumps(…, indent=2), UTF-8, keys sorted, except that dicts underrank_pattern,alpha_patternandpaca_indices_patternkeep their order (the first matching key wins). A set is written as a list. The only key a reader requires ispeft_type.runtime_configis removed from the saved dictionary (it is not saved or restored). - Base keys (
PeftConfig):peft_type,task_type,auto_mapping(details for custom models),peft_version(filled in automatically),base_model_name_or_path,revision,inference_mode(bool, default false). - Tensor names the layer class defines (
LoraLayer.adapter_layer_names):lora_A,lora_B,lora_embedding_A,lora_embedding_B,lora_magnitude_vector(DoRA). Parameters that are not tensors saved here (other_param_names):r,lora_alpha,scaling,lora_dropout,use_dora,use_rslora,lora_bias. A saved key is<module path>.lora_A.weight(adapter name removed); an embedding adapter is<module path>.lora_embedding_A(no.weightsuffix) and.lora_embedding_B; the tensor-parallel loader's comment gives the state-dict shape oflora_embedding_Aas(rank, num_embeddings). KaSA adds alora_diagparameter between A and B (from thekasa_configdescription).
| Key (default) | Meaning |
|---|---|
r (8), lora_alpha (8), lora_dropout (0.0) | Rank, alpha, dropout probability. |
target_modules (null) | Module names to adapt: a string is a regex; a list is exact names or names ending with an entry; all-linear means every linear or Conv1D module except the output layer of a PreTrainedModel; [] targets no module (use target_parameters); unset means chosen from the architecture or an error. |
exclude_modules (null) | Names to leave out, matched the same way. |
target_parameters (null) | Names of nn.Parameters to adapt (for mixture-of-experts layers); no regex strings yet. |
fan_in_fan_out (false) | True when the layer stores weights as (fan_in, fan_out), for example GPT-2's Conv1D. |
bias (none) | none, all or lora_only: whether biases are trained too. |
lora_bias (false) | A bias term on the LoRA B parameter, mainly for adapters extracted from fully fine-tuned weights. |
use_rslora (false) | Scale by lora_alpha / √r instead of lora_alpha / r. |
modules_to_save (null) | Other modules trained and saved in full, such as a classifier head. |
init_lora_weights (true) | How adapters are initialised. True: Microsoft reference initialisation, B = 0, so the adapter does nothing before training. False: random A and B (for debugging). Strings: gaussian, eva, olora, pissa, pissa_niter_N (fast SVD with N subspace iterations), corda, astra, loftq, orthogonal (A and B orthogonal, needs even r, linear layers), mica (B from the smallest singular vectors, A zero, B frozen) and nora (A columns normalised to unit L2 norm, B zero); the config also mentions lora_ga. This only affects training; the saved tensors are ordinary A and B. |
layers_to_transform (null), layers_pattern (null) | Layer index or list of indices to adapt (only with target_modules a list), and the name of the nn.ModuleList (often layers or h) the indices refer to. |
rank_pattern, alpha_pattern ({}) | Name or regex to rank, and name or regex to alpha, overriding r and lora_alpha (for example {"^model.decoder.layers.0.encoder_attn.k_proj": 16}). |
layer_replication (null) | List of [start, end) layer ranges to stack so a model is expanded with shared base weights and separate adapters; ranges [[0, 4], [2, 5]] over 5 layers give 0, 1, 2, 3, 2, 3, 4. |
trainable_token_indices (null) | Token indices of the embedding to train, as a list or as a dict from embedding module name to a list. |
megatron_config, megatron_core (megatron.core) | For Megatron parallel linear layers; the config notes it may not be serialisable. |
loftq_config ({}) | LoftQ: loftq_bits (4) and loftq_iter (1). Use with init_lora_weights = "loftq"; the model must not be quantised already. |
eva_config, corda_config, astra_config, lora_ga_config | Settings for those initialisations (EVA has rho 2.0, tau 0.99, use_label_mask, label_mask_value, whiten, adjust_scaling_factors; CorDA has cache_file, covariance_file, corda_method ipm or kpm, verbose, prune_temporary_fields; Astra has cache_file, covariance_file, verbose, prune_temporary_fields; LoRA-GA's fields were not read). |
use_dora (false) | DoRA: a learnable magnitude vector (lora_magnitude_vector) beside the direction LoRA gives; linear and Conv2D layers only. |
velora_config, kasa_config, monteclora_config, use_bdlora, arrow_config | LoRA variants: VeLoRA (num_groups, scale, init_type of batch_average, batch_average_once, random), KaSA (beta, gamma), MonteCLoRA, BD-LoRA (target_modules_bd_a, target_modules_bd_b, nblocks, match_strict) and Arrow routing (top_k, router_temperature, use_gks, task_adapter_names, gks_adapter_names, rng_seed). |
alora_invocation_tokens (null) | Activated LoRA: the token ids of an invocation string; the adapter acts only on tokens from that string on, so the earlier KV cache is the base model's. Merging is not possible. |
use_qalora (false), qalora_group_size (16) | Quantisation-aware LoRA (GPTQ only for now, linear layers) and its pooling group size. |
ensure_weight_tying (false) | Tie the adapters of tied layers after initialisation (for modules_to_save, target_modules, trainable_token_indices). |
runtime_config | LoraRuntimeConfig (ephemeral_gpu_offload); not saved. |
LyCORIS and other formats
From the KohakuBlueleaf/LyCORIS modules locon.py, loha.py and
lokr.py (custom_state_dict methods) and wrapper.py, and
from Hugging Face diffusers loaders/lora_conversion_utils.py (read 2026-11-13).
- Names: each module is a prefix (
LORA_PREFIX, which a preset can change), an underscore and the module path, with every dot replaced by an underscore, as in kohya-ss. A file's modules are found by the part of each key before its first dot. - LoCon (
locon.py; the conv-capable LoRA):alpha,lora_up.weight(multiplied by a trainablescalarwhen one is used),lora_down.weight, andlora_mid.weightwhen a Tucker decomposition is used;dora_scalewhen weight decomposition is on. - LoHa (
loha.py, Hadamard product of two low-rank matrices):alpha,hada_w1_a(times the scalar),hada_w1_b,hada_w2_a,hada_w2_b, and for Tucker convolutionshada_t1andhada_t2;dora_scaleoptional. Shapes:w1_aandw2_aare[out, rank],w1_bandw2_b[rank, in]for a linear layer;t1,t2are[rank, rank, …kernel dims]. - LoKr (
lokr.py, Kronecker product):alpha, then for the first factor either a fulllokr_w1(times the scalar) or the pairlokr_w1_a(times the scalar) andlokr_w1_b; for the second factor eitherlokr_w2orlokr_w2_aandlokr_w2_bwithlokr_t2for a Tucker convolution;dora_scaleoptional. - Other LyCORIS algorithms present in the modules folder (
boft.py,diag_oft.py,dylora.py,full.py,glora.py,ia3.py,norms.py,tlora.py): their keys were not read. - diffusers conversion (
_convert_non_diffusers_lora_to_diffusers): looks for keys endinglora_down.weightwhose module name startslora_unet_(the U-Net),lora_te_orlora_te1_(the first text encoder) orlora_te2_(the second); the matchinglora_up.weightandalphaare looked up by the same module name, and adora_scaleentry becomeslora_magnitude_vector. For the U-Net the name is the key minuslora_unet_with every underscore turned into a dot, then fixed up for the model's module names; the output uses.down.and.up.names and a separate alpha dictionary. Other conversions in the same file (Flux and others) map to PEFT-stylelora_A.weightandlora_B.weightkeys.