Skip to content

vllm.lora.model_manager

Classes:

Functions:

LRUCacheLoRAModelManager

Bases: LoRAModelManager

A model manager that manages multiple LoRAs with LRU cache.

Methods:

add_adapter(lora)

Add a LoRAModel to the manager.

pin_adapter(lora_id)

Pin a LoRAModel in the manager cache.

LoRAModelManager

A manager that manages multiple LoRA-fine-tuned models.

Methods:

__init__(model, max_num_seqs, max_num_batched_tokens, vocab_size, lora_config, device, vllm_config)

Create a LoRAModelManager and adapter for a given model.

Parameters:

  • model

    (SupportsLoRAModel) –

    the model to be adapted.

  • max_num_seqs

    (int) –

    the maximum number of sequences model can run in a single batch.

  • max_num_batched_tokens

    (int) –

    the maximum number of tokens model can run in a single batch.

  • vocab_size

    (int) –

    the vocab size of the model.

  • lora_config

    (LoRAConfig) –

    the LoRA configuration.

  • device

    (device) –

    the device the LoRA tensors are placed on.

  • vllm_config

    (VllmConfig) –

    the vLLM config for this engine.

_build_moe_ep_load_spec()

Per-rank slicing metadata for 2D RoutedEXperts LoRA modules.

_convert_3d_to_2d_moe_lora(lora_model, module, module_name)

Convert a 3D-format MoE LoRA checkpoint into the 2D pack layout that FusedMoEWithLoRA.set_lora expects.

On disk the 3D PEFT layout stores two flat tensor pairs per layer
  • {module}.base_layer.lora_{A,B}: gate_up_proj, with shapes (rank * num_experts, hidden) / (intermediate * 2, rank * num_experts)
  • {module}.lora_{A,B}: down_proj, with shapes (rank * num_experts, intermediate) / (hidden, rank * num_experts)

The 2D wrapper expects three stacked per-expert tensors, [w1, w2, w3], with (num_experts, rank, in) for lora_a and (num_experts, out, rank) for lora_b. In the 3D layout w1 (gate_proj) and w3 (up_proj) share the rank-r intermediate representation, so both halves use the same lora_a tensor.

Only invoked when enable_mixed_moe_lora_format=True and the source LoRARequest declares is_3d_lora_weight=True.

_get_punica_wrapper(module_name)

Determine whether this module supports LoRA and which wrapper to use.

_get_text_lora_names(module_name)

Names a text-only adapter uses for a language-model module.

Adapters trained on the text-only *ForCausalLM (e.g. PEFT on Qwen3_5ForCausalLM) name modules model.layers.* / lm_head, while multimodal wrappers mount the language model under a prefix such as language_model. or llm.. If the prefix holds a *ForCausalLM, the text name is the remainder; if it holds a bare decoder, it is the remainder under model..

_match_target_modules(module_name)

Check if a module passes the deployment-time target filter.

Parameters:

  • module_name

    (str) –

    Full dot-separated module name (e.g., "model.layers.0.self_attn.o_proj")

Returns:

  • bool –

    True if the module passes the filter, False otherwise.

_pad_lora_pairs_to_triplets(loras) staticmethod

Pad LoRA weight pairs to triplets for non-gated MoE.

For non-gated MoE, each expert has 2 entries (w1, w2) that need to be padded to triplets (w1, w2, None) to match pack_moe expectations.

_restrict_to_local_experts(module_name, new_module_names)

Narrow a flat expert-major sub-module list to this rank's experts.

new_module_names is produced by fused_moe_make_expert_params_mapping and is ordered [e=0,w1, e=0,w2, e=0,w3, e=1,w1, ...] (non-gated MoE has 2 entries per expert instead of 3). When the module is a 2D FusedMoEWithLoRA with EP enabled, we slice the list to the contiguous block of experts owned by this rank so the downstream pack_moe call only consumes local weights and produces a tensor sized to local_num_experts directly.

Returns the original list unchanged for non-MoE modules, the 3D MoE path (handled separately by _stack_moe_lora_weights), modules without EP, or layouts we cannot cleanly partition.

_slice_moe_lora_ep(lora_model, module, module_name)

Slice cached LoRA tensors down to this rank's local experts.

Shared factors have expert dimension one and remain available on every rank. Per-expert factors are narrowed to the local expert block.

activate_adapter(lora_id)

Move LoRA into a GPU buffer to be used in the forward pass.

create_dummy_lora(lora_id, rank, embedding_modules=None)

Create zero-initialized LoRAModel for warmup.

get_dummy_lora_warmup_rank(default_rank)

Return a dummy LoRA rank compatible with wrapped modules.

Dummy LoRAs keep warmup memory low by using a small rank. Fully sharded MoE wrappers additionally require the dummy rank to be divisible by tensor parallel size because they shard W13 along the rank axis.

pin_adapter(lora_id)

Pin a LoRAModel in the manager cache.

remove_all_adapters()

Remove all LoRAModels from the manager.

create_lora_manager(model, max_num_seqs, max_num_batched_tokens, vocab_size, lora_config, vllm_config, device, lora_manager_cls=LoRAModelManager, **kwargs)

Create a LoRA adapter for a given model.