OpenBMB/VoxCPM · error · RuntimeError

Cannot load LoRA weights: model was not initialized with LoR

Error message

Cannot load LoRA weights: model was not initialized with LoRA config. Please reinitialize with lora_config or lora_weights_path parameter.

What it means

load_lora() can only inject LoRA weights into a model that was constructed with lora_config (i.e. LoRA layers already wrapped). Calling it on a plain model raises RuntimeError.

Source

Thrown at src/voxcpm/core.py:337

    # ------------------------------------------------------------------ #
    # LoRA Interface (delegated to VoxCPMModel)
    # ------------------------------------------------------------------ #
    def load_lora(self, lora_weights_path: str) -> tuple:
        """Load LoRA weights from a checkpoint file.

        Args:
            lora_weights_path: Path to LoRA weights (.pth file or directory
                containing lora_weights.ckpt).

        Returns:
            tuple: (loaded_keys, skipped_keys) - lists of loaded and skipped parameter names.

        Raises:
            RuntimeError: If model was not initialized with LoRA config.
        """
        if self.tts_model.lora_config is None:
            raise RuntimeError(
                "Cannot load LoRA weights: model was not initialized with LoRA config. "
                "Please reinitialize with lora_config or lora_weights_path parameter."
            )
        return self.tts_model.load_lora_weights(lora_weights_path)

    def unload_lora(self):
        """Unload LoRA by resetting all LoRA weights to initial state (effectively disabling LoRA)."""
        self.tts_model.reset_lora_weights()

    def set_lora_enabled(self, enabled: bool):
        """Enable or disable LoRA layers without unloading weights.

        Args:
            enabled: If True, LoRA layers are active; if False, only base model is used.
        """
        self.tts_model.set_lora_enabled(enabled)

    def get_lora_state_dict(self) -> dict:

View on GitHub (pinned to f5a1c6a6b9)

Solutions

  1. Reinitialize VoxCPM with lora_config (rank/alpha) or lora_weights_path so LoRA layers exist, then load weights
  2. If you know your config, pass lora_weights_path directly to the constructor
  3. Verify model.tts_model.lora_config is not None before calling load_lora

Example fix

# before
model = VoxCPM(arch="v1", ...)
model.load_lora("adapter.bin")
# after
from voxcpm.lora import LoRAConfig
cfg = LoRAConfig(rank=8, alpha=16)
model = VoxCPM(arch="v1", lora_config=cfg, ...)
model.load_lora("adapter.bin")
Defensive patterns

Strategy: validation

Validate before calling

if weights_path and lora_config is None:
    raise RuntimeError("construct VoxCPM with lora_config before loading adapters")

Type guard

def can_load_lora(model) -> bool:
    return model.tts_model.lora_config is not None

Try / catch

try:
    model.load_lora(p)
except RuntimeError as e:
    if 'not initialized with LoRA' in str(e): reinit_with_lora(); return
    raise

Prevention

When it happens

Trigger: model = VoxCPM(...) without lora_config, then model.load_lora('adapter.bin').

Common situations: Fine-tuning/serving workflows where the checkpoint is loaded first and adapters are attached later; forgetting that LoRA config must be set at construction time.


AI-assisted analysis of OpenBMB/VoxCPM@f5a1c6a6b9 (2026-08-27). Data as JSON: /api/errors/881e3c7e9d440da3. Report an issue: GitHub.