Skip to content

Commit 152c913

Browse files
authored
[Frontend] Log output token IDs at DEBUG level (#52098)
Signed-off-by: ruirui6946 <142162413+ruirui6946@users.noreply.github.com>
1 parent 015660d commit 152c913

3 files changed

Lines changed: 52 additions & 25 deletions

File tree

tests/entrypoints/serve/utils/test_request_logger.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33

4+
import logging
45
from unittest.mock import MagicMock, patch
56

67
from vllm.entrypoints.serve.utils.request_logger import RequestLogger
@@ -27,10 +28,10 @@ def test_request_logger_log_outputs():
2728
mock_logger.info.assert_called_once()
2829
call_args = mock_logger.info.call_args.args
2930
assert "Generated response %s%s" in call_args[0]
31+
assert "output_token_ids" not in call_args[0]
3032
assert call_args[1] == "test-123"
3133
assert call_args[3] == "Hello, world!"
32-
assert call_args[4] == [1, 2, 3, 4]
33-
assert call_args[5] == "stop"
34+
assert call_args[4] == "stop"
3435

3536

3637
def test_request_logger_log_outputs_streaming_delta():
@@ -56,8 +57,7 @@ def test_request_logger_log_outputs_streaming_delta():
5657
assert call_args[1] == "test-456"
5758
assert call_args[2] == " (streaming delta)"
5859
assert call_args[3] == "Hello"
59-
assert call_args[4] == [1]
60-
assert call_args[5] is None
60+
assert call_args[4] is None
6161

6262

6363
def test_request_logger_log_outputs_streaming_complete():
@@ -83,8 +83,7 @@ def test_request_logger_log_outputs_streaming_complete():
8383
assert call_args[1] == "test-789"
8484
assert call_args[2] == " (streaming complete)"
8585
assert call_args[3] == "Complete response"
86-
assert call_args[4] == [1, 2, 3]
87-
assert call_args[5] == "length"
86+
assert call_args[4] == "length"
8887

8988

9089
def test_request_logger_log_outputs_with_truncation():
@@ -117,11 +116,37 @@ def test_request_logger_log_outputs_with_truncation():
117116
assert len(logged_output) == 10
118117

119118
# Check that token IDs were truncated to first 10 tokens
120-
logged_token_ids = call_args[0][4]
119+
mock_logger.debug.assert_called_once()
120+
logged_token_ids = mock_logger.debug.call_args.args[3]
121121
assert logged_token_ids == list(range(10))
122122
assert len(logged_token_ids) == 10
123123

124124

125+
def test_request_logger_log_output_token_ids_require_debug():
126+
mock_logger = MagicMock()
127+
mock_logger.isEnabledFor.side_effect = lambda level: level >= logging.INFO
128+
129+
with patch("vllm.entrypoints.serve.utils.request_logger.logger", mock_logger):
130+
request_logger = RequestLogger(max_log_len=4)
131+
132+
request_logger.log_outputs(
133+
request_id="test-no-token-ids",
134+
outputs="Test output",
135+
output_token_ids=[1, 2, 3],
136+
finish_reason="stop",
137+
)
138+
139+
mock_logger.info.assert_called_once()
140+
assert mock_logger.info.call_args.args == (
141+
"Generated response %s%s: output: %r, finish_reason: %s",
142+
"test-no-token-ids",
143+
"",
144+
"Test",
145+
"stop",
146+
)
147+
mock_logger.debug.assert_not_called()
148+
149+
125150
def test_request_logger_log_outputs_none_values():
126151
"""Test log_outputs handles None values correctly."""
127152
mock_logger = MagicMock()
@@ -144,8 +169,7 @@ def test_request_logger_log_outputs_none_values():
144169
assert "Generated response %s%s" in call_args[0]
145170
assert call_args[1] == "test-none"
146171
assert call_args[3] == "Test output"
147-
assert call_args[4] is None
148-
assert call_args[5] == "stop"
172+
assert call_args[4] == "stop"
149173

150174

151175
def test_request_logger_log_outputs_empty_output():
@@ -170,8 +194,7 @@ def test_request_logger_log_outputs_empty_output():
170194
assert "Generated response %s%s" in call_args[0]
171195
assert call_args[1] == "test-empty"
172196
assert call_args[3] == ""
173-
assert call_args[4] == []
174-
assert call_args[5] == "stop"
197+
assert call_args[4] == "stop"
175198

176199

177200
def test_request_logger_log_outputs_integration():
@@ -245,4 +268,4 @@ def test_streaming_complete_logs_full_text_content():
245268
# Verify other parameters
246269
assert call_args[1] == "test-streaming-full-text"
247270
assert call_args[2] == " (streaming complete)"
248-
assert call_args[5] == "streaming_complete"
271+
assert call_args[4] == "streaming_complete"

vllm/entrypoints/openai/cli_args.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ class BaseFrontendArgs:
141141
"""Enable the `/tokenizer_info` endpoint. May expose chat
142142
templates and other tokenizer configuration."""
143143
enable_log_outputs: bool = False
144-
"""If set to True, log model outputs (generations).
145-
Requires `--enable-log-requests`. As with `--enable-log-requests`,
146-
information is only logged at INFO level at maximum."""
144+
"""If set to True, log model outputs (generations). Requires
145+
`--enable-log-requests`. Output text and finish reasons are logged at INFO,
146+
while output token IDs are logged at DEBUG."""
147147
enable_log_deltas: bool = True
148148
"""If set to False, output deltas will not be logged. Relevant only if
149149
--enable-log-outputs is set.

vllm/entrypoints/serve/utils/request_logger.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,28 @@ def log_outputs(
7777
delta: bool = False,
7878
) -> None:
7979
max_log_len = self.max_log_len
80-
if max_log_len is not None:
81-
if outputs is not None:
82-
outputs = outputs[:max_log_len]
83-
84-
if output_token_ids is not None:
85-
# Convert to list and apply truncation
86-
output_token_ids = list(output_token_ids)[:max_log_len]
80+
if max_log_len is not None and outputs is not None:
81+
outputs = outputs[:max_log_len]
8782

8883
stream_info = ""
8984
if is_streaming:
9085
stream_info = " (streaming delta)" if delta else " (streaming complete)"
9186

87+
if logger.isEnabledFor(logging.DEBUG):
88+
if max_log_len is not None and output_token_ids is not None:
89+
output_token_ids = list(output_token_ids)[:max_log_len]
90+
91+
logger.debug(
92+
"Generated response %s%s details: output_token_ids: %s",
93+
request_id,
94+
stream_info,
95+
output_token_ids,
96+
)
97+
9298
logger.info(
93-
"Generated response %s%s: output: %r, "
94-
"output_token_ids: %s, finish_reason: %s",
99+
"Generated response %s%s: output: %r, finish_reason: %s",
95100
request_id,
96101
stream_info,
97102
outputs,
98-
output_token_ids,
99103
finish_reason,
100104
)

0 commit comments

Comments
 (0)