sgl-project/sglang · critical · ValueError

id2label mapping is missing

Error message

id2label mapping is missing

What it means

OpenAIEmbedding-style classify serving requires the model config to define id2label (classification label mapping) to build response labels. If the loaded model's config has no id2label, the ClassifyService __init__ aborts at startup with this ValueError.

Source

Thrown at python/sglang/srt/entrypoints/openai/serving_classify.py:45

class OpenAIServingClassify(OpenAIServingBase):
    """Handler for v1/classify requests"""

    def __init__(
        self,
        tokenizer_manager: TokenizerManager,
        template_manager: TemplateManager,
    ):
        super().__init__(tokenizer_manager)
        self.template_manager = template_manager
        self.id2label = self._get_id2label_mapping()
        self.model_name = (
            self.tokenizer_manager.served_model_name
            if self.tokenizer_manager.served_model_name
            else self.tokenizer_manager.model_path
        )
        if not self.id2label:
            raise ValueError("id2label mapping is missing")

    def _request_id_prefix(self) -> str:
        return "classify-"

    def _convert_to_internal_request(
        self,
        request: ClassifyRequest,
        raw_request: Request = None,
    ) -> tuple[EmbeddingReqInput, ClassifyRequest]:
        """Convert OpenAI embedding request to internal format"""
        prompt = request.input

        if isinstance(prompt, str):
            # Single string input
            prompt_kwargs = {"text": prompt}
        elif isinstance(prompt, list):
            if len(prompt) > 0 and isinstance(prompt[0], str):
                prompt_kwargs = {"text": prompt}

View on GitHub (pinned to 0132848349)

Solutions

  1. Use a model checkpoint that includes id2label in config.json (proper classification model)
  2. Add/restore the id2label map to the model's config.json if the head exists
  3. Don't expose the classify endpoint for models that aren't classifiers

Example fix

// config.json before: {}
// after
{"id2label": {"0": "negative", "1": "positive"}}
Defensive patterns

Strategy: validation

Validate before calling

import json; cfg = json.load(open(model_config_path)); assert cfg.get('id2label'), 'model lacks id2label'

Type guard

def is_classifier(config) -> bool: return isinstance(config.get('id2label'), dict) and len(config['id2label']) > 0

Prevention

When it happens

Trigger: Launching the server with a classification/classify serving path for a model whose config.json lacks an id2label mapping.

Common situations: Pointing --model-path at a checkpoint missing classification head metadata; using a base/embedding model with the classify endpoint enabled; a converted/merged model that dropped id2label during export.

Related errors


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