From b9e2bf7d067b5c27fdbc1192b3481e5fde1b2c3e Mon Sep 17 00:00:00 2001 From: reidliu41 Date: Sun, 18 May 2025 08:32:17 +0800 Subject: [PATCH 1/2] [doc] update reasoning doc Signed-off-by: reidliu41 --- docs/source/features/reasoning_outputs.md | 31 +++-------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/docs/source/features/reasoning_outputs.md b/docs/source/features/reasoning_outputs.md index 3c2571298e4f..c199c644ecfb 100644 --- a/docs/source/features/reasoning_outputs.md +++ b/docs/source/features/reasoning_outputs.md @@ -231,13 +231,12 @@ For more examples, please refer to . +You can add a new `ReasoningParser` similar to . ```python # import the required packages -from vllm.entrypoints.openai.reasoning_parsers.abs_reasoning_parsers import ( - ReasoningParser, ReasoningParserManager) +from vllm.reasoning import ReasoningParser, ReasoningParserManager from vllm.entrypoints.openai.protocol import (ChatCompletionRequest, DeltaMessage) @@ -288,31 +287,7 @@ class ExampleParser(ReasoningParser): """ ``` -Additionally, to enable structured output, you'll need to create a new `Reasoner` similar to the one in . - -```python -@dataclass -class DeepSeekReasoner(Reasoner): - """ - Reasoner for DeepSeek R series models. - """ - start_token_id: int - end_token_id: int - - start_token: str = "" - end_token: str = "" - - @classmethod - def from_tokenizer(cls, tokenizer: PreTrainedTokenizer) -> Reasoner: - return cls(start_token_id=tokenizer.encode( - "", add_special_tokens=False)[0], - end_token_id=tokenizer.encode("", - add_special_tokens=False)[0]) - - def is_reasoning_end(self, input_ids: list[int]) -> bool: - return self.end_token_id in input_ids - ... -``` +Additionally, to enable structured output, you'll need to create a new `Reasoner` similar to the one in . The structured output engine like [xgrammar](https://github.com/mlc-ai/xgrammar) will use `end_token_id` to check if the reasoning content is present in the model output and skip the structured output if it is the case. From 7579695c61ecada935f68acce755584d7482b8a4 Mon Sep 17 00:00:00 2001 From: reidliu41 Date: Sun, 18 May 2025 16:36:01 +0800 Subject: [PATCH 2/2] roll back the example Signed-off-by: reidliu41 --- docs/source/features/reasoning_outputs.md | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/source/features/reasoning_outputs.md b/docs/source/features/reasoning_outputs.md index c199c644ecfb..7a761ff9a4d9 100644 --- a/docs/source/features/reasoning_outputs.md +++ b/docs/source/features/reasoning_outputs.md @@ -289,6 +289,30 @@ class ExampleParser(ReasoningParser): Additionally, to enable structured output, you'll need to create a new `Reasoner` similar to the one in . +```python +@dataclass +class DeepSeekReasoner(Reasoner): + """ + Reasoner for DeepSeek R series models. + """ + start_token_id: int + end_token_id: int + + start_token: str = "" + end_token: str = "" + + @classmethod + def from_tokenizer(cls, tokenizer: PreTrainedTokenizer) -> Reasoner: + return cls(start_token_id=tokenizer.encode( + "", add_special_tokens=False)[0], + end_token_id=tokenizer.encode("", + add_special_tokens=False)[0]) + + def is_reasoning_end(self, input_ids: list[int]) -> bool: + return self.end_token_id in input_ids + ... +``` + The structured output engine like [xgrammar](https://github.com/mlc-ai/xgrammar) will use `end_token_id` to check if the reasoning content is present in the model output and skip the structured output if it is the case. Finally, you can enable reasoning for the model by using the `--reasoning-parser` flags.