{"record":{"id":"f6502d1889ff21c6","repo":"hiyouga/LlamaFactory","slug":"save-dir-already-exists-use-another-one","errorCode":null,"errorMessage":"`save_dir` already exists, use another one.","messagePattern":"`save_dir` already exists, use another one\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/evaluation_args.py","lineNumber":60,"sourceCode":"        default=\"en\",\n        metadata={\"help\": \"Language used at evaluation.\"},\n    )\n    n_shot: int = field(\n        default=5,\n        metadata={\"help\": \"Number of exemplars for few-shot learning.\"},\n    )\n    save_dir: str | None = field(\n        default=None,\n        metadata={\"help\": \"Path to save the evaluation results.\"},\n    )\n    download_mode: DownloadMode = field(\n        default=DownloadMode.REUSE_DATASET_IF_EXISTS,\n        metadata={\"help\": \"Download mode used for the evaluation datasets.\"},\n    )\n\n    def __post_init__(self):\n        if self.save_dir is not None and os.path.exists(self.save_dir):\n            raise ValueError(\"`save_dir` already exists, use another one.\")\n","sourceCodeStart":42,"sourceCodeEnd":61,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/evaluation_args.py#L42-L61","documentation":"EvaluationArguments.__post_init__ (src/llamafactory/hparams/evaluation_args.py:60) refuses to overwrite an existing output directory so that previous evaluation results (predictions, metrics) are not silently clobbered. The check runs os.path.exists(save_dir) at argument construction time.","triggerScenarios":"Running llamafactory-cli train/eval with an eval config whose save_dir points to a directory that already exists on disk (from a previous run).","commonSituations":"Re-running an evaluation with the same output path after an earlier run, or a resume/retry after a partially completed evaluation that already created the folder.","solutions":["Delete or move the old directory: rm -rf ./eval_results (after confirming you no longer need it).","Point save_dir to a fresh path, e.g. save_dir: eval_results/run2 (timestamped names avoid collisions).","In scripts, generate a unique directory per run (e.g. with a timestamp) so reruns never collide."],"exampleFix":"# before (bash)\nllamafactory-cli train examples/evaluation/bleu.yaml  # save_dir: saved_results already exists\n\n# after (bash)\nrm -rf saved_results\nllamafactory-cli train examples/evaluation/bleu.yaml","handlingStrategy":"validation","validationCode":"import os, time\n\ndef fresh_save_dir(base: str) -> str:\n    d = f\"{base}/{time.strftime('%Y%m%d-%H%M%S')}\"\n    if os.path.exists(d):\n        raise FileExistsError(f\"refusing to overwrite {d}\")\n    return d","typeGuard":null,"tryCatchPattern":"try:\n    eval_args = EvaluationArguments(save_dir=\"./saved_results\", ...)\nexcept ValueError:\n    # archive the old results rather than deleting blindly\n    os.rename(\"./saved_results\", f\"./saved_results.bak-{int(time.time())}\")","preventionTips":["Generate timestamped save_dir paths in experiment scripts so reruns never collide.","Treat the error as a guardrail: archive old results instead of bypassing the check."],"tags":["config","filesystem","evaluation","idempotency"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}