Conversation
…arsing Motivation: parse_message_from_completion_text in the DeepSeek V3.2 and V4 encoding modules documents that it raises ValueError for malformed output, but enforced the format with assert. It therefore raised AssertionError, and under `python -O` the checks are stripped so malformed output (e.g. a completion with no EOS token) parsed into a well-formed-looking message. Only the V4 parse_tool_calls already used ValueError. Approach: convert the assert-based format checks in parse_message_from_completion_text (both modules) and parse_tool_calls (V3.2) into explicit `raise ValueError` with the same messages. Encode-side asserts are untouched. No production caller of these functions was found (tests only), so the benefit is that the documented contract holds and the checks survive -O; the streaming-vs-batch grammar and duplicate-parameter divergences from the issue are not addressed here. Validation: - Ran a stdlib-only script that loads both modules standalone and parses malformed completions: before the change it gave AssertionError (and no error at all under `python3 -O`); after, ValueError, including under -O. - Added tests for both modules; they were only py_compile'd, not run under pytest, because importing lmdeploy locally needs deps (torch, tqdm) that are not installed here. No linter was available locally either. Report: InternLM#5011 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Assisted-by: claude-sonnet-5-5 (via Claude Code)
This branch has not been deployed
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.
Motivation
parse_message_from_completion_textindeepseek_v32_encoding.py/deepseek_v4_encoding.pydocuments that it raisesValueErrorfor malformed output, but enforced the format withassert. It raisedAssertionError, and underpython -Othe checks vanish so malformed output (e.g. missing EOS) parses as a valid message. No production caller was found (tests only), so the benefit is the documented contract plus-Osafety.Modification
Convert the assert-based format checks in the parse functions of both modules to
raise ValueErrorwith the same messages. Encode-side asserts untouched. Divergences 2 and 3 in the issue (batch vs streaming grammar, duplicate params) are not addressed.BC-breaking (Optional)
Callers catching
AssertionErrorfrom these parse functions would now needValueError(none found in the repo).Use cases (Optional)
N/A
Checklist
Fixes #5011
Fixes #5011