vllm.lora.layers
¶
Modules:
-
base– -
base_linear– -
column_parallel_linear– -
custom_layer–LoRA implementations for specialized, model-specific layers.
-
fused_moe– -
logits_processor– -
replicated_linear– -
row_parallel_linear– -
utils–
Classes:
-
BaseLayerWithLoRA– -
ColumnParallelLinearWithLoRA–LoRA on top of ColumnParallelLinear layer.
-
ColumnParallelLinearWithShardedLoRA–Differs from ColumnParallelLinearWithLoRA by slicing LoRA A also.
-
DeepseekV4CompressorKVScoreWithLoRA–Adds the adapter delta to the compressor's FP32
wkv/wgateoutput. -
DeepseekV4GroupedWoAWithLoRA–Adds each head group's adapter delta to the grouped
wo_aprojection. -
FusedMoE3DWithLoRA– -
FusedMoEWithLoRA– -
Glm5NextIndexerWkWeightsWithLoRA–Adds the adapter delta to the GLM-5.3-Flash indexer's
kand FP32 -
LogitsProcessorWithLoRA–LoRA wrapper for LogitsProcessor, with extra logic to handle the
-
MLAKVBProjWithLoRA–kv_b_projof anMLAAttentionlayer, which marks it. -
MLAKVBProjWithShardedLoRA–Fully sharded variant: LoRA-A is sharded across TP ranks.
-
MergedColumnParallelLinearVariableSliceWithLoRA–MergedColumnParallelLinear with variable number of slices (3+).
-
MergedColumnParallelLinearWithLoRA–ColumnParallelLinear layer that is composed of 2 sublayers (slices)
-
MergedColumnParallelLinearWithShardedLoRA–Differs from MergedColumnParallelLinearWithLoRA by slicing the
-
MergedQKVParallelLinearWithLoRA–MergedColumnParallelLinear layer that is composed of 3 sublayers (slices)
-
MergedQKVParallelLinearWithShardedLoRA–Differs from MergedQKVParallelLinearWithLoRA by slicing the
-
QKVParallelLinearWithLoRA–ColumnParallelLinear layer that is specifically designed for
-
QKVParallelLinearWithShardedLoRA–Differs from QKVParallelLinearWithLoRA by slicing the
-
ReplicatedLinearWithLoRA– -
RowParallelLinearWithLoRA– -
RowParallelLinearWithShardedLoRA–Differs from RowParallelLinearWithLoRA by slicing the
BaseLayerWithLoRA
¶
Bases: Module
Methods:
-
can_replace_layer–Returns True if the layer can be replaced by this LoRA layer.
-
create_lora_weights–Initializes lora matrices.
-
load_weights–Load checkpoint weights into the wrapped base layer.
-
reset_lora–Resets the lora weights at index back to 0.
-
set_lora–Overwrites lora tensors at index.
-
slice_lora_a–Slice lora a if splitting for tensor parallelism.
-
slice_lora_b–Slice lora b if splitting with tensor parallelism.
can_replace_layer(source_layer, lora_config, packed_modules_list, model_config=None)
classmethod
¶
Returns True if the layer can be replaced by this LoRA layer.
create_lora_weights(max_loras, lora_config, model_config=None)
¶
Initializes lora matrices.
load_weights(weights)
¶
Load checkpoint weights into the wrapped base layer.
reset_lora(index)
¶
Resets the lora weights at index back to 0.
set_lora(index, lora_a, lora_b)
¶
Overwrites lora tensors at index.
ColumnParallelLinearWithLoRA
¶
Bases: BaseLinearLayerWithLoRA
LoRA on top of ColumnParallelLinear layer.
LoRA B is sliced for tensor parallelism.
There are two types for the base_layer:
1. ColumnParallelLinear, e.g.dense_h_to_4h in FalconForCausalLM.
2. MergedColumnParallelLinear, e.g.gate_up_proj in Phi3ForCausalLM.
Methods:
-
forward–Forward of ColumnParallelLinear
ColumnParallelLinearWithShardedLoRA
¶
Bases: ColumnParallelLinearWithLoRA
Differs from ColumnParallelLinearWithLoRA by slicing LoRA A also.
Based on S-LoRA, slicing happens along the rank dim.
DeepseekV4CompressorKVScoreWithLoRA
¶
Bases: MergedColumnParallelLinearWithLoRA
Adds the adapter delta to the compressor's FP32 wkv/wgate output.
DeepseekV4GroupedWoAWithLoRA
¶
Bases: ColumnParallelLinearWithLoRA
Adds each head group's adapter delta to the grouped wo_a projection.
All groups share LoRA-A; group g uses LoRA-B rows
g * o_lora_rank : (g + 1) * o_lora_rank, stored as its own buffer so
the kernels get a contiguous LoRA-B at a fixed address.
FusedMoE3DWithLoRA
¶
Bases: FusedMoEWithLoRA
Methods:
-
can_replace_layer–Returns True if the layer can be replaced by this LoRA layer.
-
create_lora_weights–Initializes lora matrices.
-
set_lora–Overwrites lora tensors at index.
Attributes:
-
w13_input_size–Full size.
-
w13_output_size–Full size.
-
w2_input_size–Full size.
-
w2_output_size–Full size.
w13_input_size
property
¶
Full size.
w13_output_size
property
¶
Full size.
w2_input_size
property
¶
Full size.
w2_output_size
property
¶
Full size.
can_replace_layer(source_layer, lora_config, packed_modules_list, model_config=None)
classmethod
¶
Returns True if the layer can be replaced by this LoRA layer.
create_lora_weights(max_loras, lora_config, model_config=None)
¶
Initializes lora matrices.
set_lora(index, lora_a, lora_b)
¶
Overwrites lora tensors at index.
FusedMoEWithLoRA
¶
Bases: BaseLayerWithLoRA
Methods:
-
can_replace_layer–Returns True if the layer can be replaced by this LoRA layer.
-
create_lora_weights–Initializes lora matrices.
-
reset_lora–Resets the lora weights at index back to 0.
-
set_lora–Overwrites lora tensors at index.
_tp_shard_size
property
¶
Match the base loader's shard stride before backend padding.
_w13_a_num_experts
property
¶
Expert-dim of the w13 lora_A buffer: 1 when shared.
_w2_b_num_experts
property
¶
Expert-dim of the w2 lora_B buffer: 1 when shared.
_match_expert_dim(src, buffer)
¶
Align a LoRA factor's expert-dim (dim 0) to its stacked buffer.
Equal dims pass through. When the buffer is collapsed to expert-dim 1 (a shared factor) but the source carries per-expert copies, keep the first — every expert shares the same factor, so the copies are identical for a real adapter and irrelevant (zeros) for the dummy.
_slice_w13_a(w13_lora_a)
¶
Applies to FusedMoEWithLoRA and FusedMoE3DWithLoRA.
_slice_w2_a(w2_lora_a)
¶
Applies to FusedMoEWithLoRA and FusedMoE3DWithLoRA.
_slice_w2_b(w2_lora_b)
¶
Applies to FusedMoEWithLoRA and FusedMoE3DWithLoRA.
can_replace_layer(source_layer, lora_config, packed_modules_list, model_config=None)
classmethod
¶
Returns True if the layer can be replaced by this LoRA layer.
create_lora_weights(max_loras, lora_config, model_config=None)
¶
Initializes lora matrices.
reset_lora(index)
¶
Resets the lora weights at index back to 0.
set_lora(index, lora_a, lora_b)
¶
Overwrites lora tensors at index.
Glm5NextIndexerWkWeightsWithLoRA
¶
Bases: MergedColumnParallelLinearWithLoRA
Adds the adapter delta to the GLM-5.3-Flash indexer's k and FP32
head gate.
LogitsProcessorWithLoRA
¶
Bases: BaseLayerWithLoRA
LoRA wrapper for LogitsProcessor, with extra logic to handle the application of the LoRA adapter.
Parameters:
-
(base_layer¶LogitsProcessor) –LogitsProcessor layer
-
(hidden_size¶int) –hidden size of the model
-
(dtype¶dtype) –data type of the model
-
(device¶device) –device of the model
-
(sharded_to_full_mapping¶list[int] | None) –index mapping from sharded vocab to full vocab received from base_layer.get_sharded_to_full_mapping(). If None, no reindexing will be done.
MLAKVBProjWithLoRA
¶
Bases: ColumnParallelLinearWithLoRA
kv_b_proj of an MLAAttention layer, which marks it.
Absorbed MLA folds kv_b_proj into the cached W_UK/W_UV, so the
attention layer adds the adapter after its BMMs instead of calling forward.
Methods:
-
apply_mla_absorbed_kv_b_lora–Add the adapter to MLA's absorbed, head-major projection.
apply_mla_absorbed_kv_b_lora(x, out, *, qk_nope_head_dim, is_query, gather_dcp=False)
¶
Add the adapter to MLA's absorbed, head-major projection.
Parameters:
-
(x¶Tensor) –[num_heads, num_tokens, dim]input of the absorbedW_UK(query) orW_UV(value) BMM. -
(out¶Tensor) –The token-major BMM output, updated in place.
-
(qk_nope_head_dim¶int) –Per-head rows of LoRA-B before the value rows.
-
(is_query¶bool) –Whether
xis the query side. -
(gather_dcp¶bool, default:False) –Gather LoRA-B heads across decode context parallel ranks.
MLAKVBProjWithShardedLoRA
¶
Bases: MLAKVBProjWithLoRA, ColumnParallelLinearWithShardedLoRA
Fully sharded variant: LoRA-A is sharded across TP ranks.
MergedColumnParallelLinearVariableSliceWithLoRA
¶
Bases: MergedColumnParallelLinearWithLoRA
MergedColumnParallelLinear with variable number of slices (3+).
This handles cases where the checkpoint has a single weight for the whole module (not split into slices), but the layer itself has multiple slices.
Methods:
-
set_lora–Override to handle single tensor weights
set_lora(index, lora_a, lora_b)
¶
Override to handle single tensor weights that need to be split into slices.
MergedColumnParallelLinearWithLoRA
¶
Bases: ColumnParallelLinearWithLoRA
ColumnParallelLinear layer that is composed of 2 sublayers (slices) packed together (e.g. gate_proj + up_proj -> gate_up_proj).
This means we have 2 LoRAs, each applied to one half of the layer.
Both slices must have the same size.
Methods:
-
create_lora_weights–The main reason for overriding this function is to enhance code
-
expand_packed_lora–Expand packed adapter groups when they don't match n_slices.
create_lora_weights(max_loras, lora_config, model_config=None)
¶
The main reason for overriding this function is to enhance code maintainability.
expand_packed_lora(lora_a, lora_b)
¶
Expand packed adapter groups when they don't match n_slices. E.g. in_proj_qkv (covers Q+K+V) + in_proj_z.
A None group member means that member was not adapted; the slice(s) it covers are emitted as None placeholders so the other groups stay aligned and those slices are left at base weights. This matches the None-tolerance already present in slice_lora_b() and the set_lora() stacking loop.
MergedColumnParallelLinearWithShardedLoRA
¶
Bases: MergedColumnParallelLinearWithLoRA
Differs from MergedColumnParallelLinearWithLoRA by slicing the LoRA A's also.
Based on S-LoRA, slicing happens along the rank dim.
MergedQKVParallelLinearWithLoRA
¶
Bases: MergedColumnParallelLinearWithLoRA
MergedColumnParallelLinear layer that is composed of 3 sublayers (slices) packed together in qkv proj fashion (q_proj + k_proj + v_proj -> qkv_proj).
This means we have 3 LoRAs, each applied to one slice of the layer.
Q slice may have different shape than K and V slices (which both have the same shape).
Methods:
-
create_lora_weights–The main reason for overloading this function is to handle inconsistent
create_lora_weights(max_loras, lora_config, model_config=None)
¶
The main reason for overloading this function is to handle inconsistent weight dimensions in qkv lora.
MergedQKVParallelLinearWithShardedLoRA
¶
Bases: MergedQKVParallelLinearWithLoRA
Differs from MergedQKVParallelLinearWithLoRA by slicing the LoRA A's also.
Based on S-LoRA, slicing happens along the rank dim.
QKVParallelLinearWithLoRA
¶
Bases: ColumnParallelLinearWithLoRA
ColumnParallelLinear layer that is specifically designed for qkv_proj. Certain models, such as chatglm3 and baichuan-7b, only contains a single LoRA within their qkv_proj layer.
During inference with Tensor Parallel, the weights of lora_b must be accurately partitioned according to the respective ranks.
Q slice may have different shape than K and V slices (which both have the same shape).
QKVParallelLinearWithShardedLoRA
¶
Bases: QKVParallelLinearWithLoRA
Differs from QKVParallelLinearWithLoRA by slicing the LoRA A's also.
Based on S-LoRA, slicing happens along the rank dim.
ReplicatedLinearWithLoRA
¶
Bases: BaseLinearLayerWithLoRA
Methods:
-
forward–Forward of ReplicatedLinearWithLoRA.
-
slice_lora_a–Slice lora a if splitting for tensor parallelism.
-
slice_lora_b–Slice lora b if splitting with tensor parallelism.
RowParallelLinearWithLoRA
¶
RowParallelLinearWithShardedLoRA
¶
Bases: RowParallelLinearWithLoRA
Differs from RowParallelLinearWithLoRA by slicing the LoRA B's also.
Based on S-LoRA, slicing happens along the output dim. This yields a combined partial sum from the row parallel base layer and column partitioned output from the LoRA.