[Bug Fix] Validate tokenizer-dependent features with skip_tokenizer_init (#27882)

Co-authored-by: Randall <randall@iterationlab.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Randall Lin
2026-06-14 20:07:52 -07:00
committed by GitHub
co-authored by Randall Cursor
parent 37505eca27
commit 0417951a86
4 changed files with 81 additions and 9 deletions
@@ -29,6 +29,36 @@ TOP_K_ALL = 1 << 30
logger = logging.getLogger(__name__)
def raise_if_tokenizer_required(
tokenizer, stop_strs, stop_regex_strs, min_new_tokens=0
):
"""Raise ValueError if tokenizer-dependent features are used without a tokenizer.
String-based stop conditions (stop_strs, stop_regex_strs) require tokenizer.decode()
to convert output token IDs to text for matching. min_new_tokens requires the
tokenizer's eos_token_id to penalize. When skip_tokenizer_init=True, these cannot
be used.
"""
if tokenizer is not None:
return
if stop_strs:
raise ValueError(
f"stop={stop_strs!r} is unavailable when skip_tokenizer_init=True "
"(requires tokenizer to decode tokens to text for matching)."
)
if stop_regex_strs:
raise ValueError(
f"stop_regex={stop_regex_strs!r} is unavailable when skip_tokenizer_init=True "
"(requires tokenizer to decode tokens to text for matching)."
)
if min_new_tokens > 0:
raise ValueError(
f"min_new_tokens={min_new_tokens} is unavailable when skip_tokenizer_init=True "
"(requires tokenizer for eos_token_id)."
)
class SamplingParams:
"""
The sampling parameters.
@@ -210,6 +240,11 @@ class SamplingParams:
self.stop_regex_max_len = stop_regex_max_len
# Validate tokenizer is available for tokenizer-dependent features
raise_if_tokenizer_required(
tokenizer, self.stop_strs, self.stop_regex_strs, self.min_new_tokens
)
# This function gets a strict upperbound on the maximum number of tokens that would need
# to be buffered to match the input regex string
+13
View File
@@ -4354,6 +4354,11 @@ class ServerArgs:
)
self.enable_dynamic_batch_tokenizer = False
logger.info(
"skip_tokenizer_init=True: string-based stop conditions (stop, stop_regex) "
"and min_new_tokens are unavailable."
)
def _handle_environment_variables(self):
envs.SGLANG_ENABLE_TORCH_COMPILE.set("1" if self.enable_torch_compile else "0")
if self.mamba_ssm_dtype is not None:
@@ -4681,6 +4686,14 @@ class ServerArgs:
self.preferred_sampling_params
)
# Validate preferred_sampling_params doesn't use tokenizer-dependent features
if self.skip_tokenizer_init:
from sglang.srt.sampling.sampling_params import SamplingParams
test_params = SamplingParams(**self.preferred_sampling_params)
# raises if tokenizer-dependent features used
test_params.normalize(None)
def _handle_crash_dump_env(self):
if not self.crash_dump_folder:
return