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 6, 17:00 UTC
[responsesAPI][ez] add a unit test for SimpleContext logprobs (#37126)
Signed-off-by: Andrew Xia <axia@meta.com>
Andrew Xia committed
Mar 15, 2026 at 17:12 UTC
e9163b536e721c431500f6f43ace22fcb3532e7e
1 file changed
+53
tests/entrypoints/openai/responses/test_simple.py
+53
@@ -137,6 +137,59 @@ async def test_streaming_output_consistency(client: OpenAI, model_name: str):
137
)
138
139
140
+@pytest.mark.asyncio
141
+@pytest.mark.parametrize("model_name", [MODEL_NAME])
142
+async def test_streaming_logprobs(client: OpenAI, model_name: str):
143
+ """Test that streaming with logprobs returns valid logprob data on
144
+ output_text.delta events and that top_logprobs has the requested count."""
145
+ response = await client.responses.create(
146
+ model=model_name,
147
+ input="Say hello.",
148
+ stream=True,
149
+ top_logprobs=3,
150
+ include=["message.output_text.logprobs"],
151
+ )
152
+
153
+ events = []
154
+ async for event in response:
155
+ events.append(event)
156
+
157
+ assert len(events) > 0
158
+
159
+ # Collect all output_text.delta events that carry logprobs
160
+ text_delta_events = [e for e in events if e.type == "response.output_text.delta"]
161
+ assert len(text_delta_events) > 0, "Expected at least one text delta event"
162
+
163
+ for delta_event in text_delta_events:
164
+ logprobs = delta_event.logprobs
165
+ assert logprobs is not None, "logprobs should be present on text delta events"
166
+ assert len(logprobs) > 0, "logprobs list should not be empty"
167
+ for lp in logprobs:
168
+ # Each logprob entry must have a token and a logprob value
169
+ assert lp.token is not None
170
+ assert isinstance(lp.logprob, float)
171
+ assert lp.logprob <= 0.0, f"logprob should be <= 0, got {lp.logprob}"
172
+ # top_logprobs should have up to 3 entries
173
+ assert lp.top_logprobs is not None
174
+ assert len(lp.top_logprobs) <= 3
175
+ for tl in lp.top_logprobs:
176
+ assert tl.token is not None
177
+ assert isinstance(tl.logprob, float)
178
+
179
+ # Verify that top_logprobs are actually populated, not always empty
180
+ all_top_logprobs = [
181
+ tl for e in text_delta_events for lp in e.logprobs for tl in lp.top_logprobs
182
+ ]
183
+ assert len(all_top_logprobs) > 0, (
184
+ "Expected at least one top_logprobs entry across all delta events"
185
+ )
186
+
187
+ # Verify the completed event still has valid output
188
+ completed = events[-1]
189
+ assert completed.type == "response.completed"
190
+ assert completed.response.status == "completed"
191
+
192
+
193
@pytest.mark.asyncio
194
@pytest.mark.parametrize("model_name", [MODEL_NAME])
195
async def test_streaming_reasoning_tokens_e2e(client: OpenAI, model_name: str):