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 strengths has {len(strengths)} items What it means
Same per-adapter list validation in _apply_lora_to_layers, but for strengths: the strengths list must match lora_nicknames in length so each adapter has a scaling factor.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/lora/pipeline.py:649
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"
lora_B_name = name + ".lora_B"
if (
lora_A_name in self.lora_adapters[nickname]
and lora_B_name in self.lora_adapters[nickname]
):View on GitHub (pinned to 0132848349)
Solutions
- Provide one strength per nickname, e.g. strengths=[1.0]*len(lora_nicknames)
- Omit strengths entirely if defaults are acceptable
Example fix
# before pipeline.set_lora(lora_paths=paths, lora_nicknames=['a','b'], strengths=[0.8]) # after pipeline.set_lora(lora_paths=paths, lora_nicknames=['a','b'], strengths=[0.8, 0.8])
Defensive patterns
Strategy: validation
Validate before calling
if strengths is not None: assert len(strengths) == len(lora_nicknames)
Prevention
- Default strengths to [1.0]*len(lora_nicknames)
- Zip all adapter lists together when constructing them
When it happens
Trigger: Calling set_lora(lora_nicknames=['a','b'], strengths=[1.0]) — fewer (or more) strength values than adapters.
Common situations: Passing a single scalar strength when multiple adapters are composed; strengths list built for an older adapter set after adding a new adapter.
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/365fedebd9ac370b.
Report an issue: GitHub.