code: def test_recovery_custom_io(tmpdir):
      from speechbrain.utils.checkpoints import (
          register_checkpoint_hooks,
      )
      from speechbrain.utils.checkpoints import mark_as_saver
      from speechbrain.utils.checkpoints import mark_as_loader
      from speechbrain.utils.checkpoints import Checkpointer
  
      @register_checkpoint_hooks
      class CustomRecoverable:
          def __init__(self, param):
              self.param = int(param)
  
          @mark_as_saver
          def save(self, path):
              with open(path, "w") as fo:
                  fo.write(str(self.param))
  
          @mark_as_loader
          def load(self, path, end_of_epoch):
              del end_of_epoch  # Unused
              with open(path) as fi:
                  self.param = int(fi.read())
  
      custom_recoverable = CustomRecoverable(0)
      recoverer = Checkpointer(
          tmpdir, {"custom_recoverable": custom_recoverable}
      )
      custom_recoverable.param = 1
      # First, make sure no checkpoints are found
      # (e.g. somehow tmpdir contaminated)
      ckpt = recoverer.recover_if_possible()
      assert ckpt is None
      ckpt = recoverer.save_checkpoint()
      custom_recoverable.param = 2
      loaded_ckpt = recoverer.recover_if_possible()
      # Make sure we got the same thing:
      assert ckpt == loaded_ckpt
      # With this custom recoverable, the load is instant:
      assert custom_recoverable.param == 1
  
file_path: speechbrain/tests/unittests/test_checkpoints.py
imports: import torch
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_recovery_custom_io(tmpdir) without return types