[Bugfix] Return HTTP 500 for non-streaming generate errors (#49195)
Signed-off-by: WEI CHENG CHIU <waynehacking8@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from vllm.config.multimodal import MultiModalConfig
|
from vllm.config.multimodal import MultiModalConfig
|
||||||
from vllm.entrypoints.openai.engine.protocol import StreamOptions
|
from vllm.entrypoints.openai.engine.protocol import GenerationError, StreamOptions
|
||||||
from vllm.entrypoints.openai.models.protocol import BaseModelPath
|
from vllm.entrypoints.openai.models.protocol import BaseModelPath
|
||||||
from vllm.entrypoints.openai.models.serving import OpenAIServingModels
|
from vllm.entrypoints.openai.models.serving import OpenAIServingModels
|
||||||
from vllm.entrypoints.scale_out.token_in_token_out.protocol import (
|
from vllm.entrypoints.scale_out.token_in_token_out.protocol import (
|
||||||
@@ -229,6 +229,30 @@ async def test_serve_tokens_threads_session_id_header_to_engine():
|
|||||||
assert engine.generate.call_args.kwargs["session_id"] == "header-session"
|
assert engine.generate.call_args.kwargs["session_id"] == "header-session"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_non_stream_error():
|
||||||
|
"""finish_reason='error' raises for the HTTP exception handler."""
|
||||||
|
engine = _mock_engine()
|
||||||
|
|
||||||
|
async def mock_generate(*args, **kwargs):
|
||||||
|
yield _make_request_output(
|
||||||
|
"req-1", token_ids=[], finish_reason="error", finished=True
|
||||||
|
)
|
||||||
|
|
||||||
|
engine.generate = MagicMock(side_effect=mock_generate)
|
||||||
|
serving = _build_serving_tokens(engine)
|
||||||
|
|
||||||
|
request = GenerateRequest(
|
||||||
|
token_ids=[1, 2, 3],
|
||||||
|
sampling_params=SamplingParams(max_tokens=10),
|
||||||
|
model=MODEL_NAME,
|
||||||
|
stream=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(GenerationError):
|
||||||
|
await serving.serve_tokens(request)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_stream_basic():
|
async def test_stream_basic():
|
||||||
"""Streaming returns SSE chunks with correct token_ids and ends with [DONE]."""
|
"""Streaming returns SSE chunks with correct token_ids and ends with [DONE]."""
|
||||||
|
|||||||
@@ -288,6 +288,8 @@ class ServingTokens(GenerateBaseServing):
|
|||||||
choices: list[GenerateResponseChoice] = []
|
choices: list[GenerateResponseChoice] = []
|
||||||
num_generated_tokens = 0
|
num_generated_tokens = 0
|
||||||
for output in final_res.outputs:
|
for output in final_res.outputs:
|
||||||
|
self._raise_if_error(output.finish_reason, request_id)
|
||||||
|
|
||||||
token_ids = output.token_ids
|
token_ids = output.token_ids
|
||||||
out_logprobs = output.logprobs
|
out_logprobs = output.logprobs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user