sgl-project/sglang · error · ValueError

stop_regex={stop_regex_strs!r} is unavailable when skip_toke

Error message

stop_regex={stop_regex_strs!r} is unavailable when skip_tokenizer_init=True (requires tokenizer to decode tokens to text for matching).

What it means

With --skip-tokenizer-init, regex-based stop conditions are unsupported for the same reason as string stops: matching stop_regex requires decoding tokens to text, and no tokenizer exists. raise_if_tokenizer_required rejects stop_regex_strs during normalize().

Source

Thrown at python/sglang/srt/sampling/sampling_params.py:329

    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)."
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. Drop stop_regex and use stop_token_ids with the ids of concrete delimiter tokens.
  2. Or run the server with a tokenizer (remove --skip-tokenizer-init).

Example fix

# before
SamplingParams(stop_regex=[r"\n\nUser:"])  # with --skip-tokenizer-init
# after
SamplingParams(stop_token_ids=[tokenizer.convert_tokens_to_ids(t) for t in ("\n\n", "User", ":")])
Defensive patterns

Strategy: type-guard

Validate before calling

if skip_tokenizer_init:
    params.pop('stop_regex', None)  # or reject early with your own message

Type guard

def regex_stop_ok_without_tokenizer(params: dict) -> bool:
    return not params.get('stop_regex')

Prevention

When it happens

Trigger: Server started with --skip-tokenizer-init and a request sets SamplingParams(stop_regex=["\n\nUser:"]) or a string entry inside stop that is treated as a regex.

Common situations: Agents/chat loops that stop on a pattern (e.g. turn delimiter) pointed at a tokenizer-free endpoint; porting configs from a normal server to a skip-tokenizer benchmark server.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/4c3266b54c961374. Report an issue: GitHub.