code: def _find_stale_snapshots(fmt, path, n_retains, **kwargs):
      """Finds stale snapshots in a directory, retaining several files
  
      Args:
          fmt (str): format string to match with file names of
              existing snapshots, where prefix and suffix are
              only examined. Also, files' staleness is judged
              by timestamps. The default is metime.
          path (str): a directory path to search for snapshot files.
          n_retains (int): Number of snapshot files to retain
              through the cleanup. Must be a positive integer for any cleanup to
              take place.
          num_retain (int): Same as ``n_retains`` (deprecated).
  
      Yields:
          str: The next stale file that matches format
          ``fmt`` directly under ``path`` and with older ``mtime``,
          excluding newest ``n_retains`` files.
  
      """
      if "num_retain" in kwargs:
          warnings.warn(
              "Argument `num_retain` is deprecated. "
              "Please use `n_retains` instead",
              DeprecationWarning,
          )
          n_retains = kwargs["num_retain"]
  
      snapshot_files = _find_snapshot_files(fmt, path)
      n_removes = len(snapshot_files) - n_retains
      if n_removes > 0:
          for _, filename in snapshot_files[:n_removes]:
              yield filename
  
imports: import os
  import warnings
  import chainer
  from chainer.serializers import npz
  from chainer.training import extension
  from chainer.training.extensions import snapshot_writers
  from chainer.utils import argument
label_desc: Use image node_id 3 for calling a global function with example usage: _find_stale_snapshots(fmt, path, n_retains) without return types