Fix streaming logprobs corruption caused by shared mutable list reference (#21030)

This commit is contained in:
Lianmin Zheng
2026-03-21 00:18:48 -07:00
committed by GitHub
parent d089db0563
commit dba6fb3d30
4 changed files with 36 additions and 48 deletions

View File

@@ -160,23 +160,20 @@ class TestOpenAIServer(CustomTestCase):
is_first = is_firsts.get(index, True)
if logprobs:
# When finish_reason is set, logprobs may be None if this chunk
# only contains buffered text being flushed (no new tokens generated).
# The detokenizer holds back text at word boundaries during streaming.
if response.choices[0].logprobs is not None:
assert response.choices[0].logprobs, f"no logprobs in response"
assert isinstance(
response.choices[0].logprobs.tokens[0], str
), f"{response.choices[0].logprobs.tokens[0]} is not a string"
if not (is_first and echo):
assert isinstance(
response.choices[0].logprobs.tokens[0], str
), f"{response.choices[0].logprobs.tokens[0]} is not a string"
if not (is_first and echo):
assert isinstance(
response.choices[0].logprobs.top_logprobs[0], dict
), f"top_logprobs was not a dictionary"
ret_num_top_logprobs = len(
response.choices[0].logprobs.top_logprobs[0]
)
# FIXME: Sometimes, some top_logprobs are missing in the return value. The reason is that some output id maps to the same output token and duplicate in the map
# assert ret_num_top_logprobs == logprobs, f"{ret_num_top_logprobs} vs {logprobs}"
assert ret_num_top_logprobs > 0, f"ret_num_top_logprobs was 0"
response.choices[0].logprobs.top_logprobs[0], dict
), f"top_logprobs was not a dictionary"
ret_num_top_logprobs = len(
response.choices[0].logprobs.top_logprobs[0]
)
# FIXME: Sometimes, some top_logprobs are missing in the return value. The reason is that some output id maps to the same output token and duplicate in the map
# assert ret_num_top_logprobs == logprobs, f"{ret_num_top_logprobs} vs {logprobs}"
assert ret_num_top_logprobs > 0, f"ret_num_top_logprobs was 0"
if is_first:
if echo: