Spaces:
Sleeping
Sleeping
Download blockdiffusion/utils/checkpoint.py from wkea/blockdiffusion-api: direct link, hf CLI and curl.
- Browser
- Download file 527 Bytes
-
https://huggingface.co/spaces/wkea/blockdiffusion-api/resolve/main/blockdiffusion/utils/checkpoint.py
- Command line
-
hf download hf://spaces/wkea/blockdiffusion-api/blockdiffusion/utils/checkpoint.py
-
curl -L -o checkpoint.py https://huggingface.co/spaces/wkea/blockdiffusion-api/resolve/main/blockdiffusion/utils/checkpoint.py
527 Bytes
| from __future__ import annotations | |
| import os | |
| from typing import Any, Dict, Optional | |
| import torch | |
| def save_checkpoint(path: str, payload: Dict[str, Any]) -> None: | |
| """ | |
| 保存 checkpoint(会自动创建目录)。 | |
| """ | |
| os.makedirs(os.path.dirname(path), exist_ok=True) | |
| torch.save(payload, path) | |
| def load_checkpoint(path: str, map_location: Optional[str] = None) -> Dict[str, Any]: | |
| """ | |
| 读取 checkpoint。 | |
| """ | |
| return torch.load(path, map_location=map_location) | |