sgl-project/sglang · error · ValueError

Language '{language}' not recognized. Use full name (e.g., '

Error message

Language '{language}' not recognized. Use full name (e.g., 'English') or ISO 639-1 code (e.g., 'en').

What it means

Whisper's normalize_language_to_code accepts a language given as a Whisper language name ('english') or an ISO 639-1 code ('en') and must resolve it to a code present in WHISPER_LANG_TOKEN_CODES. Anything else — unknown names, 3-letter ISO 639-2 codes ('eng'), regional tags ('en-US') — fails normalization and raises ValueError.

Source

Thrown at python/sglang/srt/multimodal/processors/whisper.py:127

    # Check if it's a full language name
    if language_lower in LANG_NAME_TO_CODE:
        return LANG_NAME_TO_CODE[language_lower]

    # Fused autodetect's FSM regex covers the full Whisper language-token
    # vocab (see WHISPER_LANG_TOKEN_CODES), which is wider than the
    # English-name-keyed ISO639_1_SUPPORTED_LANGS dict. Accept any code in
    # that wider set too so that detection -> reuse-as-input round-trips.
    # Lazy import to avoid top-level cycle with the openai entrypoint.
    from sglang.srt.entrypoints.openai.transcription_adapters.whisper import (
        WHISPER_LANG_TOKEN_CODES,
    )

    if language_lower in WHISPER_LANG_TOKEN_CODES:
        return language_lower

    # Not recognized
    raise ValueError(
        f"Language '{language}' not recognized. "
        f"Use full name (e.g., 'English') or ISO 639-1 code (e.g., 'en')."
    )


class WhisperProcessor(BaseMultimodalProcessor):
    models = [WhisperForConditionalGeneration]

    def __init__(self, hf_config, server_args, _processor, *args, **kwargs):
        super().__init__(hf_config, server_args, _processor, *args, **kwargs)
        # Cache tokenizer for language token lookup
        self._tokenizer = getattr(self._processor, "tokenizer", None)

    def _pop_sampling_param(self, request_obj, key: str):
        sampling_params = getattr(request_obj, "sampling_params", None) or {}
        return sampling_params.pop(key, None)

    def _get_language_token_id(self, language: Optional[str]) -> int:

View on GitHub (pinned to 0132848349)

Solutions

  1. Use the ISO 639-1 two-letter code ('en', 'zh') or the full Whisper name ('English')
  2. Strip regional suffixes: language.split('-')[0].lower()
  3. Check WHISPER_LANG_TOKEN_CODES for the supported set

Example fix

# before
language='en-US'
# after
language = language.split('-')[0].lower()  # 'en'
Defensive patterns

Strategy: validation

Validate before calling

code = language.strip().lower().split('-')[0]
if code not in WHISPER_LANG_TOKEN_CODES and code not in WHISPER_LANG_NAMES:
    raise ValueError(f'unsupported language: {language}')

Prevention

When it happens

Trigger: Passing language='eng' (ISO 639-2), 'en-US' (regional suffix), or a misspelled name like 'Englsih' to WhisperProcessor.process_mm_data_async.

Common situations: Data pipelines storing BCP-47 or 639-2 codes; users typing locale strings with region; languages Whisper does not support at all (e.g. 'klingon').

Related errors


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