Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/openai/openai_frontend/engine/triton_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def _validate_chat_request(

# Logprobs are only supported for vLLM backend currently
if metadata.backend != "vllm" and (
request.logprobs is not None or request.top_logprobs is not None
request.logprobs or request.top_logprobs is not None
):
raise ClientError(
"logprobs are currently available only for the vLLM backend"
Expand Down
25 changes: 24 additions & 1 deletion python/openai/tests/test_chat_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ def test_chat_completions_sampling_parameters(
assert response.json()["detail"] == "logit bias is not currently supported"
return

# TRT-LLM backend doesn't support logprobs
if (
param_key == "logprobs"
and param_value is True
and model == "tensorrt_llm_bls"
):
assert response.status_code == 400
assert (
"logprobs are currently available only for the vLLM backend"
in response.json()["detail"]
)
return

assert response.status_code == 200
assert response.json()["choices"][0]["message"]["content"]
assert response.json()["choices"][0]["message"]["role"] == "assistant"
Expand Down Expand Up @@ -620,9 +633,19 @@ def test_chat_completions_logprobs_false(

@pytest.mark.parametrize("top_logprobs_value", [0, 5])
def test_chat_completions_top_logprobs_without_logprobs(
self, client, model: str, messages: List[dict], top_logprobs_value: int
self,
client,
model: str,
messages: List[dict],
top_logprobs_value: int,
backend: str,
):
"""Test that top_logprobs without logprobs raises validation error."""
if backend != "vllm":
pytest.skip(
reason="logprobs are currently available only for the vLLM backend"
)

response = client.post(
"/v1/chat/completions",
json={
Expand Down
13 changes: 13 additions & 0 deletions python/openai/tests/test_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ def test_completions_sampling_parameters(
assert response.json()["detail"] == "logit bias is not supported"
return

# TRT-LLM backend doesn't support logprobs
if (
sampling_parameter == "logprobs"
and value is not None
and model == "tensorrt_llm_bls"
):
assert response.status_code == 400
assert (
"logprobs are currently available only for the vLLM backend"
in response.json()["detail"]
)
return

assert response.status_code == 200
assert response.json()["choices"][0]["text"].strip()

Expand Down
6 changes: 6 additions & 0 deletions python/openai/tests/test_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ def _create_model_repository_mock_llm(self):
data_type: TYPE_BOOL
dims: [1]
optional: true
},
{
name: "return_logprobs"
data_type: TYPE_BOOL
dims: [1]
optional: true
}
]
output [
Expand Down
10 changes: 8 additions & 2 deletions python/openai/tests/test_openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ async def test_chat_completion_logprobs(

assert stream_tokens_list == non_stream_tokens_list, "Tokens should match"
assert np.allclose(
stream_logprobs_values, non_stream_logprobs_values, rtol=0, atol=1e-2
stream_logprobs_values, non_stream_logprobs_values, rtol=0, atol=1e-1
), "Logprob values should be close"

@pytest.mark.asyncio
Expand Down Expand Up @@ -658,7 +658,7 @@ async def test_completion_logprobs(
assert stream_text_offsets == logprobs.text_offset, "Text offsets should match"
assert stream_top_logprobs == logprobs.top_logprobs, "Top logprobs should match"
assert np.allclose(
stream_token_logprobs, logprobs.token_logprobs, rtol=0, atol=1e-2
stream_token_logprobs, logprobs.token_logprobs, rtol=0, atol=1e-1
), "Token logprob values should be close"

@pytest.mark.parametrize("top_logprobs_value", [0, 5])
Expand All @@ -669,10 +669,16 @@ async def test_top_logprobs_requires_logprobs(
model: str,
messages: List[dict],
top_logprobs_value: int,
backend: str,
):
"""
Test that top_logprobs without logprobs raises an error
"""
if backend != "vllm":
pytest.skip(
reason="logprobs are currently available only for the vLLM backend"
)

with pytest.raises(openai.BadRequestError) as exc_info:
await client.chat.completions.create(
model=model,
Expand Down
Loading