[Bugfix][Structured Output] Support outlines engine with reasoning outputs for DeepSeek R1 (#14114)
This commit is contained in:
@@ -4,10 +4,13 @@ from __future__ import annotations
|
||||
|
||||
from transformers import PreTrainedTokenizer
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.guided_decoding.reasoner.deepseek_reasoner import ( # noqa: E501
|
||||
DeepSeekReasoner)
|
||||
from vllm.model_executor.guided_decoding.reasoner.reasoner import Reasoner
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def get_reasoner(tokenizer: PreTrainedTokenizer,
|
||||
reasoning_backend: str | None) -> Reasoner | None:
|
||||
@@ -17,7 +20,12 @@ def get_reasoner(tokenizer: PreTrainedTokenizer,
|
||||
elif reasoning_backend == "deepseek_r1":
|
||||
return DeepSeekReasoner.from_tokenizer(tokenizer)
|
||||
else:
|
||||
raise ValueError(f"Unknown reasoning backend '{reasoning_backend}'")
|
||||
# Raise a warning for unknown reasoning backend and return None
|
||||
# We cannot raise an error here because some reasoning models
|
||||
# may not have a corresponding Reasoner class.
|
||||
logger.warning("Unknown reasoning backend %s for structured outputs ",
|
||||
reasoning_backend)
|
||||
return None
|
||||
|
||||
|
||||
__all__ = ["Reasoner", "get_reasoner"]
|
||||
|
||||
@@ -26,3 +26,13 @@ class DeepSeekReasoner(Reasoner):
|
||||
|
||||
def is_reasoning_end(self, input_ids: list[int]) -> bool:
|
||||
return self.end_token_id in input_ids
|
||||
|
||||
def extract_content(self, input_ids: list[int]) -> list[int]:
|
||||
"""
|
||||
Extract the content after the end tokens
|
||||
"""
|
||||
if self.end_token_id not in input_ids or \
|
||||
input_ids.index(self.end_token_id) + 1 == len(input_ids):
|
||||
return []
|
||||
else:
|
||||
return input_ids[input_ids.index(self.end_token_id) + 1:]
|
||||
|
||||
@@ -17,3 +17,7 @@ class Reasoner(ABC):
|
||||
@abstractmethod
|
||||
def is_reasoning_end(self, input_ids: list[int]) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def extract_content(self, input_ids: list[int]) -> list[int]:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user