main
py 76 lines 2.42 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Test error handling in Processor. Should not impact other reqs."""
4
5 import asyncio
6
7 import pytest
8
9 from tests.v1.shutdown.utils import SHUTDOWN_TEST_TIMEOUT_SEC
10 from vllm import SamplingParams
11 from vllm.engine.arg_utils import AsyncEngineArgs
12 from vllm.inputs import ExplicitEncoderDecoderPrompt
13 from vllm.sampling_params import RequestOutputKind
14 from vllm.v1.engine.async_llm import AsyncLLM
15 from vllm.v1.engine.exceptions import EngineGenerateError
16
17 MODELS = ["meta-llama/Llama-3.2-1B"]
18
19
20 @pytest.mark.asyncio
21 @pytest.mark.timeout(SHUTDOWN_TEST_TIMEOUT_SEC)
22 @pytest.mark.parametrize("model", MODELS)
23 async def test_async_llm_processor_error(model: str) -> None:
24 """Test that AsyncLLM propagates a processor error.
25 Test empty tokens prompt (failure) and non-empty prompt (no failure.)
26 AsyncLLM always uses an MP client.
27 """
28 engine_args = AsyncEngineArgs(model=model, enforce_eager=True)
29 async_llm = AsyncLLM.from_engine_args(engine_args)
30
31 async def generate(request_id: str):
32 # An encoder/decoder prompt is rejected by the Processor for a
33 # decoder only model.
34 generator = async_llm.generate(
35 ExplicitEncoderDecoderPrompt(
36 encoder_prompt="Hello my name is", decoder_prompt=None
37 ),
38 request_id=request_id,
39 sampling_params=SamplingParams(),
40 )
41 try:
42 async for _ in generator:
43 pass
44 except Exception as e:
45 return e
46
47 NUM_REQS = 3
48 tasks = [generate(f"request-{idx}") for idx in range(NUM_REQS)]
49 outputs = await asyncio.gather(*tasks)
50
51 # Every request should have get an EngineGenerateError.
52 for output in outputs:
53 with pytest.raises(EngineGenerateError):
54 raise output
55
56 # AsyncLLM should be errored.
57 assert not async_llm.errored
58
59 # This should be no problem.
60 EXPECTED_TOKENS = 5
61 outputs = []
62 async for out in async_llm.generate(
63 "Hello my name is",
64 request_id="abc",
65 sampling_params=SamplingParams(
66 max_tokens=EXPECTED_TOKENS, output_kind=RequestOutputKind.DELTA
67 ),
68 ):
69 outputs.append(out)
70
71 generated_tokens = []
72 for out in outputs:
73 generated_tokens.extend(out.outputs[0].token_ids)
74 assert len(generated_tokens) == EXPECTED_TOKENS
75
76 async_llm.shutdown()