Optimize BaseResponseParser streaming and add parser benchmark#4697
Open
lvhan028 wants to merge 1 commit into
Open
Optimize BaseResponseParser streaming and add parser benchmark#4697lvhan028 wants to merge 1 commit into
lvhan028 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes streaming parsing in BaseResponseParser (reducing string concatenation overhead and avoiding repeated partial JSON parsing for tool calls) and adds a standalone benchmark script to measure streaming vs complete parsing performance.
Changes:
- Avoid repeated
partial_json_parser.loads()calls for growing tool-call payloads during streaming. - Replace
_accumulated_textstring concatenation with chunk accumulation inBaseResponseParser. - Add
benchmark/benchmark_parser.pyto benchmark streaming and complete parsing scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lmdeploy/serve/parsers/tool_parser/tool_parser.py | Skip redundant partial JSON parsing on non-final chunks after tool name is emitted. |
| lmdeploy/serve/parsers/response_parser.py | Accumulate streamed text via chunk list and reuse precomputed open-tag list in complete parsing. |
| benchmark/benchmark_parser.py | New benchmark script for parser streaming and complete parsing throughput. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self._name_emitted and not final: | ||
| return [] | ||
|
|
||
| flags = Allow.ALL if final else Allow.ALL & ~Allow.STR |
| rcls = ReasoningParserManager.get(cfg.reasoning_parser) | ||
| reasoning_open = rcls.get_reasoning_open_tag() | ||
| reasoning_close = rcls.get_reasoning_close_tag() | ||
| rparser = rcls(enable_thinking=cfg.enable_thinking if cfg.enable_thinking else None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.