{"record":{"id":"881e3c7e9d440da3","repo":"OpenBMB/VoxCPM","slug":"cannot-load-lora-weights-model-was-not-initialize","errorCode":null,"errorMessage":"Cannot load LoRA weights: model was not initialized with LoRA config. Please reinitialize with lora_config or lora_weights_path parameter.","messagePattern":"Cannot load LoRA weights: model was not initialized with LoRA config\\. Please reinitialize with lora_config or lora_weights_path parameter\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/voxcpm/core.py","lineNumber":337,"sourceCode":"\n    # ------------------------------------------------------------------ #\n    # LoRA Interface (delegated to VoxCPMModel)\n    # ------------------------------------------------------------------ #\n    def load_lora(self, lora_weights_path: str) -> tuple:\n        \"\"\"Load LoRA weights from a checkpoint file.\n\n        Args:\n            lora_weights_path: Path to LoRA weights (.pth file or directory\n                containing lora_weights.ckpt).\n\n        Returns:\n            tuple: (loaded_keys, skipped_keys) - lists of loaded and skipped parameter names.\n\n        Raises:\n            RuntimeError: If model was not initialized with LoRA config.\n        \"\"\"\n        if self.tts_model.lora_config is None:\n            raise RuntimeError(\n                \"Cannot load LoRA weights: model was not initialized with LoRA config. \"\n                \"Please reinitialize with lora_config or lora_weights_path parameter.\"\n            )\n        return self.tts_model.load_lora_weights(lora_weights_path)\n\n    def unload_lora(self):\n        \"\"\"Unload LoRA by resetting all LoRA weights to initial state (effectively disabling LoRA).\"\"\"\n        self.tts_model.reset_lora_weights()\n\n    def set_lora_enabled(self, enabled: bool):\n        \"\"\"Enable or disable LoRA layers without unloading weights.\n\n        Args:\n            enabled: If True, LoRA layers are active; if False, only base model is used.\n        \"\"\"\n        self.tts_model.set_lora_enabled(enabled)\n\n    def get_lora_state_dict(self) -> dict:","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/OpenBMB/VoxCPM/blob/f5a1c6a6b901bc732e20f0d59a369f6829ad717a/src/voxcpm/core.py#L319-L355","documentation":"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.","triggerScenarios":"model = VoxCPM(...) without lora_config, then model.load_lora('adapter.bin').","commonSituations":"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.","solutions":["Reinitialize VoxCPM with lora_config (rank/alpha) or lora_weights_path so LoRA layers exist, then load weights","If you know your config, pass lora_weights_path directly to the constructor","Verify model.tts_model.lora_config is not None before calling load_lora"],"exampleFix":"# before\nmodel = VoxCPM(arch=\"v1\", ...)\nmodel.load_lora(\"adapter.bin\")\n# after\nfrom voxcpm.lora import LoRAConfig\ncfg = LoRAConfig(rank=8, alpha=16)\nmodel = VoxCPM(arch=\"v1\", lora_config=cfg, ...)\nmodel.load_lora(\"adapter.bin\")","handlingStrategy":"validation","validationCode":"if weights_path and lora_config is None:\n    raise RuntimeError(\"construct VoxCPM with lora_config before loading adapters\")","typeGuard":"def can_load_lora(model) -> bool:\n    return model.tts_model.lora_config is not None","tryCatchPattern":"try:\n    model.load_lora(p)\nexcept RuntimeError as e:\n    if 'not initialized with LoRA' in str(e): reinit_with_lora(); return\n    raise","preventionTips":["Decide LoRA usage at construction time","Pass lora_weights_path to the constructor when known upfront"],"tags":["lora","fine-tuning","model-state"],"backgroundTag":"lora-adapter-not-initialized","analyzedSha":"f5a1c6a6b901bc732e20f0d59a369f6829ad717a","analyzedAt":"2026-08-27T05:54:30.617Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}