{"record":{"id":"fdee1f5949b38ebc","repo":"hiyouga/LlamaFactory","slug":"please-specify-export-dir-to-save-model","errorCode":null,"errorMessage":"Please specify `export_dir` to save model.","messagePattern":"Please specify `export_dir` to save model\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/train/tuner.py","lineNumber":180,"sourceCode":"\ndef run_exp(args: Optional[dict[str, Any]] = None, callbacks: Optional[list[\"TrainerCallback\"]] = None) -> None:\n    args = read_args(args)\n    if \"-h\" in args or \"--help\" in args:\n        get_train_args(args)\n\n    ray_args = get_ray_args(args)\n    callbacks = callbacks or []\n    if ray_args.use_ray:\n        _ray_training_function(ray_args, config={\"args\": args, \"callbacks\": callbacks})\n    else:\n        _training_function(config={\"args\": args, \"callbacks\": callbacks})\n\n\ndef export_model(args: Optional[dict[str, Any]] = None) -> None:\n    model_args, data_args, finetuning_args, _ = get_infer_args(args)\n\n    if model_args.export_dir is None:\n        raise ValueError(\"Please specify `export_dir` to save model.\")\n\n    if model_args.adapter_name_or_path is not None and model_args.export_quantization_bit is not None:\n        raise ValueError(\"Please merge adapters before quantizing the model.\")\n\n    tokenizer_module = load_tokenizer(model_args)\n    tokenizer = tokenizer_module[\"tokenizer\"]\n    processor = tokenizer_module[\"processor\"]\n    template = get_template_and_fix_tokenizer(tokenizer, data_args)\n    model = load_model(tokenizer, model_args, finetuning_args)  # must after fixing tokenizer to resize vocab\n\n    if getattr(model, \"quantization_method\", None) is not None and model_args.adapter_name_or_path is not None:\n        raise ValueError(\"Cannot merge adapters to a quantized model.\")\n\n    if not isinstance(model, PreTrainedModel):\n        raise ValueError(\"The model is not a `PreTrainedModel`, export aborted.\")\n\n    if getattr(model, \"quantization_method\", None) is not None:  # quantized model adopts float16 type\n        setattr(model.config, \"torch_dtype\", torch.float16)","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/train/tuner.py#L162-L198","documentation":"`export_model` (src/llamafactory/train/tuner.py:180) requires a destination; if `model_args.export_dir` is None it refuses to proceed because model.save_pretrained would have nowhere to write. export_dir is the `export_dir:` key of the export YAML.","triggerScenarios":"Running `llamafactory-cli export` with a YAML missing the `export_dir:` line, or calling export_model(args) with a dict that omits it.","commonSituations":"Quickly built export configs from a train config where export_dir was never added; automation scripts that template export configs.","solutions":["Add `export_dir: /path/to/output` to the export YAML.","If calling programmatically, pass {'export_dir': ...} in the args dict.","Ensure the directory is writable and has space for the sharded weights."],"exampleFix":"# before (yaml)\nmodel_name_or_path: meta-llama/Llama-3-8b\nadapter_name_or_path: output/lora\n\n# after\nmodel_name_or_path: meta-llama/Llama-3-8b\nadapter_name_or_path: output/lora\nexport_dir: output/merged-model","handlingStrategy":"validation","validationCode":"assert export_dir, \"export config must set export_dir\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat export_dir as a required field in export config templates.","Fail fast in wrappers by checking the key before calling export_model."],"tags":["export","config","merge"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}