class_docstr: Try to convert inputs to FP16 and CPU if got a PyTorch's CUDA Out of
  Memory error. It will do the following steps:
  
      1. First retry after calling `torch.cuda.empty_cache()`.
      2. If that still fails, it will then retry by converting inputs
        to FP16.
      3. If that still fails trying to convert inputs to CPUs.
        In this case, it expects the function to dispatch to
        CPU implementation.
  
  Args:
      to_cpu (bool): Whether to convert outputs to CPU if get an OOM
          error. This will slow down the code significantly.
          Defaults to True.
      test (bool): Skip `_ignore_torch_cuda_oom` operate that can use
          lightweight data in unit test, only used in
          test unit. Defaults to False.
  
  Examples:
      >>> from mmdet.utils.memory import AvoidOOM
      >>> AvoidCUDAOOM = AvoidOOM()
      >>> output = AvoidOOM.retry_if_cuda_oom(
      >>>     some_torch_function)(input1, input2)
      >>> # To use as a decorator
      >>> # from mmdet.utils import AvoidCUDAOOM
      >>> @AvoidCUDAOOM.retry_if_cuda_oom
      >>> def function(*args, **kwargs):
      >>>     return None
  ```
  
  Note:
      1. The output may be on CPU even if inputs are on GPU. Processing
          on CPU will slow down the code significantly.
      2. When converting inputs to CPU, it will only look at each argument
          and check if it has `.device` and `.to` for conversion. Nested
          structures of tensors are not supported.
      3. Since the function might be called more than once, it has to be
          stateless.
code: def __init__(self, to_cpu=True, test=False):
      self.to_cpu = to_cpu
      self.test = test
  
file_path: mmdetection/mmdet/utils/memory.py
imports: import warnings
  from collections import abc
  from contextlib import contextmanager
  from functools import wraps
  import torch
  from mmengine.logging import MMLogger
label_desc: Use image node_id 1 to create a new AvoidOOM object  with example: obj = AvoidOOM(to_cpu, test)