{"record":{"id":"31bbc08ff43a27a3","repo":"sgl-project/sglang","slug":"length-mismatch-lora-nicknames-has-len-lora-nick","errorCode":null,"errorMessage":"Length mismatch: lora_nicknames has {len(lora_nicknames)} items, but lora_paths has {len(lora_paths)} items","messagePattern":"Length mismatch: lora_nicknames has (.+?) items, but lora_paths has (.+?) items","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/lora/pipeline.py","lineNumber":644,"sourceCode":"        merge_weights: bool = True,\n        merge_cache: LoraMergeCache | None = None,\n    ) -> int:\n        \"\"\"\n        Apply LoRA weights to the given lora_layers. Supports multiple LoRA adapters.\n\n        Args:\n            lora_layers: The dictionary of LoRA layers to apply weights to.\n            lora_nicknames: The list of nicknames of the LoRA adapters.\n            lora_paths: The list of paths to the LoRA adapters. Must match length of lora_nicknames.\n            rank: The distributed rank (for logging).\n            strengths: The list of LoRA strengths for merge. Must match length of lora_nicknames.\n            clear_existing: If True, clear existing LoRA weights before adding new ones.\n\n        Returns:\n            The number of layers that had LoRA weights applied.\n        \"\"\"\n        if len(lora_paths) != len(lora_nicknames):\n            raise ValueError(\n                f\"Length mismatch: lora_nicknames has {len(lora_nicknames)} items, \"\n                f\"but lora_paths has {len(lora_paths)} items\"\n            )\n        if len(strengths) != len(lora_nicknames):\n            raise ValueError(\n                f\"Length mismatch: lora_nicknames has {len(lora_nicknames)} items, \"\n                f\"but strengths has {len(strengths)} items\"\n            )\n\n        adapted_count = 0\n        missing_layers_by_adapter = [[] for _ in lora_nicknames]\n        applied_count_by_adapter = [0 for _ in lora_nicknames]\n        for name, layer in lora_layers.items():\n            # Apply all LoRA adapters in order\n            for idx, (nickname, path, lora_strength) in enumerate(\n                zip(lora_nicknames, lora_paths, strengths)\n            ):\n                lora_A_name = name + \".lora_A\"","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/lora/pipeline.py#L626-L662","documentation":"_apply_lora_to_layers validates that lora_paths, lora_nicknames, and strengths lists are the same length. This variant fires when the nickname list length differs from the paths list length, meaning the pipeline cannot map adapters to checkpoints.","triggerScenarios":"Calling set_lora(lora_paths=[p1, p2], lora_nicknames=['a']) or any combination where len(lora_paths) != len(lora_nicknames).","commonSituations":"Appending an adapter nickname but forgetting its path; building lists in separate loops/config sections that drift out of sync; loading from a config where one field is optional and defaulted to a single-element list.","solutions":["Make lora_paths and lora_nicknames the same length (one entry per adapter)","If an adapter is already loaded, pass None in its lora_paths slot instead of omitting the element","Add an assert in your config loader before calling set_lora"],"exampleFix":"# before\npipeline.set_lora(lora_paths=['a.safetensors'], lora_nicknames=['a','b'])\n# after\npipeline.set_lora(lora_paths=['a.safetensors', None], lora_nicknames=['a','b'])","handlingStrategy":"validation","validationCode":"assert len(lora_paths) == len(lora_nicknames), 'paths/nicknames length mismatch'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build adapter specs as a list of (path, nickname, strength) tuples then unzip","Centralize adapter list construction in one config function"],"tags":["lora","argument-validation","length-mismatch"],"backgroundTag":"argument-length-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}