Repository navigation
[Bugfix][Tool Parser] Fix Hunyuan A13B nested JSON tool streaming - #38103
vineetatiwari27 wants to merge 2 commits into
Conversation
Signed-off-by: Vineeta Tiwari <vineeta.tiwari2@ibm.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the hunyuan_a13b_tool_parser to correctly handle nested JSON objects within streaming tool call arguments. The previous regex-based approach was replaced with a new brace-depth scanning mechanism, which includes the introduction of _scan_braced_json_object and _extract_tool_arguments_text methods. This change resolves a known limitation, allowing a previously xfailed test case for nested JSON parsing to now pass. However, a high-severity performance concern has been raised regarding the new implementation, as it re-scans the current_text on each token, leading to a quadratic time complexity (O(N^2)). It is recommended to refactor this to a stateful streaming parser to achieve linear time complexity (O(N)).
| "sent_arguments" | ||
| ] | ||
| if not self.streaming_state["sent_tools"][current_idx][ | ||
| args_text = self._extract_tool_arguments_text(current_text, current_idx) |
There was a problem hiding this comment.
The new approach using _extract_tool_arguments_text and _scan_braced_json_object correctly handles nested JSON, which is a great improvement. However, this implementation introduces a performance concern. On each call (for each new token), these functions re-scan a large portion of the growing current_text. This leads to an overall quadratic time complexity (O(N^2)) for parsing the arguments stream, where N is the length of the arguments. In a performance-critical library like vLLM, this can be a significant issue for tool calls with large arguments.
Consider refactoring this to use a stateful streaming parser. The parser's state (current position, brace depth, etc.) could be stored in self.streaming_state and updated incrementally with each new token, avoiding the need to re-scan previously processed text. This would bring the complexity down to linear time (O(N)).
Signed-off-by: Vineeta Tiwari <vineeta.tiwari2@ibm.com> Made-with: Cursor
|
This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you! |
|
This pull request has been automatically closed due to inactivity. Please feel free to reopen if you intend to continue working on it. Thank you! |
Summary
Fix streaming tool parsing for Hunyuan A13B when
function_call.argumentscontains deeply nested JSON objects.Why this PR
HunyuanA13BToolParserand its streaming reconstruction offunction_call.argumentsbraces at arbitrary nesting depth.Tests
pytest tests/tool_parsers/test_hunyuan_a13b_tool_parser.py -vAI assistance
AI assistance was used to implement and validate this parser change.