{"record":{"id":"8b3d7c56d6c9a80e","repo":"hiyouga/LlamaFactory","slug":"please-specify-peft-config-to-merge-and-export-mod","errorCode":null,"errorMessage":"Please specify peft_config to merge and export model.","messagePattern":"Please specify peft_config to merge and export model\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/plugins/model_plugins/peft.py","lineNumber":306,"sourceCode":"\n    logger.info_rank0(f\"Set trainable layers: {trainable_layers}\")\n\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.\")","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/plugins/model_plugins/peft.py#L288-L324","documentation":"merge_and_export_model in the v1 peft plugin requires a peft_config section because export parameters (adapter paths, dtype, export dir) are read from it. Calling export without any peft_config means there is nothing to merge and no export settings, so it fails fast. This usually means the YAML passed to the export command lacks the peft_config block.","triggerScenarios":"Running export with a config file that has no peft_config key, or passing a model_args object where peft_config is None.","commonSituations":"User exports a merged model but wrote settings under top-level keys instead of peft_config; or reused a training YAML for a non-peft run and ran the export entry point with it.","solutions":["Add a peft_config block to the export YAML with name: lora, export_dir, and adapter_name_or_path","If you only want to convert/export a base model without adapters, use the appropriate non-peft export path instead of merge_and_export_model","Verify the CLI subcommand and YAML file actually correspond (export vs train configs)"],"exampleFix":"# before\nmodel_name_or_path: qwen/Qwen2.5-7B\nexport_dir: outputs/merged\n\n# after\nmodel_name_or_path: qwen/Qwen2.5-7B\npeft_config:\n  name: lora\n  export_dir: outputs/merged\n  adapter_name_or_path: outputs/sft/checkpoint-500","handlingStrategy":"validation","validationCode":"raw = yaml.safe_load(open(\"export.yaml\"))\nassert raw.get(\"peft_config\"), \"export YAML requires a peft_config section (name: lora, export_dir, adapter_name_or_path)\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a dedicated export YAML template with the peft_config block pre-filled","Run a config schema check in CI for export pipelines"],"tags":["peft","export","merge","configuration"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}