code: def delete_checkpoints(checkpoint_dir=None, keep="all"):
      """Deletes unneeded checkpoints, keep can be "all", "last", or "none"."""
      assert keep in [
          "all",
          "last",
          "none",
      ], "Invalid keep setting: {}".format(keep)
      checkpoint_dir = (
          checkpoint_dir if checkpoint_dir else get_checkpoint_dir()
      )
      if keep == "all" or not pathmgr.exists(checkpoint_dir):
          return 0
      checkpoints = [
          f for f in pathmgr.ls(checkpoint_dir) if _NAME_PREFIX in f
      ]
      checkpoints = (
          sorted(checkpoints)[:-1] if keep == "last" else checkpoints
      )
      for checkpoint in checkpoints:
          pathmgr.rm(os.path.join(checkpoint_dir, checkpoint))
      return len(checkpoints)
  
file_path: pycls/pycls/core/checkpoint.py
imports: import os
  import pycls.core.distributed
  import torch
  from pycls.core.config import cfg
  from pycls.core.io import pathmgr
  from pycls.core.net import unwrap_model
label_desc: Use image node_id 8 for calling a global function with example usage: delete_checkpoints(checkpoint_dir, keep) and returns: len, int