{"record":{"id":"dabe41f4e3819c4b","repo":"hiyouga/LlamaFactory","slug":"currently-lora-stage-does-not-support-loading-mode","errorCode":null,"errorMessage":"Currently lora stage does not support loading model by meta.","messagePattern":"Currently lora stage does not support loading model by meta\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/core/model_engine.py","lineNumber":212,"sourceCode":"                **init_kwargs,\n            )\n\n        init_mode = self.args.init_config.name if self.args.init_config is not None else \"init_on_default\"\n        model._init_mode = init_mode\n\n        if hasattr(model, \"thinker\"):\n            model = model.thinker\n            model._init_mode = init_mode\n\n        if self.args.peft_config is None:\n            if self.is_train:\n                logger.info_rank0(\"Fine-tuning mode: full tuning\")\n                model = model.to(torch.float32)\n            else:\n                logger.info_rank0(\"Inference the original model\")\n        else:\n            if self.args.peft_config.name == \"lora\" and init_mode == \"init_on_meta\":\n                raise ValueError(\"Currently lora stage does not support loading model by meta.\")\n\n            from ..plugins.model_plugins.peft import PeftPlugin\n\n            model = PeftPlugin(self.args.peft_config.name)(\n                model,\n                peft_config=self.args.peft_config,\n                is_train=self.is_train,\n            )\n\n        if self.args.kernel_config is not None:\n            from ..plugins.model_plugins.kernels.interface import apply_kernels\n\n            model = apply_kernels(model, self.args.kernel_config, require_logits=self.is_train)\n\n        return model\n\n\nif __name__ == \"__main__\":","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/core/model_engine.py#L194-L230","documentation":"Raised by the v1 ModelEngine when a LoRA adapter setup is combined with init_mode == 'init_on_meta'. The engine can materialize the base model on the meta device for full tuning, but the PeftPlugin path needs real module instances to wrap with LoRA layers, so meta-device initialization is explicitly rejected. It is a hard stop before any weights are touched.","triggerScenarios":"Constructing the v1 model engine with args.peft_config set (peft_config.name == 'lora') while the model is created with init_mode='init_on_meta' (e.g. a trainer/kernel plugin that requests meta-device init to save CPU memory).","commonSituations":"Enabling a memory-saving meta-device/kernel config (kernel_config, FSDP2-style delayed init) together with a LoRA finetune; porting a v0 workflow that loaded models on meta into the experimental v1 architecture.","solutions":["Change init_mode away from 'init_on_meta' (e.g. normal eager/deferred weight loading) so the LoRA plugin can wrap concrete modules","Or switch from LoRA to full fine-tuning (drop peft_config), which does support meta init in this engine","Or stay on the v0 path (do not set USE_V1=1) where LoRA + meta loading combinations may be handled differently"],"exampleFix":"# before\nengine = ModelEngine(args_with(peft_config=lora_cfg), init_mode=\"init_on_meta\")  # ValueError\n\n# after\nengine = ModelEngine(args_with(peft_config=lora_cfg), init_mode=\"deferred\")  # concrete modules for PeftPlugin","handlingStrategy":"validation","validationCode":"def check_lora_init_mode(peft_config, init_mode: str) -> None:\n    if peft_config is not None and peft_config.name == \"lora\" and init_mode == \"init_on_meta\":\n        raise SystemExit(\"LoRA cannot use init_on_meta; pick another init_mode or full tuning\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep LoRA runs on a non-meta init_mode in v1 configs","Add a config lint rule: reject YAMLs combining peft: lora with meta-device/kernel init settings"],"tags":["lora","peft","model-loading","meta-device","v1"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}