@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / e53be6f00a
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 15, 04:45 UTC

[Misc] Add type assertion of request_id for LLMEngine.add_request (#19700)

Signed-off-by: n2ptr <xuzhanchaomail@163.com>

Chales Xu committed Jun 28, 2025 at 13:47 UTC e53be6f00ab37c58d767e44d8ceef26e9defc743
3 files changed +14 -5
tests/mq_llm_engine/test_error_handling.py
+5 -5
@@ -66,7 +66,7 @@ async def test_evil_forward(tmp_socket):
66 with pytest.raises(MQEngineDeadError):
67 async for _ in client.generate(prompt="Hello my name is",
68 sampling_params=SamplingParams(),
69 - request_id=uuid.uuid4()):
69 + request_id=str(uuid.uuid4())):
70 pass
71 assert client.errored
72
@@ -115,7 +115,7 @@ async def test_failed_health_check(tmp_socket):
115 with pytest.raises(MQEngineDeadError):
116 async for _ in client.generate(prompt="Hello my name is",
117 sampling_params=SamplingParams(),
118 - request_id=uuid.uuid4()):
118 + request_id=str(uuid.uuid4())):
119 pass
120
121 client.close()
@@ -157,7 +157,7 @@ async def test_failed_abort(tmp_socket):
157 async for _ in client.generate(
158 prompt="Hello my name is",
159 sampling_params=SamplingParams(max_tokens=10),
160 - request_id=uuid.uuid4()):
160 + request_id=str(uuid.uuid4())):
161 pass
162 assert "KeyError" in repr(execinfo.value)
163 assert client.errored
@@ -189,7 +189,7 @@ async def test_batch_error(tmp_socket):
189 params = SamplingParams(min_tokens=2048, max_tokens=2048)
190 async for _ in client.generate(prompt="Hello my name is",
191 sampling_params=params,
192 - request_id=uuid.uuid4()):
192 + request_id=str(uuid.uuid4())):
193 pass
194
195 tasks = [asyncio.create_task(do_generate(client)) for _ in range(10)]
@@ -289,7 +289,7 @@ async def test_engine_process_death(tmp_socket):
289 with pytest.raises(MQEngineDeadError):
290 async for _ in client.generate(prompt="Hello my name is",
291 sampling_params=SamplingParams(),
292 - request_id=uuid.uuid4()):
292 + request_id=str(uuid.uuid4())):
293 pass
294
295 # And the health check should show the engine is dead
vllm/engine/llm_engine.py
+4
@@ -687,6 +687,10 @@ class LLMEngine:
687 >>> # continue the request processing
688 >>> ...
689 """
690 + if not isinstance(request_id, str):
691 + raise TypeError(
692 + f"request_id must be a string, got {type(request_id)}")
693 +
694 if lora_request is not None and not self.lora_config:
695 raise ValueError(f"Got lora_request {lora_request} but LoRA is "
696 "not enabled!")
vllm/v1/engine/llm_engine.py
+5
@@ -192,6 +192,11 @@ class LLMEngine:
192 prompt_adapter_request: Optional[PromptAdapterRequest] = None,
193 priority: int = 0,
194 ) -> None:
195 + # Validate the request_id type.
196 + if not isinstance(request_id, str):
197 + raise TypeError(
198 + f"request_id must be a string, got {type(request_id)}")
199 +
200 # Process raw inputs into the request.
201 prompt_str, request = self.processor.process_inputs(
202 request_id, prompt, params, arrival_time, lora_request,