diff --git a/python/openai/openai_frontend/engine/triton_engine.py b/python/openai/openai_frontend/engine/triton_engine.py index 179b963b57..9d515079b9 100644 --- a/python/openai/openai_frontend/engine/triton_engine.py +++ b/python/openai/openai_frontend/engine/triton_engine.py @@ -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" diff --git a/python/openai/tests/test_chat_completions.py b/python/openai/tests/test_chat_completions.py index e708689e0e..eee18bf354 100644 --- a/python/openai/tests/test_chat_completions.py +++ b/python/openai/tests/test_chat_completions.py @@ -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" @@ -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={ diff --git a/python/openai/tests/test_completions.py b/python/openai/tests/test_completions.py index ea1cf62166..4dcad4c2d2 100644 --- a/python/openai/tests/test_completions.py +++ b/python/openai/tests/test_completions.py @@ -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() diff --git a/python/openai/tests/test_lora.py b/python/openai/tests/test_lora.py index 550273cf52..d6322ee4b2 100644 --- a/python/openai/tests/test_lora.py +++ b/python/openai/tests/test_lora.py @@ -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 [ diff --git a/python/openai/tests/test_openai_client.py b/python/openai/tests/test_openai_client.py index e5ce4ae55e..62fc6bfa18 100644 --- a/python/openai/tests/test_openai_client.py +++ b/python/openai/tests/test_openai_client.py @@ -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 @@ -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]) @@ -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,