class_docstr: Save checkpoints periodically for persistence and recovery.
  
  Reference: https://github.com/PyTorchLightning/pytorch-lightning/blob/bfa8b7be/pytorch_lightning/callbacks/model_checkpoint.py
  
  Parameters
  ----------
  dirpath
      Directory to save the checkpoint file.
  filename
      Checkpoint filename. Can contain named formatting options to be auto-filled.
      For example: ``{iter:03d}-{reward:.2f}.pth``.
      Supported argument names are:
  
      - iter (int)
      - metrics in ``trainer.metrics``
      - time string, in the format of ``%Y%m%d%H%M%S``
  save_latest
      Save the latest checkpoint in ``latest.pth``.
      If ``link``, ``latest.pth`` will be created as a softlink.
      If ``copy``, ``latest.pth`` will be stored as an individual copy.
      Set to none to disable this.
  every_n_iters
      Checkpoints are saved at the end of every n iterations of training,
      after validation if applicable.
  time_interval
      Maximum time (seconds) before checkpoints save again.
  save_on_fit_end
      Save one last checkpoint at the end to fit.
      Do nothing if a checkpoint is already saved there.
class_docstr_tok: ["Save","checkpoints","periodically","for","persistence","and","recovery",".","Reference",":","https",":","\/\/github.com\/PyTorchLightning\/pytorch-lightning\/blob\/bfa8b7be\/pytorch_lightning\/callbacks\/model_checkpoint.py","Parameters","--","--","--","--","--","dirpath","Directory","to","save","the","checkpoint","file",".","filename","Checkpoint","filename",".","Can","contain","named","formatting","options","to","be","auto-filled",".","For","example",":","``","{","iter:03d","}","-","{","reward",":",".2f","}",".pth","``",".","Supported","argument","names","are",":","-","iter","(","int",")","-","metrics","in","``","trainer.metrics","``","-","time","string",",","in","the","format","of","``","%","Y","%","m","%","d","%","H","%","M","%","S","``","save_latest","Save","the","latest","checkpoint","in","``","latest.pth","``",".","If","``","link","``",",","``","latest.pth","``","will","be","created","as","a","softlink",".","If","``","copy","``",",","``","latest.pth","``","will","be","stored","as","an","individual","copy",".","Set","to","none","to","disable","this",".","every_n_iters","Checkpoints","are","saved","at","the","end","of","every","n","iterations","of","training",",","after","validation","if","applicable",".","time_interval","Maximum","time","(","seconds",")","before","checkpoints","save","again",".","save_on_fit_end","Save","one","last","checkpoint","at","the","end","to","fit",".","Do","nothing","if","a","checkpoint","is","already","saved","there","."]
code: def __init__(
      self,
      dirpath: Path,
      filename: str = "{iter:03d}.pth",
      save_latest: Literal["link", "copy"] | None = "link",
      every_n_iters: int | None = None,
      time_interval: int | None = None,
      save_on_fit_end: bool = True,
  ):
      self.dirpath = Path(dirpath)
      self.filename = filename
      self.save_latest = save_latest
      self.every_n_iters = every_n_iters
      self.time_interval = time_interval
      self.save_on_fit_end = save_on_fit_end
  
      self._last_checkpoint_name: str | None = None
      self._last_checkpoint_iter: int | None = None
      self._last_checkpoint_time: float | None = None
  
imports: from __future__ import annotations
  import copy
  import os
  import shutil
  import time
  from datetime import datetime
  from pathlib import Path
  from typing import Any, List, TYPE_CHECKING
  import numpy
  import pandas
  import torch
  from qlib.log import get_module_logger
  from qlib.typehint import Literal
label_desc: Use image node_id 1 to create a new Checkpoint object from inherited base classes: Callback with example: obj = Checkpoint(dirpath, filename, save_latest, every_n_iters, time_interval, save_on_fit_end)