Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Vllm project Vllm LoRARequest Init

From Leeroopedia


Knowledge Sources
Domains LLM Serving, Model Adaptation, Request Management
Last Updated 2026-02-08 13:00 GMT

Overview

Concrete tool for creating a LoRA adapter request descriptor provided by vllm.

Description

The LoRARequest class (defined at lines 8-67 of vllm/lora/request.py) is a msgspec.Struct that encapsulates the identity and location of a LoRA adapter for use in inference requests. It validates that lora_int_id is greater than 0 and that lora_path is non-empty in its __post_init__ method. Equality and hashing are overridden to use only lora_name, enabling consistent adapter identification across engine components.

The class also supports in-place adapter reloading via the load_inplace parameter, tensorizer-based loading via tensorizer_config_dict, and provides convenience properties (adapter_id, name, path) for accessing core fields.

Usage

Use this class to create a LoRA request object before submitting an inference request to the engine via LLMEngine.add_request(). Each adapter needs a unique lora_name and a unique lora_int_id. The lora_path should point to the directory containing the adapter weights (as returned by snapshot_download).

Code Reference

Source Location

  • Repository: vllm
  • File: vllm/lora/request.py (lines 8-67)

Signature

class LoRARequest(
    msgspec.Struct,
    omit_defaults=True,
    array_like=True,
):
    lora_name: str
    lora_int_id: int
    lora_path: str = ""
    base_model_name: str | None = None
    tensorizer_config_dict: dict | None = None
    load_inplace: bool = False

Import

from vllm.lora.request import LoRARequest

I/O Contract

Inputs

Name Type Required Description
lora_name str Yes Human-readable name for the LoRA adapter. Used for equality comparison and hashing.
lora_int_id int Yes Unique positive integer identifier (must be > 0). Used internally to index into adapter weight arrays.
lora_path str No Filesystem path to the directory containing adapter weights. Cannot be empty when provided. Default: "".
base_model_name str or None No Name of the base model this adapter was trained on. Default: None.
tensorizer_config_dict dict or None No Configuration dictionary for tensorizer-based adapter loading. Default: None.
load_inplace bool No If True, forces reloading the adapter even if one with the same lora_int_id is already cached. Default: False.

Outputs

Name Type Description
LoRARequest LoRARequest A validated LoRA request descriptor object ready to be passed to engine.add_request()

Usage Examples

Create LoRA Requests for Two Adapters

from vllm.lora.request import LoRARequest

# Create request for first adapter
lora_request_1 = LoRARequest("sql-lora", 1, lora_path)

# Create request for second adapter (same weights, different identity)
lora_request_2 = LoRARequest("sql-lora2", 2, lora_path)

# Equality is based on lora_name
assert lora_request_1 != lora_request_2  # Different names

Create LoRA Request with In-Place Reloading

from vllm.lora.request import LoRARequest

# Force reload of adapter weights even if already cached
lora_request = LoRARequest(
    lora_name="sql-lora",
    lora_int_id=1,
    lora_path="/path/to/adapter/weights",
    load_inplace=True,
)

Access Convenience Properties

from vllm.lora.request import LoRARequest

req = LoRARequest("sql-lora", 1, "/path/to/adapter")

# Convenience properties
print(req.adapter_id)  # 1 (same as lora_int_id)
print(req.name)        # "sql-lora" (same as lora_name)
print(req.path)        # "/path/to/adapter" (same as lora_path)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment