{"record":{"id":"4d7ab4f4448c678a","repo":"huggingface/transformers","slug":"provided-path-save-directory-should-be-a-direc","errorCode":null,"errorMessage":"Provided path ({save_directory}) should be a directory, not a file","messagePattern":"Provided path \\((.+?)\\) should be a directory, not a file","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":570,"sourceCode":"        self.rope_parameters = value\n\n    def save_pretrained(self, save_directory: str | os.PathLike, push_to_hub: bool = False, **kwargs):\n        \"\"\"\n        Save a configuration object to the directory `save_directory`, so that it can be re-loaded using the\n        [`~PreTrainedConfig.from_pretrained`] class method.\n\n        Args:\n            save_directory (`str` or `os.PathLike`):\n                Directory where the configuration JSON file will be saved (will be created if it does not exist).\n            push_to_hub (`bool`, *optional*, defaults to `False`):\n                Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the\n                repository you want to push to with `repo_id` (will default to the name of `save_directory` in your\n                namespace).\n            kwargs (`dict[str, Any]`, *optional*):\n                Additional key word arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.\n        \"\"\"\n        if os.path.isfile(save_directory):\n            raise AssertionError(f\"Provided path ({save_directory}) should be a directory, not a file\")\n\n        generation_parameters = self._get_generation_parameters()\n        if len(generation_parameters) > 0:\n            raise ValueError(\n                \"Some generation parameters are set in the model config. These should go into `model.generation_config`\"\n                f\"as opposed to `model.config`. \\nGeneration parameters found: {str(generation_parameters)}\",\n            )\n\n        os.makedirs(save_directory, exist_ok=True)\n\n        if push_to_hub:\n            commit_message = kwargs.pop(\"commit_message\", None)\n            repo_id = kwargs.pop(\"repo_id\", save_directory.split(os.path.sep)[-1])\n            repo_id = hf_api().create_repo(repo_id, exist_ok=True, **kwargs).repo_id\n            files_timestamps = self._get_files_timestamps(save_directory)\n\n        # This attribute is important to know on load, but should not be serialized on save.\n        if \"transformers_weights\" in self:","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L552-L588","documentation":"AssertionError from PretrainedConfig.save_pretrained when the given save_directory path is an existing file. The method must create config.json inside a directory, so passing a file path (including a path ending in config.json) is rejected before any write happens.","triggerScenarios":"config.save_pretrained('model_dir/config.json') instead of config.save_pretrained('model_dir'); passing an existing file path of any kind; paths computed by joining a filename onto a base path that already exists as a file.","commonSituations":"Adapting save code from APIs that take full file paths (e.g. json.dump to a file); CLI scripts whose output argument is the config filename; typos where the parent directory was never created and a same-named file exists.","solutions":["Pass the directory only: config.save_pretrained('output_dir') — it creates the dir and writes config.json inside","If the path exists as a stale file, remove or rename it, then retry with the directory","Guard with os.path.isdir(...) in shared save helpers"],"exampleFix":"# before\nconfig.save_pretrained('out/config.json')\n# after\nconfig.save_pretrained('out')","handlingStrategy":"type-guard","validationCode":"out = Path(save_path)\nif out.is_file():\n    out = out.parent\nout.mkdir(parents=True, exist_ok=True)\nconfig.save_pretrained(out)","typeGuard":"def is_save_dir(p: str) -> bool:\n    path = Path(p)\n    return path.suffix == '' or path.is_dir()  # config.json suffix means a file was passed","tryCatchPattern":"try:\n    config.save_pretrained(save_path)\nexcept AssertionError as e:\n    if 'should be a directory' in str(e):\n        config.save_pretrained(Path(save_path).parent)\n    else:\n        raise","preventionTips":["Pass directories to save_pretrained; the method writes config.json itself","Never append 'config.json' to save paths in shared helpers"],"tags":["config","serialization","filesystem"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}