code: def catch_cuda_oom(enabled: bool = True):
      if enabled:
          try:
              yield
          except RuntimeError as re:
              if "CUDA out of memory." in repr(re):
                  LOGGER.exception(
                      "CUDA Out-Of-Memory Caught and Execution Resumed.",
                      exc_info=re,
                  )
                  torch.cuda.empty_cache()
                  torch.cuda.synchronize()
              else:
                  raise re
      else:
          yield
  
imports: from typing_extensions import Final
  import logging
  import torch
  from contextlib import contextmanager
label_desc: Use image node_id 1 for calling a global function with example usage: catch_cuda_oom(enabled) without return types