File size: 527 Bytes
c388140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)