{"record":{"id":"133300f33b69b768","repo":"hiyouga/LlamaFactory","slug":"please-specify-export-dir","errorCode":null,"errorMessage":"Please specify export_dir.","messagePattern":"Please specify export_dir\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/plugins/model_plugins/peft.py","lineNumber":312,"sourceCode":"    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)\n        model = model.to(target_dtype)\n        logger.info_rank0(f\"Converted model to {export_peft_config.infer_dtype}.\")\n\n    logger.info_rank0(f\"Exporting model to {export_peft_config.export_dir}...\")","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/plugins/model_plugins/peft.py#L294-L330","documentation":"The export routine reads export_dir from the parsed LoRA peft_config to know where to write the merged model; without it there is no destination and it aborts before loading the model. It is a required field of the export flow, distinct from training output_dir.","triggerScenarios":"peft_config exists with name lora and adapter paths, but export_dir key is missing from the peft_config section.","commonSituations":"User puts the destination in top-level export_dir or output_dir instead of under peft_config; or copies a training YAML and forgets the export-specific keys.","solutions":["Add export_dir under peft_config in the export YAML","Make sure it is not nested at the top level of the file","Ensure the directory is writable and has enough disk space for a full-precision merge"],"exampleFix":"# before\npeft_config:\n  name: lora\n  adapter_name_or_path: outputs/sft\n\n# after\npeft_config:\n  name: lora\n  adapter_name_or_path: outputs/sft\n  export_dir: outputs/merged","handlingStrategy":"validation","validationCode":"pc = raw.get(\"peft_config\", {})\nassert pc.get(\"export_dir\"), \"peft_config.export_dir is required for merge-and-export\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Nest export settings under peft_config, not at YAML top level","Check free disk space before merge jobs"],"tags":["peft","export","configuration"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}