{"record":{"id":"e19fb560b7ec24b9","repo":"Lightning-AI/pytorch-lightning","slug":"missing-folder-os-path-dirname-tags-csv","errorCode":null,"errorMessage":"Missing folder: {os.path.dirname(tags_csv)}.","messagePattern":"Missing folder: (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/saving.py","lineNumber":284,"sourceCode":"    >>> vars(hparams) == hparams_new\n    True\n    >>> os.remove(path_csv)\n\n    \"\"\"\n    fs = get_filesystem(tags_csv)\n    if not fs.exists(tags_csv):\n        rank_zero_warn(f\"Missing Tags: {tags_csv}.\", category=RuntimeWarning)\n        return {}\n\n    with fs.open(tags_csv, \"r\", newline=\"\") as fp:\n        csv_reader = csv.reader(fp, delimiter=\",\")\n        return {row[0]: convert(row[1]) for row in list(csv_reader)[1:]}\n\n\ndef save_hparams_to_tags_csv(tags_csv: _PATH, hparams: Union[dict, Namespace]) -> None:\n    fs = get_filesystem(tags_csv)\n    if not _is_dir(fs, os.path.dirname(tags_csv)):\n        raise RuntimeError(f\"Missing folder: {os.path.dirname(tags_csv)}.\")\n\n    if isinstance(hparams, Namespace):\n        hparams = vars(hparams)\n\n    with fs.open(tags_csv, \"w\", newline=\"\") as fp:\n        fieldnames = [\"key\", \"value\"]\n        writer = csv.DictWriter(fp, fieldnames=fieldnames)\n        writer.writerow({\"key\": \"key\", \"value\": \"value\"})\n        for k, v in hparams.items():\n            writer.writerow({\"key\": k, \"value\": v})\n\n\ndef load_hparams_from_yaml(config_yaml: _PATH, use_omegaconf: bool = True) -> dict[str, Any]:\n    \"\"\"Load hparams from a file.\n\n        Args:\n            config_yaml: Path to config yaml file\n            use_omegaconf: If omegaconf is available and ``use_omegaconf=True``,","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/saving.py#L266-L302","documentation":"RuntimeError from save_hparams_to_tags_csv when the directory portion of the tags_csv path does not exist on the target filesystem (checked via fsspec). The writer refuses to create the file if its parent folder is missing.","triggerScenarios":"Calling save_hparams_to_tags_csv('newdir/tags.csv', hparams) when 'newdir' doesn't exist; also triggered indirectly by trainer save / checkpointing flows that write a tags.csv into a not-yet-created folder.","commonSituations":"Custom checkpoint callbacks writing to nested paths, or fsspec remote paths (s3://, gs://) where the directory check fails due to permissions or a wrong bucket/prefix.","solutions":["Create the directory first: os.makedirs(os.path.dirname(path), exist_ok=True)","Fix a typo'd or missing parent path in the argument","For remote filesystems, verify the bucket/prefix exists and credentials are valid"],"exampleFix":"// before\nsave_hparams_to_tags_csv(\"logs/exp1/tags.csv\", hparams)  # logs/exp1 missing\n// after\nos.makedirs(\"logs/exp1\", exist_ok=True)\nsave_hparams_to_tags_csv(\"logs/exp1/tags.csv\", hparams)","handlingStrategy":"validation","validationCode":"import os\nos.makedirs(os.path.dirname(tags_csv) or \".\", exist_ok=True)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create output dirs before writing artifacts","Wrap artifact writing in a helper that mkdirs first"],"tags":["lightning","hparams","csv","missing-directory","fsspec"],"backgroundTag":"output-directory-missing","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}