wkea's picture
Deploy Space
c388140 verified
Raw History Blame Contribute Delete
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)