sgl-project/sglang · error · ValueError

LoRA with name {lora_ref.lora_name} already exists. Loaded L

Error message

LoRA with name {lora_ref.lora_name} already exists. Loaded LoRAs: {self._registry.keys()}

What it means

Raised by LoRARegistry._register_adapter when registering a LoRA name that already exists in the registry (an OrderedDict keyed by lora_name). Registration happens in registry __init__ and register(); duplicate names would alias two adapters to one key, so it is rejected.

Source

Thrown at python/sglang/srt/lora/lora_registry.py:242

        If exclude_pinned is True, then return the LRU LoRA adapter that isn't pinned.
        """
        async with self._registry_lock.reader_lock:
            if not exclude_pinned:
                return next(iter(self._registry), None)

            for lora_name, lora_ref in self._registry.items():
                if not lora_ref.pinned:
                    return lora_name
            else:
                return None

    def _register_adapter(self, lora_ref: LoRARef):
        """
        Internal helper method to register a LoRA adapter.
        """

        if lora_ref.lora_name in self._registry:
            raise ValueError(
                f"LoRA with name {lora_ref.lora_name} already exists. Loaded LoRAs: {self._registry.keys()}"
            )
        self._registry[lora_ref.lora_name] = lora_ref
        self._counters[lora_ref.lora_id] = ConcurrentCounter()
        return lora_ref

    @property
    def num_registered_loras(self) -> int:
        """
        Returns the total number of LoRA adapters currently registered.
        """
        return len(self._registry)

    def get_all_adapters(self) -> Dict[str, LoRARef]:
        """
        Returns a dictionary of all registered LoRA adapters.

        Returns:

View on GitHub (pinned to 0132848349)

Solutions

  1. Unload/unregister the existing adapter before registering the same name
  2. Use a unique lora_name for the new adapter
  3. Serialize load operations per name (lock or single-writer) to avoid racing registrations

Example fix

# before
await registry.register(LoRARef(lora_name='a', lora_path=p1))
await registry.register(LoRARef(lora_name='a', lora_path=p2))
# after
await registry.register(LoRARef(lora_name='a-v2', lora_path=p2))
Defensive patterns

Strategy: validation

Validate before calling

if lora_ref.lora_name in registry._registry:
    raise ValueError(f"{lora_ref.lora_name} already registered; pick another name or unregister first")

Try / catch

try:
    registry.register(lora_ref)
except ValueError as e:
    if 'already exists' in str(e):
        await registry.unregister(lora_ref.lora_name)
        registry.register(lora_ref)  # replace
    else:
        raise

Prevention

When it happens

Trigger: Constructing/registering a LoRARef whose lora_name equals an existing registry key — e.g. two load requests racing, or re-creating a registry entry with the same name.

Common situations: Concurrent load requests for the same name; retry logic that re-registers after a partial failure; startup lora_paths containing the same name twice.

Related errors


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