@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / a4fc21895e
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 14, 05:30 UTC

[Bugfix] Fixed when return_token_ids=False, the first event still contains prompt_token_ids. (#27561)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>

Chauncey committed Oct 27, 2025 at 19:06 UTC a4fc21895ed279930e5998eff4b9480da9d8442a
2 files changed +13 -3
tests/entrypoints/openai/test_return_token_ids.py
+12 -2
@@ -27,8 +27,12 @@ def server():
27
28
29 @pytest.mark.asyncio
30 -async def test_basic_completion_with_emoji(server):
30 +@pytest.mark.parametrize("return_token_ids", [True, False, None])
31 +async def test_basic_completion_with_emoji(server, return_token_ids: bool | None):
32 """Test basic completion with emoji to verify token_ids field."""
33 + extra_body = None
34 + if return_token_ids is not None:
35 + extra_body = {"return_token_ids": return_token_ids}
36 async with server.get_async_client() as client:
37 # Test with return_token_ids enabled
38 completion = await client.completions.create(
@@ -37,7 +41,7 @@ async def test_basic_completion_with_emoji(server):
41 max_tokens=10,
42 temperature=0,
43 logprobs=1,
40 - extra_body={"return_token_ids": True},
44 + extra_body=extra_body,
45 )
46
47 # Check the raw response to see the structure
@@ -45,6 +49,12 @@ async def test_basic_completion_with_emoji(server):
49
50 # Verify prompt_token_ids field is present in the completion response
51 assert "prompt_token_ids" in completion_dict["choices"][0]
52 + if not return_token_ids:
53 + # If return_token_ids is False, token_ids should not be present
54 + assert completion_dict["choices"][0].get("token_ids") is None
55 + assert completion_dict["choices"][0].get("prompt_token_ids") is None
56 + # Skip further checks
57 + return
58 assert isinstance(completion.choices[0].prompt_token_ids, list)
59
60 # Check against the expected prompt token IDs
vllm/entrypoints/openai/serving_completion.py
+1 -1
@@ -399,7 +399,7 @@ class OpenAIServingCompletion(OpenAIServing):
399
400 # has_echoed[i] is reused here to indicate whether
401 # we have already returned the prompt token IDs.
402 - if not has_echoed[i]:
402 + if not has_echoed[i] and request.return_token_ids:
403 prompt_token_ids_to_return = prompt_token_ids
404 has_echoed[i] = True
405