Skip to content

Fix error in deepseek parser#5136

Merged
ericharper merged 3 commits into
NVIDIA:mainfrom
tdene:tde/fix_deepseek_parser
Jun 5, 2026
Merged

Fix error in deepseek parser#5136
ericharper merged 3 commits into
NVIDIA:mainfrom
tdene:tde/fix_deepseek_parser

Conversation

@tdene
Copy link
Copy Markdown
Contributor

@tdene tdene commented Jun 3, 2026

  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do ?

Comparison of vllm and Megatron-LM reasoning parser.

MLM path: https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/core/tokenizers/text/parsers/deepseek_r1_reasoning_parser.py
vllm paths: https://github.com/vllm-project/vllm/blob/main/vllm/reasoning/deepseek_r1_reasoning_parser.py https://github.com/vllm-project/vllm/blob/main/vllm/reasoning/basic_parsers.py

MLM code:

        if "</think>" in text:
            if "<think>" in text:
                # Strip the <think> prefix (it might not be present if it was part of the prompt)
                pre_text, text = text.split("<think>", maxsplit=1)
            else:
                pre_text = ""
            reasoning_content, remaining_text = text.split("</think>", maxsplit=1)
            return pre_text + remaining_text, {'reasoning': reasoning_content}
        else:
            return text, {}

vllm code:

        model_output_parts = model_output.partition(self.start_token)
        model_output = (
            model_output_parts[2] if model_output_parts[1] else model_output_parts[0]
        )

        # For models that may not generate start token,
        # assume the reasoning content is always at the start.
        if self.end_token not in model_output:
            return model_output, None
        else:
            reasoning, _, content = model_output.partition(self.end_token)
            # If generation stops right after end-of-think, return null content
            final_content = content or None
            return reasoning, final_content

NOTE: In this table, the tuple represents (reasoning, content).

+---------------------------+--------------------+--------------------+-------+
| input                     |          vLLM      | Megatron-LM        |
+---------------------------+--------------------+--------------------+-------+
| 'answer'                  | ('answer', None)   | (None, 'answer')   |
| '<think>r'                | ('r', None)        | (None, '<think>r') |
| 'pre<think>r</think>post' | ('r', 'post')      | ('r', 'prepost')   |
| 'r</think>a<think>b'      | ('b', None)        | CRASH (ValueError) |
+---------------------------+--------------------+--------------------+-------+

In a nutshell:

  • vllm assumes that all rollouts that use a reasoning parser are CoT, and there is never a case where we will skip reasoning and go straight to non-reasoning content.
  • vllm throws away everything before the first explicit <think> tag.
  • vllm does not need an explicit </think> tag,

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact @NVIDIA/mcore-oncall.

Issue tracking

For PRs from open-source community contributors:

  • New features: a linked issue is required. Please open a feature request and reference it here before submitting the PR.
  • Small updates (bug fixes, minor improvements): a linked issue is recommended and will accelerate the PR review process.

Linked issue:

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Jun 3, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Jun 3, 2026
@ericharper ericharper enabled auto-merge June 3, 2026 17:17
@ericharper
Copy link
Copy Markdown
Contributor

/ok to test 4a0fb9c

1 similar comment
@ericharper
Copy link
Copy Markdown
Contributor

/ok to test 4a0fb9c

@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Jun 5, 2026
@ericharper ericharper added this pull request to the merge queue Jun 5, 2026
@svcnvidia-nemo-ci
Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/27027461512

@svcnvidia-nemo-ci
Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/27037180102

Merged via the queue into NVIDIA:main with commit 5a2c6fa Jun 5, 2026
87 of 90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants