Lightning-AI/pytorch-lightning · error · RuntimeError
Missing folder: {os.path.dirname(tags_csv)}.
Error message
Missing folder: {os.path.dirname(tags_csv)}. What it means
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.
Source
Thrown at src/lightning/pytorch/core/saving.py:284
>>> vars(hparams) == hparams_new
True
>>> os.remove(path_csv)
"""
fs = get_filesystem(tags_csv)
if not fs.exists(tags_csv):
rank_zero_warn(f"Missing Tags: {tags_csv}.", category=RuntimeWarning)
return {}
with fs.open(tags_csv, "r", newline="") as fp:
csv_reader = csv.reader(fp, delimiter=",")
return {row[0]: convert(row[1]) for row in list(csv_reader)[1:]}
def save_hparams_to_tags_csv(tags_csv: _PATH, hparams: Union[dict, Namespace]) -> None:
fs = get_filesystem(tags_csv)
if not _is_dir(fs, os.path.dirname(tags_csv)):
raise RuntimeError(f"Missing folder: {os.path.dirname(tags_csv)}.")
if isinstance(hparams, Namespace):
hparams = vars(hparams)
with fs.open(tags_csv, "w", newline="") as fp:
fieldnames = ["key", "value"]
writer = csv.DictWriter(fp, fieldnames=fieldnames)
writer.writerow({"key": "key", "value": "value"})
for k, v in hparams.items():
writer.writerow({"key": k, "value": v})
def load_hparams_from_yaml(config_yaml: _PATH, use_omegaconf: bool = True) -> dict[str, Any]:
"""Load hparams from a file.
Args:
config_yaml: Path to config yaml file
use_omegaconf: If omegaconf is available and ``use_omegaconf=True``,View on GitHub (pinned to 9fed5c27d2)
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
Example fix
// before
save_hparams_to_tags_csv("logs/exp1/tags.csv", hparams) # logs/exp1 missing
// after
os.makedirs("logs/exp1", exist_ok=True)
save_hparams_to_tags_csv("logs/exp1/tags.csv", hparams) Defensive patterns
Strategy: validation
Validate before calling
import os os.makedirs(os.path.dirname(tags_csv) or ".", exist_ok=True)
Prevention
- Always create output dirs before writing artifacts
- Wrap artifact writing in a helper that mkdirs first
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Missing folder: {os.path.dirname(config_yaml)}.
- .csv, .yml or .yaml is required for `hparams_file`
- hparams must be dictionary
- Error while merging hparams: the keys {inconsistent_keys} ar
- Received multiple values for {', '.join(duplicated_plugin_ke
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/e19fb560b7ec24b9.
Report an issue: GitHub.