{"record":{"id":"49b223f8a1a3efc2","repo":"hiyouga/LlamaFactory","slug":"currently-merge-and-export-model-function-is-only","errorCode":null,"errorMessage":"Currently merge and export model function is only supported for lora.","messagePattern":"Currently merge and export model function is only supported for lora\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/plugins/model_plugins/peft.py","lineNumber":308,"sourceCode":"\n    # Count trainable params for verification\n    trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)\n    all_params = sum(p.numel() for p in model.parameters())\n    logger.info_rank0(\n        f\"trainable params: {trainable_params} || all params: {all_params} || trainable%: {100 * trainable_params / all_params:.4f}\"\n    )\n\n    return model\n\n\ndef merge_and_export_model(args: InputArgument = None):\n    model_args, _, _, _ = get_args(args)\n\n    raw_config = model_args.peft_config\n    if raw_config is None:\n        raise ValueError(\"Please specify peft_config to merge and export model.\")\n    if raw_config.name != \"lora\":\n        raise ValueError(\"Currently merge and export model function is only supported for lora.\")\n\n    export_peft_config = PeftPlugin.parse_params(raw_config, LoraParams)\n    if export_peft_config.export_dir is None:\n        raise ValueError(\"Please specify export_dir.\")\n    if export_peft_config.adapter_name_or_path is None:\n        raise ValueError(\"Please set adapter_name_or_path to merge adapters into base model.\")\n\n    logger.info_rank0(\"Loading model for export...\")\n    model_engine = ModelEngine(model_args, is_train=False)\n    model = model_engine.model\n    tokenizer = model_engine.processor\n\n    if export_peft_config.infer_dtype == \"auto\":\n        if model.config.torch_dtype == torch.float32 and torch.cuda.is_bf16_supported():\n            model = model.to(torch.bfloat16)\n            logger.info_rank0(\"Converted model to bfloat16.\")\n    else:\n        target_dtype = getattr(torch, export_peft_config.infer_dtype)","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/plugins/model_plugins/peft.py#L290-L326","documentation":"The v1 merge-and-export path only implements adapter merging for LoRA: it parses the peft_config with LoraParams and calls PEFT LoRA merge APIs. Setting peft_config.name to anything else (freeze, vera, etc.) is rejected because no merge implementation exists for those methods. Freeze tuning has no separate adapter weights to merge anyway.","triggerScenarios":"peft_config present with name != 'lora' (e.g. 'freeze', 'llamaplus') while running merge_and_export_model / the export command.","commonSituations":"User trains with freeze or another method and then tries to export a merged model from the same YAML; or the name field was left from a previous experiment.","solutions":["Set peft_config.name to lora for the export run","If you trained with freeze, no merge is needed: freeze-trained weights are already in the full model, save/export the checkpoint directly","Check spelling/case of the name field (must be exactly 'lora')"],"exampleFix":"# before\npeft_config:\n  name: freeze\n\n# after\npeft_config:\n  name: lora","handlingStrategy":"validation","validationCode":"name = raw.get(\"peft_config\", {}).get(\"name\")\nassert name == \"lora\", f\"merge_and_export only supports lora, got {name!r}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember freeze/other methods have no adapter to merge; save full weights instead","Pin the peft name field explicitly in export configs"],"tags":["peft","export","lora","configuration"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}