vllm.lora.punica_wrapper.punica_gpu
¶
Based on: Chen, L., Ye, Z., Wu, Y., Zhuo, D., Ceze, L., & Krishnamurthy, A. (2023). Punica: Multi-Tenant LoRA Serving. https://arxiv.org/abs/2310.18547
Classes:
-
PunicaWrapperGPU–PunicaWrapperGPU is designed to manage and provide metadata for the punica
PunicaWrapperGPU
¶
Bases: PunicaWrapperBase
PunicaWrapperGPU is designed to manage and provide metadata for the punica kernel. The main function is to maintain the state information for Multi-LoRA, and to provide the interface for the punica triton kernel.
Methods:
-
add_expand–Performs GEMM for multiple slices of lora_b.
-
add_lora_embedding–Applies lora specifically for VocabParallelEmbeddingWithLoRA.
-
add_lora_fused_moe–Perform a fused forward computation for a LoRA MoE layer.
-
add_lora_linear–Applicable to linear-related lora.
-
add_lora_logits–Applies lora specifically for LogitsProcessorWithLoRA.
-
add_shrink–Performs GEMM for multiple slices of lora_a.
-
moe_lora_align_block_size–Aligns tokens and experts into block-sized chunks for LoRA-based
add_expand(y, x, lora_b_stacked, output_slices, offset_start=0, add_inputs=True, **kwargs)
¶
Performs GEMM for multiple slices of lora_b.
Semantics
for i in range(len(lora_b_stacked)): slice = output_slices[i] y[:, offset:offset+slice] += x[i] @ lora_b_stacked[i] offset += slice
Parameters:
-
(y¶Tensor) –Output tensor.
-
(x¶Tensor) –Input tensors
-
(lora_b_stacked¶tuple[Tensor, ...]) –lora_b's weight
-
(output_slices¶tuple[int, ...]) –Every slice's size
-
(offset_start¶int, default:0) –The starting position of y, defaults to 0.
-
(add_inputs¶bool, default:True) –If True, add LoRA output to y; if False, write LoRA-only output to y (used for dual-stream when base and LoRA run on different CUDA streams). Defaults to True.
-
(**kwargs¶Any, default:{}) –Unused; accepted for compatibility with the base class signature.
add_lora_embedding(y, x, lora_b_stacked, add_inputs=True, **kwargs)
¶
Applies lora specifically for VocabParallelEmbeddingWithLoRA.
Semantics
y += x @ lora_b_stacked
Parameters:
add_lora_fused_moe(y, x, lora_a_stacked, lora_b_stacked, topk_weights, sorted_token_ids, expert_ids, num_tokens_post_padded, max_lora_rank, top_k_num, shrink_config, expand_config, adapter_enabled, mul_routed_weight=False, fully_sharded=False, offset=0, token_lora_mapping=None, add_inputs=True)
¶
Perform a fused forward computation for a LoRA MoE layer.
add_lora_linear(y, x, lora_a_stacked, lora_b_stacked, scale, output_slices, *, buffer=None, **kwargs)
¶
Applicable to linear-related lora.
Semantics
for i in range(len(lora_a_stacked)): y[i] += ( x[i].unsqueeze(0) @ lora_a_stacked[indices[i], layer_idx, :, :] @ lora_b_stacked[indices[i], layer_idx, :, :] * scale ).squeeze(0)
Parameters:
-
(y¶Tensor) –Output tensor. Will be changed in-place.
-
(x¶Tensor) –Input tensor
-
(lora_a_stacked¶tuple[Tensor, ...]) –lora_a's weight.
-
(lora_b_stacked¶tuple[Tensor, ...]) –lora_b's weight.
-
(scale¶float) –Scaling factor.
-
(output_slices¶tuple[int, ...]) –Every slice's size.
-
(buffer¶Optional[Tensor], default:None) –Defaults to None.
-
(**kwargs¶Any, default:{}) –Accepts
add_inputs(bool, defaults to True); any other keys are ignored.
add_lora_logits(y, x, lora_a_stacked, lora_b_stacked, scale, *, buffer=None, **kwargs)
¶
Applies lora specifically for LogitsProcessorWithLoRA.
Semantics
buffer = (x @ lora_a_stacked) * scale y += buffer @ lora_b_stacked
Parameters:
-
(y¶Tensor) –Output tensor.
-
(x¶Tensor) –Input tensor.
-
(lora_a_stacked¶Tensor) –lora_a's weights.
-
(lora_b_stacked¶Tensor) –lora_b's weights.
-
(scale¶float) –Scaling factor.
-
(buffer¶Optional[Tensor], default:None) –Default to None.
-
(**kwargs¶Any, default:{}) –Unused; accepted for compatibility with the base class signature.
add_shrink(y, x, lora_a_stacked, scale, **kwargs)
¶
Performs GEMM for multiple slices of lora_a.
Semantics: for i in range(len(lora_a_stacked)): y[i] += (x @ lora_a_stacked[i]) * scale
Parameters:
moe_lora_align_block_size(topk_ids, num_tokens, block_size, num_experts, max_loras, adapter_enabled, expert_map=None, pad_sorted_ids=False, naive_block_assignment=False, token_lora_mapping=None)
¶
Aligns tokens and experts into block-sized chunks for LoRA-based mixture-of-experts (MoE) execution.
When token_lora_mapping is provided, it overrides the global mapping
read from self.token_mapping_meta. This is how EP+LoRA injects the
per-rank-local token→LoRA map after all-to-all dispatch.