Convert formatting to use ruff instead of yapf + isort (#26247)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@@ -11,8 +11,11 @@ import regex as re
|
||||
if TYPE_CHECKING:
|
||||
from vllm.transformers_utils.tokenizer import AnyTokenizer
|
||||
|
||||
from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
|
||||
DeltaMessage, ResponsesRequest)
|
||||
from vllm.entrypoints.openai.protocol import (
|
||||
ChatCompletionRequest,
|
||||
DeltaMessage,
|
||||
ResponsesRequest,
|
||||
)
|
||||
from vllm.logger import init_logger
|
||||
from vllm.reasoning import ReasoningParser, ReasoningParserManager
|
||||
|
||||
@@ -33,8 +36,7 @@ class Indices:
|
||||
return self.end - self.start
|
||||
|
||||
|
||||
def string_overlap(a: str,
|
||||
b: str) -> tuple[Optional[Indices], Optional[Indices]]:
|
||||
def string_overlap(a: str, b: str) -> tuple[Optional[Indices], Optional[Indices]]:
|
||||
"""
|
||||
Find the longest overlap where the end of string a matches the start
|
||||
of string b.
|
||||
@@ -95,7 +97,7 @@ class Olmo3ReasoningBuffer:
|
||||
self.state = Olmo3ReasoningState.REASONING
|
||||
pretext, self.buffer = (
|
||||
self.buffer[:start_think_idx],
|
||||
self.buffer[start_think_idx + len(self.think_start):],
|
||||
self.buffer[start_think_idx + len(self.think_start) :],
|
||||
)
|
||||
if start_think_idx > 0:
|
||||
# this covers the case there's content before
|
||||
@@ -108,7 +110,7 @@ class Olmo3ReasoningBuffer:
|
||||
self.state = Olmo3ReasoningState.CONTENT
|
||||
pretext, self.buffer = (
|
||||
self.buffer[:end_think_idx],
|
||||
self.buffer[end_think_idx + len(self.think_end):],
|
||||
self.buffer[end_think_idx + len(self.think_end) :],
|
||||
)
|
||||
if end_think_idx > 0:
|
||||
# this covers the case there's content before
|
||||
@@ -153,12 +155,17 @@ class Olmo3ReasoningBuffer:
|
||||
_, overlap_think_end = string_overlap(delta_text, self.think_end)
|
||||
|
||||
partial_overlap_start = overlap_think_start is not None and len(
|
||||
overlap_think_start) < len(self.think_start)
|
||||
overlap_think_start
|
||||
) < len(self.think_start)
|
||||
partial_overlap_end = overlap_think_end is not None and len(
|
||||
overlap_think_end) < len(self.think_end)
|
||||
overlap_think_end
|
||||
) < len(self.think_end)
|
||||
|
||||
if (partial_overlap_start and self.think_start in self.buffer
|
||||
and not partial_overlap_end):
|
||||
if (
|
||||
partial_overlap_start
|
||||
and self.think_start in self.buffer
|
||||
and not partial_overlap_end
|
||||
):
|
||||
# we can only process the buffer if partial overlap
|
||||
# is the last part of think token (thus causing
|
||||
# text_buffer to contain the start of think token)
|
||||
@@ -223,12 +230,15 @@ class Olmo3ReasoningParser(ReasoningParser):
|
||||
# notice that the first think is optional; this allows template to
|
||||
# work in cases when we hardcode a <think> at the beginning of the
|
||||
# reasoning template.
|
||||
reasoning_expr = (rf"^(?:{self.think_start})?(?P<reasoning>.*?)" +
|
||||
rf"{self.think_end}(?P<content>.*)$")
|
||||
reasoning_expr = (
|
||||
rf"^(?:{self.think_start})?(?P<reasoning>.*?)"
|
||||
+ rf"{self.think_end}(?P<content>.*)$"
|
||||
)
|
||||
self.reasoning_regex = re.compile(reasoning_expr, re.DOTALL)
|
||||
|
||||
self.buffer = Olmo3ReasoningBuffer(think_start=self.think_start,
|
||||
think_end=self.think_end)
|
||||
self.buffer = Olmo3ReasoningBuffer(
|
||||
think_start=self.think_start, think_end=self.think_end
|
||||
)
|
||||
|
||||
def is_reasoning_end(self, input_ids: list[int]) -> bool:
|
||||
text = self.model_tokenizer.decode(input_ids)
|
||||
@@ -281,8 +291,7 @@ class Olmo3ReasoningParser(ReasoningParser):
|
||||
"""Extract content using token ID sequence state machine"""
|
||||
|
||||
delta_message = self.buffer.add_text(delta_text)
|
||||
if (delta_message is None
|
||||
and self.buffer.think_end in self.buffer.buffer):
|
||||
if delta_message is None and self.buffer.think_end in self.buffer.buffer:
|
||||
# this is a bit hacky, but, because of how the buffer is
|
||||
# constructed, if the last delta_text contains characters that
|
||||
# marks the end of thinking tokens, then messages in the buffer
|
||||
|
||||
Reference in New Issue
Block a user