[Bugfix] fix KeyError on top logprobs are special tokens (#17637)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
Chauncey 2025-05-05 10:22:35 +08:00 committed by GitHub
parent 68e1ee0072
commit 5394ad7387
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1111,7 +1111,8 @@ class OpenAIServingChat(OpenAIServing):
return_as_token_id is not None else self.return_tokens_as_token_ids
for i, token_id in enumerate(token_ids):
step_top_logprobs = top_logprobs[i]
if step_top_logprobs is None:
if step_top_logprobs is None or step_top_logprobs.get(
token_id) is None:
token = tokenizer.decode(token_id)
if should_return_as_token_id:
token = f"token_id:{token_id}"