code: def test_checkpoint_deletion(tmpdir, device):
      from speechbrain.utils.checkpoints import Checkpointer
  
      class Recoverable(torch.nn.Module):
          def __init__(self, param):
              super().__init__()
              self.param = torch.nn.Parameter(
                  torch.tensor([param], device=device)
              )
  
          def forward(self, x):
              return x * self.param
  
      recoverable = Recoverable(1.0)
      recoverables = {"recoverable": recoverable}
      recoverer = Checkpointer(tmpdir, recoverables)
      first_ckpt = recoverer.save_checkpoint()
      recoverer.delete_checkpoints()
      # Will not delete only checkpoint by default:
      assert first_ckpt in recoverer.list_checkpoints()
      second_ckpt = recoverer.save_checkpoint()
      recoverer.delete_checkpoints()
      # Oldest checkpoint is deleted by default:
      assert first_ckpt not in recoverer.list_checkpoints()
      # Other syntax also should work:
      recoverer.save_and_keep_only()
      assert second_ckpt not in recoverer.list_checkpoints()
      # Can delete all checkpoints:
      recoverer.delete_checkpoints(num_to_keep=0)
      assert not recoverer.list_checkpoints()
  
      # Now each should be kept:
      # Highest foo
      c1 = recoverer.save_checkpoint(meta={"foo": 2})
      # Latest CKPT after filtering
      c2 = recoverer.save_checkpoint(meta={"foo": 1})
      # Filtered out
      c3 = recoverer.save_checkpoint(meta={"epoch_ckpt": True})
      recoverer.delete_checkpoints(
          num_to_keep=1,
          max_keys=["foo"],
          importance_keys=[lambda c: c.meta["unixtime"]],
          ckpt_predicate=lambda c: "epoch_ckpt" not in c.meta,
      )
      assert all(
          c in recoverer.list_checkpoints() for c in [c1, c2, c3]
      )
      # Reset:
      recoverer.delete_checkpoints(num_to_keep=0)
      assert not recoverer.list_checkpoints()
  
      # Test the keeping multiple checkpoints without predicate:
      # This should be deleted:
      c_to_delete = recoverer.save_checkpoint(meta={"foo": 2})
      # Highest foo
      c1 = recoverer.save_checkpoint(meta={"foo": 3})
      # Latest CKPT after filtering
      c2 = recoverer.save_checkpoint(meta={"foo": 1})
      recoverer.delete_checkpoints(
          num_to_keep=1,
          importance_keys=[
              lambda c: c.meta["unixtime"],
              lambda c: c.meta["foo"],
          ],
      )
      assert all(c in recoverer.list_checkpoints() for c in [c1, c2])
      assert c_to_delete not in recoverer.list_checkpoints()
  
file_path: speechbrain/tests/unittests/test_checkpoints.py
imports: import torch
  import pytest
label_desc: Use image node_id 3 for calling a global function with example usage: test_checkpoint_deletion(tmpdir, device) and returns: unknown