File size: 533 Bytes
59630ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | """
This repo is forked from [Boyuan Chen](https://boyuan.space/)'s research
template [repo](https://github.com/buoyancy99/research-template).
By its MIT license, you must keep the above sentence in `README.md`
and the `LICENSE` file to credit the author.
"""
import torch
from pathlib import Path
def safe_torch_save(obj, path: Path):
"""
Safely save a torch object to disk.
If the path does not exist, create folders as needed.
"""
path.parent.mkdir(parents=True, exist_ok=True)
torch.save(obj, path)
|