{"record":{"id":"e9ab7f8ba3b45ad8","repo":"huggingface/transformers","slug":"provided-path-should-be-a-directory-not-a-fi","errorCode":null,"errorMessage":"Provided path ({}) 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/generation/configuration_utils.py","lineNumber":907,"sourceCode":"                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\n        # At save time, validate the instance enforcing strictness -- if any warning/exception would be thrown, we\n        # refuse to save the instance.\n        # This strictness is enforced to prevent bad configurations from being saved and re-used.\n        try:\n            self.validate(strict=True)\n        except ValueError as exc:\n            raise ValueError(str(exc) + \"\\n\\nFix these issues to save the configuration.\")\n\n        config_file_name = config_file_name if config_file_name is not None else GENERATION_CONFIG_NAME\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        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\", str(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        output_config_file = os.path.join(save_directory, config_file_name)\n\n        self.to_json_file(output_config_file, use_diff=True, keys_to_pop=[\"compile_config\"])\n        logger.info(f\"Configuration saved in {output_config_file}\")\n\n        if push_to_hub:\n            self._upload_modified_files(\n                save_directory,\n                repo_id,","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/configuration_utils.py#L889-L925","documentation":"AssertionError from GenerationConfig.save_pretrained(): save_directory exists but is a regular file, not a directory. The method must create generation_config.json inside that directory, so a file path (often a mistyped path or an existing JSON file path) is rejected up front.","triggerScenarios":"cfg.save_pretrained('config.json') or any existing file path; passing a path where a previous run created a file with the intended directory name.","commonSituations":"User passes the desired output FILE name instead of the directory; a stale file (not directory) left at the target path by an earlier tool.","solutions":["Pass a directory path: cfg.save_pretrained('./my_config_dir') — the file generation_config.json is created inside it","If a stray file occupies the name, rename or remove it: os.remove('bad_path') then retry","Check first: assert not os.path.isfile(save_directory) in your own code before calling"],"exampleFix":"# before\ncfg.save_pretrained('my_gen_config.json')\n# after\ncfg.save_pretrained('./output_dir')  # writes ./output_dir/generation_config.json","handlingStrategy":"validation","validationCode":"import os\nif os.path.exists(save_directory) and not os.path.isdir(save_directory):\n    raise ValueError(f'{save_directory} is a file; pass a directory')","typeGuard":"def is_save_dir(p: str) -> bool:\n    import os\n    return not os.path.exists(p) or os.path.isdir(p)","tryCatchPattern":null,"preventionTips":["save_pretrained always takes a directory; the JSON filename is chosen by the library","Check os.path.isdir(path) or use a fresh output directory per run"],"tags":["generation-config","save","filesystem","path"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}