Skip to content

Commit b186149

Browse files
authored
[Bugfix][Frontend] validate arg priority in frontend LLM class before add request (vllm-project#27596)
Signed-off-by: Junpu Fan <[email protected]>
1 parent 2abbd35 commit b186149

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/entrypoints/llm/test_generate.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ def test_multiple_sampling_params(llm: LLM):
7171
assert len(PROMPTS) == len(outputs)
7272

7373

74+
def test_multiple_priority(llm: LLM):
75+
# Generate works when priority is None
76+
outputs = llm.generate(PROMPTS, sampling_params=None, priority=None)
77+
assert len(PROMPTS) == len(outputs)
78+
79+
# Generate works when length of priority is same as the len(PROMPTS)
80+
outputs = llm.generate(PROMPTS, sampling_params=None, priority=[0] * len(PROMPTS))
81+
assert len(PROMPTS) == len(outputs)
82+
83+
# Exception raised, if the length of priority does not match the length of prompts
84+
with pytest.raises(ValueError):
85+
outputs = llm.generate(
86+
PROMPTS, sampling_params=None, priority=[0] * (len(PROMPTS) - 1)
87+
)
88+
89+
# Exception raised, if the priority list is empty
90+
with pytest.raises(ValueError):
91+
outputs = llm.generate(PROMPTS, sampling_params=None, priority=[])
92+
93+
7494
def test_max_model_len():
7595
max_model_len = 20
7696
llm = LLM(

vllm/entrypoints/llm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,12 @@ def _validate_and_add_requests(
15651565
raise ValueError(
15661566
"The lengths of prompts and lora_request must be the same."
15671567
)
1568+
if priority is not None and len(priority) != num_requests:
1569+
raise ValueError(
1570+
"The lengths of prompts "
1571+
f"({num_requests}) and priority ({len(priority)}) "
1572+
"must be the same."
1573+
)
15681574

15691575
for sp in params if isinstance(params, Sequence) else (params,):
15701576
if isinstance(sp, SamplingParams):

0 commit comments

Comments
 (0)