sgl-project/sglang · error · ValueError
Length mismatch: lora_nicknames has {len(lora_nicknames)} it
Error message
Length mismatch: lora_nicknames has {len(lora_nicknames)} items, but lora_paths has {len(lora_paths)} items What it means
_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.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/lora/pipeline.py:644
merge_weights: bool = True,
merge_cache: LoraMergeCache | None = None,
) -> int:
"""
Apply LoRA weights to the given lora_layers. Supports multiple LoRA adapters.
Args:
lora_layers: The dictionary of LoRA layers to apply weights to.
lora_nicknames: The list of nicknames of the LoRA adapters.
lora_paths: The list of paths to the LoRA adapters. Must match length of lora_nicknames.
rank: The distributed rank (for logging).
strengths: The list of LoRA strengths for merge. Must match length of lora_nicknames.
clear_existing: If True, clear existing LoRA weights before adding new ones.
Returns:
The number of layers that had LoRA weights applied.
"""
if len(lora_paths) != len(lora_nicknames):
raise ValueError(
f"Length mismatch: lora_nicknames has {len(lora_nicknames)} items, "
f"but lora_paths has {len(lora_paths)} items"
)
if len(strengths) != len(lora_nicknames):
raise ValueError(
f"Length mismatch: lora_nicknames has {len(lora_nicknames)} items, "
f"but strengths has {len(strengths)} items"
)
adapted_count = 0
missing_layers_by_adapter = [[] for _ in lora_nicknames]
applied_count_by_adapter = [0 for _ in lora_nicknames]
for name, layer in lora_layers.items():
# Apply all LoRA adapters in order
for idx, (nickname, path, lora_strength) in enumerate(
zip(lora_nicknames, lora_paths, strengths)
):
lora_A_name = name + ".lora_A"View on GitHub (pinned to 0132848349)
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
Example fix
# before pipeline.set_lora(lora_paths=['a.safetensors'], lora_nicknames=['a','b']) # after pipeline.set_lora(lora_paths=['a.safetensors', None], lora_nicknames=['a','b'])
Defensive patterns
Strategy: validation
Validate before calling
assert len(lora_paths) == len(lora_nicknames), 'paths/nicknames length mismatch'
Prevention
- Build adapter specs as a list of (path, nickname, strength) tuples then unzip
- Centralize adapter list construction in one config function
When it happens
Trigger: Calling set_lora(lora_paths=[p1, p2], lora_nicknames=['a']) or any combination where len(lora_paths) != len(lora_nicknames).
Common situations: 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.
Related errors
- Length mismatch: lora_nicknames has {len(lora_nicknames)} it
- g and beta must cover every q token
- attn_sink requires topk_length to be provided as well
- missing value for {a} (expected e.g. `{a} 2,4`)
- combined_history=True requires direction=0 (bidi)
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/31bbc08ff43a27a3.
Report an issue: GitHub.