@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 1bf43ae35d
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 13, 22:00 UTC

[BugFix][LoRA] use adapter_id instead of id field of lora_request (#27728)

Signed-off-by: Biswa Panda <biswa.panda@gmail.com>

Biswa Panda committed Nov 2, 2025 at 18:08 UTC 1bf43ae35d7f6a83cc2025b8c0a2332456f4afe9
2 files changed +64 -3
tests/v1/core/test_prefix_caching.py
+61 -2
@@ -9,7 +9,8 @@ import pytest
9 import torch
10
11 import vllm.v1.core.kv_cache_utils as kv_cache_utils
12 -from vllm.distributed.kv_events import AllBlocksCleared, BlockRemoved
12 +from vllm.distributed.kv_events import AllBlocksCleared, BlockRemoved, BlockStored
13 +from vllm.lora.request import LoRARequest
14 from vllm.multimodal.inputs import (
15 MultiModalFeatureSpec,
16 MultiModalKwargsItem,
@@ -59,6 +60,7 @@ def make_request(
60 mm_hashes: list[str] | None = None,
61 prompt_logprobs: int | None = None,
62 cache_salt: str | None = None,
63 + lora_request: LoRARequest | None = None,
64 ):
65 mm_features = []
66 if mm_positions is not None:
@@ -79,7 +81,7 @@ def make_request(
81 sampling_params=SamplingParams(max_tokens=17, prompt_logprobs=prompt_logprobs),
82 pooling_params=None,
83 eos_token_id=100,
82 - lora_request=None,
84 + lora_request=lora_request,
85 cache_salt=cache_salt,
86 block_hasher=get_request_block_hasher(block_size, hash_fn),
87 )
@@ -1337,6 +1339,63 @@ def test_kv_cache_events(blocks_to_cache: int):
1339 assert len(manager.block_pool.cached_block_hash_to_block) == 0
1340
1341
1342 +@pytest.mark.parametrize("blocks_to_cache", [2, 3, 10])
1343 +def test_kv_cache_events_with_lora(blocks_to_cache: int):
1344 + """Test BlockStored events contain correct lora_id when using LoRA requests."""
1345 + block_size = 16
1346 + num_blocks = blocks_to_cache + 1
1347 +
1348 + # Create KVCacheManager with events enabled
1349 + manager = KVCacheManager(
1350 + make_kv_cache_config(block_size, num_blocks),
1351 + max_model_len=8192,
1352 + enable_caching=True,
1353 + enable_kv_cache_events=True,
1354 + )
1355 +
1356 + # Test with LoRA request
1357 + lora_request = LoRARequest(
1358 + lora_name="test_lora", lora_int_id=42, lora_path="/test/path"
1359 + )
1360 +
1361 + num_tokens = block_size * blocks_to_cache
1362 + req_with_lora = make_request(
1363 + "lora_req",
1364 + list(range(num_tokens)),
1365 + block_size,
1366 + sha256,
1367 + lora_request=lora_request,
1368 + )
1369 +
1370 + # Allocate slots and get events
1371 + _ = manager.allocate_slots(req_with_lora, num_tokens)
1372 + events = manager.take_events()
1373 +
1374 + # Verify BlockStored event contains correct lora_id
1375 + block_stored_event = events[-1]
1376 + assert isinstance(block_stored_event, BlockStored)
1377 + assert block_stored_event.lora_id == 42 # Should match lora_request.adapter_id
1378 + assert len(block_stored_event.block_hashes) == blocks_to_cache
1379 + assert block_stored_event.block_size == block_size
1380 +
1381 + # Clean up
1382 + manager.free(req_with_lora)
1383 +
1384 + # Test without LoRA request (should have lora_id=None)
1385 + req_without_lora = make_request(
1386 + "no_lora_req", list(range(num_tokens)), block_size, sha256
1387 + )
1388 +
1389 + _ = manager.allocate_slots(req_without_lora, num_tokens)
1390 + events = manager.take_events()
1391 +
1392 + block_stored_event = events[-1]
1393 + assert isinstance(block_stored_event, BlockStored)
1394 + assert block_stored_event.lora_id is None # Should be None when no LoRA request
1395 + assert len(block_stored_event.block_hashes) == blocks_to_cache
1396 + assert block_stored_event.block_size == block_size
1397 +
1398 +
1399 def test_eagle_enabled_removes_last_block():
1400 """Verify Eagle does NOT remove blocks when request
1401 length is divisible by block size."""
vllm/v1/core/block_pool.py
+3 -1
@@ -259,7 +259,9 @@ class BlockPool:
259 num_cached_blocks * block_size : num_full_blocks * block_size
260 ],
261 block_size=block_size,
262 - lora_id=request.lora_request.id if request.lora_request else None,
262 + lora_id=request.lora_request.adapter_id
263 + if request.lora_request
264 + else None,
265 medium=MEDIUM_GPU,
266 )
267 )