core.tokenizers.text.parsers.deepseek_r1_reasoning_parser#

Module Contents#

Classes#

DeepSeekR1ReasoningParser

Parser for DeepSeek R1 style reasoning output.

API#

class core.tokenizers.text.parsers.deepseek_r1_reasoning_parser.DeepSeekR1ReasoningParser#

Bases: megatron.core.tokenizers.text.parsers.base_parser.BaseParser

Parser for DeepSeek R1 style reasoning output.

static parse(text: str, **kwargs) tuple[str, dict[str, str]]#

Extract reasoning content delimited by <think>...</think> tags.

Any text before the first <think> is discarded. When no </think> follows, the model is still “thinking”: all text is reasoning. Otherwise the text is split at the first </think>.

Parameters:

text (str) – The text to parse.

Returns:

A tuple containing the unprocessed text and a dictionary with the extracted reasoning content.

Return type:

tuple[str, dict[str, str]]