Skip to content

vllm.lora.layers.column_parallel_linear

Classes:

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

forward(input_)

Forward of ColumnParallelLinear

Parameters:

  • input_

    (Tensor) –

    Tensor whose last dimension is input_size.

Returns:

ColumnParallelLinearWithShardedLoRA

Bases: ColumnParallelLinearWithLoRA

Differs from ColumnParallelLinearWithLoRA by slicing LoRA A also.

Based on S-LoRA, slicing happens along the rank dim.

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(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.

_mcp_apply(x, bias, layer)

Fully-sharded (S-LoRA) apply path for column-parallel LoRA layers.