code: def register_checkpoint_hooks(cls, save_on_main_only=True):
      """Class decorator which registers the load, save and transfer hooks.
  
      The hooks must have been marked with mark_as_loader and mark_as_saver,
      and possibly mark_as_transfer.
  
      Arguments
      ---------
      cls : class
          Class to decorate
      save_on_main_only : bool
          By default, the saver is only run on a single process. This argument
          provides the option to run the saver on all processes, needed
          for some savers where data is first gathered before saving.
  
      Example
      -------
      >>> @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 here
      ...         with open(path) as fi:
      ...             self.param = int(fi.read())
      """
      global DEFAULT_LOAD_HOOKS
      global DEFAULT_SAVE_HOOKS
      global DEFAULT_TRANSFER_HOOKS
      for name, method in cls.__dict__.items():
          if hasattr(method, "_speechbrain_saver"):
              # If the save method is to be run on main only, wrap the method with
              # main_process_only() which stops it from running on the other procs
              if save_on_main_only:
                  DEFAULT_SAVE_HOOKS[cls] = main_process_only(method)
              else:
                  DEFAULT_SAVE_HOOKS[cls] = method
              logger.debug(
                  f"Registered checkpoint save hook for {name}"
              )
          if hasattr(method, "_speechbrain_loader"):
              DEFAULT_LOAD_HOOKS[cls] = method
              logger.debug(
                  f"Registered checkpoint load hook for {name}"
              )
          if hasattr(method, "_speechbrain_transfer"):
              DEFAULT_TRANSFER_HOOKS[cls] = method
              logger.debug(
                  f"Registered parameter transfer hook for {name}"
              )
      return cls
  
imports: import torch
  import collections
  import collections.abc
  import os
  import time
  import yaml
  import pathlib
  import inspect
  import shutil
  import logging
  import warnings
  from packaging import version
  import speechbrain.utils._workarounds
  from speechbrain.utils.distributed import main_process_only, if_main_process, ddp_barrier
label_desc: Use image node_id 7 for calling a global function with example usage: register_checkpoint_hooks(cls, save_on_main_only) and returns: cls