sgl-project/sglang · error · ValueError

lora_path list length ({len(self.lora_path)}) must match bat

Error message

lora_path list length ({len(self.lora_path)}) must match batch size ({num})

What it means

When lora_path is a list, SGLang requires one LoRA path (or None) per request in the batch; a length mismatch means per-request adapter assignment is ambiguous.

Source

Thrown at python/sglang/srt/managers/io_struct.py:1239

            if self.sampling_params is None:
                self.sampling_params = [{}] * self.batch_size
            elif isinstance(self.sampling_params, dict):
                self.sampling_params = [self.sampling_params] * self.batch_size
            for i in range(self.batch_size):
                self.sampling_params[i]["max_new_tokens"] = 0

            self._normalize_lora_paths(self.batch_size)

        self._validate_rid_uniqueness()

    def _normalize_lora_paths(self, num):
        """Normalize LoRA paths for batch processing."""
        if self.lora_path is not None:
            if isinstance(self.lora_path, str):
                self.lora_path = [self.lora_path] * num
            elif isinstance(self.lora_path, list):
                if len(self.lora_path) != num:
                    raise ValueError(
                        f"lora_path list length ({len(self.lora_path)}) must match batch size ({num})"
                    )
            else:
                raise ValueError("lora_path should be a list or a string.")

    def contains_mm_input(self) -> bool:
        return (
            has_valid_data(self.image_data)
            or has_valid_data(self.video_data)
            or has_valid_data(self.audio_data)
        )

    def _get_positional_embed_overrides_item(
        self, i: int
    ) -> Optional[PositionalEmbeds]:
        """Extract the i-th item from positional_embed_overrides."""
        if self.positional_embed_overrides is None:
            return None

View on GitHub (pinned to 0132848349)

Solutions

  1. Make len(lora_path) == batch_size, using None entries for requests without an adapter
  2. Or pass a single str to apply one LoRA to the whole batch
  3. Or pass None if no LoRA is needed

Example fix

// before
GenerateReqInput(text=['a','b','c'], lora_path=['/lora/a'])
// after
GenerateReqInput(text=['a','b','c'], lora_path=['/lora/a', None, None])
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(lora_path, list):
    assert len(lora_path) == batch_size, f'{len(lora_path)} != {batch_size}'

Prevention

When it happens

Trigger: Batch of 4 prompts with lora_path=['/a','/b']; per-request lora lists built before the prompt list changed size.

Common situations: Appending prompts after building the lora list; sharding requests across workers but slicing the lora list incorrectly.

Related errors


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