Configuration for reasoning models.
Set reasoning_start_str and reasoning_end_str to the strings that delimit the reasoning block (e.g. "<think>" and "</think>"). The corresponding token IDs are derived automatically via initialize_token_ids and are not intended to be set directly.
Source code in vllm/config/reasoning.py
| @config
class ReasoningConfig:
"""Configuration for reasoning models.
Set `reasoning_start_str` and `reasoning_end_str` to the strings that delimit
the reasoning block (e.g. `"<think>"` and `"</think>"`). The
corresponding token IDs are derived automatically via
`initialize_token_ids` and are not intended to be set directly.
"""
# NOTE: These parameters are temporary, the intent is to derive them
# automatically from the reasoning parser in a future version.
reasoning_start_str: str = "<think>"
"""String that indicates the start of reasoning."""
reasoning_end_str: str = "</think>"
"""String that indicates the end of reasoning content."""
_reasoning_start_token_ids: list[int] | None = field(
default=None, init=False, repr=False
)
"""Private backing field for `reasoning_start_token_ids`. Set by
`initialize_token_ids`. Not intended to be configured directly."""
_reasoning_end_token_ids: list[int] | None = field(
default=None, init=False, repr=False
)
"""Private backing field for `reasoning_end_token_ids`. Set by
`initialize_token_ids`. Not intended to be configured directly."""
@property
def reasoning_start_token_ids(self) -> list[int] | None:
"""Token IDs derived from `reasoning_start_str`. Set automatically by
`initialize_token_ids`. Not intended to be configured directly."""
return self._reasoning_start_token_ids
@property
def reasoning_end_token_ids(self) -> list[int] | None:
"""Token IDs derived from `reasoning_end_str`. Set automatically by
`initialize_token_ids`. Not intended to be configured directly."""
return self._reasoning_end_token_ids
def initialize_token_ids(self, model_config: ModelConfig) -> None:
"""Initialize reasoning token IDs from strings using the tokenizer."""
if (
self._reasoning_start_token_ids is not None
and self._reasoning_end_token_ids is not None
):
return
tokenizer = cached_tokenizer_from_config(model_config=model_config)
self._reasoning_start_token_ids = tokenizer.encode(
self.reasoning_start_str, add_special_tokens=False
)
self._reasoning_end_token_ids = tokenizer.encode(
self.reasoning_end_str, add_special_tokens=False
)
if not self._reasoning_start_token_ids or not self._reasoning_end_token_ids:
raise ValueError(
f"ReasoningConfig: failed to tokenize reasoning strings: "
f"reasoning_start_str='{self.reasoning_start_str}', "
f"reasoning_end_str='{self.reasoning_end_str}'. "
"Ensure the strings are valid tokens in the model's vocabulary."
)
|
_reasoning_end_token_ids class-attribute instance-attribute
_reasoning_end_token_ids: list[int] | None = field(
default=None, init=False, repr=False
)
Private backing field for reasoning_end_token_ids. Set by initialize_token_ids. Not intended to be configured directly.
_reasoning_start_token_ids class-attribute instance-attribute
_reasoning_start_token_ids: list[int] | None = field(
default=None, init=False, repr=False
)
Private backing field for reasoning_start_token_ids. Set by initialize_token_ids. Not intended to be configured directly.
reasoning_end_str class-attribute instance-attribute
reasoning_end_str: str = '</think>'
String that indicates the end of reasoning content.
reasoning_end_token_ids property
reasoning_end_token_ids: list[int] | None
Token IDs derived from reasoning_end_str. Set automatically by initialize_token_ids. Not intended to be configured directly.
reasoning_start_str class-attribute instance-attribute
reasoning_start_str: str = '<think>'
String that indicates the start of reasoning.
reasoning_start_token_ids property
reasoning_start_token_ids: list[int] | None
Token IDs derived from reasoning_start_str. Set automatically by initialize_token_ids. Not intended to be configured directly.
initialize_token_ids
initialize_token_ids(model_config: ModelConfig) -> None
Initialize reasoning token IDs from strings using the tokenizer.
Source code in vllm/config/reasoning.py
| def initialize_token_ids(self, model_config: ModelConfig) -> None:
"""Initialize reasoning token IDs from strings using the tokenizer."""
if (
self._reasoning_start_token_ids is not None
and self._reasoning_end_token_ids is not None
):
return
tokenizer = cached_tokenizer_from_config(model_config=model_config)
self._reasoning_start_token_ids = tokenizer.encode(
self.reasoning_start_str, add_special_tokens=False
)
self._reasoning_end_token_ids = tokenizer.encode(
self.reasoning_end_str, add_special_tokens=False
)
if not self._reasoning_start_token_ids or not self._reasoning_end_token_ids:
raise ValueError(
f"ReasoningConfig: failed to tokenize reasoning strings: "
f"reasoning_start_str='{self.reasoning_start_str}', "
f"reasoning_end_str='{self.reasoning_end_str}'. "
"Ensure the strings are valid tokens in the model's vocabulary."
)
|