{"record":{"id":"2a86a6a5071e6b43","repo":"sgl-project/sglang","slug":"lora-path-list-length-len-self-lora-path-must","errorCode":null,"errorMessage":"lora_path list length ({len(self.lora_path)}) must match batch size ({num})","messagePattern":"lora_path list length \\((.+?)\\) must match batch size \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/io_struct.py","lineNumber":1239,"sourceCode":"            if self.sampling_params is None:\n                self.sampling_params = [{}] * self.batch_size\n            elif isinstance(self.sampling_params, dict):\n                self.sampling_params = [self.sampling_params] * self.batch_size\n            for i in range(self.batch_size):\n                self.sampling_params[i][\"max_new_tokens\"] = 0\n\n            self._normalize_lora_paths(self.batch_size)\n\n        self._validate_rid_uniqueness()\n\n    def _normalize_lora_paths(self, num):\n        \"\"\"Normalize LoRA paths for batch processing.\"\"\"\n        if self.lora_path is not None:\n            if isinstance(self.lora_path, str):\n                self.lora_path = [self.lora_path] * num\n            elif isinstance(self.lora_path, list):\n                if len(self.lora_path) != num:\n                    raise ValueError(\n                        f\"lora_path list length ({len(self.lora_path)}) must match batch size ({num})\"\n                    )\n            else:\n                raise ValueError(\"lora_path should be a list or a string.\")\n\n    def contains_mm_input(self) -> bool:\n        return (\n            has_valid_data(self.image_data)\n            or has_valid_data(self.video_data)\n            or has_valid_data(self.audio_data)\n        )\n\n    def _get_positional_embed_overrides_item(\n        self, i: int\n    ) -> Optional[PositionalEmbeds]:\n        \"\"\"Extract the i-th item from positional_embed_overrides.\"\"\"\n        if self.positional_embed_overrides is None:\n            return None","sourceCodeStart":1221,"sourceCodeEnd":1257,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/io_struct.py#L1221-L1257","documentation":"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.","triggerScenarios":"Batch of 4 prompts with lora_path=['/a','/b']; per-request lora lists built before the prompt list changed size.","commonSituations":"Appending prompts after building the lora list; sharding requests across workers but slicing the lora list incorrectly.","solutions":["Make len(lora_path) == batch_size, using None entries for requests without an adapter","Or pass a single str to apply one LoRA to the whole batch","Or pass None if no LoRA is needed"],"exampleFix":"// before\nGenerateReqInput(text=['a','b','c'], lora_path=['/lora/a'])\n// after\nGenerateReqInput(text=['a','b','c'], lora_path=['/lora/a', None, None])","handlingStrategy":"validation","validationCode":"if isinstance(lora_path, list):\n    assert len(lora_path) == batch_size, f'{len(lora_path)} != {batch_size}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build prompts and lora_path in the same loop","Pad with None for adapter-less requests"],"tags":["sglang","lora","batching","input-validation"],"backgroundTag":"lora-batch-config-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}