fix(sglang): treat streamed usage metadata as optional#11062
Conversation
Signed-off-by: Kirill Shkolenko <shkolenko.kirill@gmail.com>
|
👋 Hi Cirilus! Thank you for contributing to ai-dynamo/dynamo. Just a reminder: The 🚀 |
Walkthrough
Defensive completion_usage handling
🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
|
/ok to test 8f1f652 |
|
Hi @Cirilus, thanks for the contribution! Please address the open comments 🙏 |
Signed-off-by: Kirill Shkolenko <shkolenko.kirill@gmail.com>
Signed-off-by: Kirill Shkolenko <shkolenko.kirill@gmail.com>
|
/ok to test b76cc97 |
Overview:
Fixes a SGLang token-stream failure where a final chunk with
finish_reasoncan omit completion usage fields inmeta_info, causing the decode worker to raiseKeyError: 'prompt_tokens'.Details:
SGLang streaming responses do not guarantee usage metadata on every streamed chunk. SGLang's own streaming path treats these fields as optional and accumulates them via
meta.get(...): https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/entrypoints/openai/serving_responses.py#L2033-L2036._process_token_streampreviously accessedmeta_info["prompt_tokens"],meta_info["completion_tokens"], andmeta_info["cached_tokens"]unconditionally whenfinish_reasonwas present. This can raiseKeyErroron final chunks that omit usage metadata.This PR changes the handler to read those fields optionally and only attach
completion_usagewhen bothprompt_tokensandcompletion_tokensare available. It also adds regression coverage for a final token-stream chunk withfinish_reasonbut without usage metadata.Where should the reviewer start?
components/src/dynamo/sglang/request_handlers/llm/decode_handler.pycomponents/src/dynamo/sglang/tests/test_sglang_decode_handler.pyRelated Issues
🔗 This PR is linked to an issue:
Summary by CodeRabbit