[Bugfix] Accept logprobs=-1 in the Completion API (#46175)
Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
This commit is contained in:
@@ -476,6 +476,30 @@ def test_negative_prompt_token_ids_flat():
|
||||
)
|
||||
|
||||
|
||||
def test_logprobs_minus_one_allowed():
|
||||
"""logprobs=-1 means "return all logprobs". The sampling layer and the chat
|
||||
top_logprobs / prompt_logprobs validators all accept -1, so the completion
|
||||
logprobs validator must accept it too instead of rejecting it as negative."""
|
||||
request = CompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
prompt="Test prompt",
|
||||
max_tokens=10,
|
||||
logprobs=-1,
|
||||
)
|
||||
assert request.logprobs == -1
|
||||
|
||||
|
||||
def test_logprobs_below_minus_one_rejected():
|
||||
"""Values more negative than -1 stay invalid."""
|
||||
with pytest.raises(Exception, match="must be a positive value or -1"):
|
||||
CompletionRequest(
|
||||
model=MODEL_NAME,
|
||||
prompt="Test prompt",
|
||||
max_tokens=10,
|
||||
logprobs=-2,
|
||||
)
|
||||
|
||||
|
||||
class TestCompletionPromptListLimit:
|
||||
"""Regression tests for CVE: unbounded prompt list fan-out."""
|
||||
|
||||
|
||||
@@ -526,9 +526,13 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
parameter="prompt_logprobs",
|
||||
value=prompt_logprobs,
|
||||
)
|
||||
if (logprobs := data.get("logprobs")) is not None and logprobs < 0:
|
||||
if (
|
||||
(logprobs := data.get("logprobs")) is not None
|
||||
and logprobs < 0
|
||||
and logprobs != -1
|
||||
):
|
||||
raise VLLMValidationError(
|
||||
"`logprobs` must be a positive value.",
|
||||
"`logprobs` must be a positive value or -1.",
|
||||
parameter="logprobs",
|
||||
value=logprobs,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user