[Frontend] Support returning all prompt logprobs (#24956)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
Chauncey 2025-09-17 17:03:52 +08:00 committed by GitHub
parent bb58dc8c20
commit 544fe76b95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 8 deletions

View File

@ -22,6 +22,8 @@ def server():
"--enforce-eager",
"--max-model-len",
"4080",
"--max-logprobs", # test prompt_logprobs equal to -1
"151936"
]
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
@ -77,3 +79,23 @@ async def test_chat_session_with_echo_and_continue_final_message(
else:
assert message.content is not None and saying not in message.content
assert message.role == "assistant"
@pytest.mark.asyncio
async def test_prompt_logprobs(client: openai.AsyncOpenAI):
messages = [{
"role": "system",
"content": "You are a helpful assistant."
}, {
"role": "user",
"content": "Beijing is the capital of which country?"
}]
completion = await client.chat.completions.create(
model=MODEL_NAME,
messages=messages,
extra_body={"prompt_logprobs": -1},
)
assert completion.prompt_logprobs is not None
assert len(completion.prompt_logprobs) > 0

View File

@ -822,13 +822,17 @@ class ChatCompletionRequest(OpenAIBaseModel):
@classmethod
def check_logprobs(cls, data):
if (prompt_logprobs := data.get("prompt_logprobs")) is not None:
if data.get("stream") and prompt_logprobs > 0:
if data.get("stream") and (prompt_logprobs > 0
or prompt_logprobs == -1):
raise ValueError(
"`prompt_logprobs` are not available when `stream=True`.")
if prompt_logprobs < 0:
raise ValueError("`prompt_logprobs` must be a positive value.")
if prompt_logprobs < 0 and prompt_logprobs != -1:
raise ValueError(
"`prompt_logprobs` must be a positive value or -1.")
if prompt_logprobs == -1 and not envs.VLLM_USE_V1:
raise ValueError("`prompt_logprobs=-1` is only supported with "
"vLLM engine V1.")
if (top_logprobs := data.get("top_logprobs")) is not None:
if top_logprobs < 0:
raise ValueError("`top_logprobs` must be a positive value.")
@ -1246,13 +1250,17 @@ class CompletionRequest(OpenAIBaseModel):
@classmethod
def check_logprobs(cls, data):
if (prompt_logprobs := data.get("prompt_logprobs")) is not None:
if data.get("stream") and prompt_logprobs > 0:
if data.get("stream") and (prompt_logprobs > 0
or prompt_logprobs == -1):
raise ValueError(
"`prompt_logprobs` are not available when `stream=True`.")
if prompt_logprobs < 0:
raise ValueError("`prompt_logprobs` must be a positive value.")
if prompt_logprobs < 0 and prompt_logprobs != -1:
raise ValueError(
"`prompt_logprobs` must be a positive value or -1.")
if prompt_logprobs == -1 and not envs.VLLM_USE_V1:
raise ValueError("`prompt_logprobs=-1` is only supported with "
"vLLM engine V1.")
if (logprobs := data.get("logprobs")) is not None and logprobs < 0:
raise ValueError("`logprobs` must be a positive value.")