Skip to content

Commit d889367

Browse files
varun-sundar-rabindranathVarun Sundar Rabindranath
authored andcommitted
[V1] LoRA - Enable more V1 tests (vllm-project#14315)
Signed-off-by: Varun Sundar Rabindranath <[email protected]> Co-authored-by: Varun Sundar Rabindranath <[email protected]>
1 parent 6e0976e commit d889367

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

tests/lora/test_chatglm3_tp.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def v1(run_with_both_engines_lora):
5555
pass
5656

5757

58-
@pytest.mark.skip_v1
5958
@fork_new_process_for_each_test
6059
def test_chatglm3_lora(chatglm3_lora_files):
6160
llm = vllm.LLM(MODEL_PATH,
@@ -75,7 +74,6 @@ def test_chatglm3_lora(chatglm3_lora_files):
7574
assert output2[i] == EXPECTED_LORA_OUTPUT[i]
7675

7776

78-
@pytest.mark.skip_v1
7977
@multi_gpu_test(num_gpus=4)
8078
@fork_new_process_for_each_test
8179
def test_chatglm3_lora_tp4(chatglm3_lora_files):
@@ -97,7 +95,6 @@ def test_chatglm3_lora_tp4(chatglm3_lora_files):
9795
assert output2[i] == EXPECTED_LORA_OUTPUT[i]
9896

9997

100-
@pytest.mark.skip_v1
10198
@multi_gpu_test(num_gpus=4)
10299
@fork_new_process_for_each_test
103100
def test_chatglm3_lora_tp4_fully_sharded_loras(chatglm3_lora_files):

tests/lora/test_mixtral.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
MODEL_PATH = "mistralai/Mixtral-8x7B-Instruct-v0.1"
1111

1212

13+
@pytest.fixture(autouse=True)
14+
def v1(run_with_both_engines_lora):
15+
# Simple autouse wrapper to run both engines for each test
16+
# This can be promoted up to conftest.py to run for every
17+
# test in a package
18+
pass
19+
20+
1321
def do_sample(llm: vllm.LLM, lora_path: str, lora_id: int,
1422
prompts: list[str]) -> list[str]:
1523

tests/lora/test_qwen2vl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
from vllm.platforms import current_platform
1313

1414

15+
@pytest.fixture(autouse=True)
16+
def v1(run_with_both_engines_lora):
17+
# Simple autouse wrapper to run both engines for each test
18+
# This can be promoted up to conftest.py to run for every
19+
# test in a package
20+
pass
21+
22+
1523
@dataclass
1624
class TestConfig:
1725
model_path: str

tests/lora/test_ultravox.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from os import path
55
from tempfile import TemporaryDirectory
66

7+
import pytest
78
import torch
89
from huggingface_hub import snapshot_download
910
from safetensors.torch import load_file, save_file
@@ -21,6 +22,14 @@
2122
PROMPT = "Tell me about a Fool's mate move in 20 words. Provide the moves!"
2223

2324

25+
@pytest.fixture(autouse=True)
26+
def v1(run_with_both_engines_lora):
27+
# Simple autouse wrapper to run both engines for each test
28+
# This can be promoted up to conftest.py to run for every
29+
# test in a package
30+
pass
31+
32+
2433
def llama3_1_8b_chess_lora_path():
2534
return snapshot_download(
2635
repo_id="mkopecki/chess-lora-adapter-llama-3.1-8b")

tests/lora/test_worker.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,45 @@
33
import os
44
import random
55
import tempfile
6+
from typing import Union
67
from unittest.mock import patch
78

9+
import pytest
10+
11+
import vllm.envs as envs
812
from vllm.config import (CacheConfig, DeviceConfig, LoadConfig, LoRAConfig,
913
ModelConfig, ParallelConfig, SchedulerConfig,
1014
VllmConfig)
1115
from vllm.lora.models import LoRAMapping
1216
from vllm.lora.request import LoRARequest
17+
from vllm.v1.worker.gpu_worker import Worker as V1Worker
1318
from vllm.worker.worker import Worker
1419

1520

21+
@pytest.fixture(autouse=True)
22+
def v1(run_with_both_engines_lora):
23+
# Simple autouse wrapper to run both engines for each test
24+
# This can be promoted up to conftest.py to run for every
25+
# test in a package
26+
pass
27+
28+
1629
@patch.dict(os.environ, {"RANK": "0"})
1730
def test_worker_apply_lora(sql_lora_files):
31+
32+
def set_active_loras(worker: Union[Worker, V1Worker],
33+
lora_requests: list[LoRARequest]):
34+
lora_mapping = LoRAMapping([], [])
35+
if isinstance(worker, Worker):
36+
# v0 case
37+
worker.model_runner.set_active_loras(lora_requests, lora_mapping)
38+
else:
39+
# v1 case
40+
worker.model_runner.lora_manager.set_active_adapters(
41+
lora_requests, lora_mapping)
42+
43+
worker_cls = V1Worker if envs.VLLM_USE_V1 else Worker
44+
1845
vllm_config = VllmConfig(
1946
model_config=ModelConfig(
2047
"meta-llama/Llama-2-7b-hf",
@@ -40,24 +67,25 @@ def test_worker_apply_lora(sql_lora_files):
4067
lora_config=LoRAConfig(max_lora_rank=8, max_cpu_loras=32,
4168
max_loras=32),
4269
)
43-
worker = Worker(
70+
worker = worker_cls(
4471
vllm_config=vllm_config,
4572
local_rank=0,
4673
rank=0,
4774
distributed_init_method=f"file://{tempfile.mkstemp()[1]}",
4875
)
76+
4977
worker.init_device()
5078
worker.load_model()
5179

52-
worker.model_runner.set_active_loras([], LoRAMapping([], []))
80+
set_active_loras(worker, [])
5381
assert worker.list_loras() == set()
5482

5583
n_loras = 32
5684
lora_requests = [
5785
LoRARequest(str(i + 1), i + 1, sql_lora_files) for i in range(n_loras)
5886
]
5987

60-
worker.model_runner.set_active_loras(lora_requests, LoRAMapping([], []))
88+
set_active_loras(worker, lora_requests)
6189
assert worker.list_loras() == {
6290
lora_request.lora_int_id
6391
for lora_request in lora_requests
@@ -69,8 +97,7 @@ def test_worker_apply_lora(sql_lora_files):
6997
k=random.randint(1, n_loras))
7098
random.shuffle(iter_lora_requests)
7199
iter_lora_requests = iter_lora_requests[:-random.randint(0, n_loras)]
72-
worker.model_runner.set_active_loras(iter_lora_requests,
73-
LoRAMapping([], []))
100+
set_active_loras(worker, lora_requests)
74101
assert worker.list_loras().issuperset(
75102
{lora_request.lora_int_id
76103
for lora_request in iter_lora_requests})

0 commit comments

Comments
 (0)