code: def cache(fn):
      """Similar to :func:`functools.cache` (Python >= 3.8) or :func:`functools.lru_cache` with infinite cache size,
      but this also caches exceptions.
      """
      sentinel = object()
      out_cache = {}
      exc_tb_cache = {}
  
      @functools.wraps(fn)
      def wrapper(*args, **kwargs):
          key = args + tuple(kwargs.values())
  
          out = out_cache.get(key, sentinel)
          if out is not sentinel:
              return out
  
          exc_tb = exc_tb_cache.get(key, sentinel)
          if exc_tb is not sentinel:
              raise exc_tb[0].with_traceback(exc_tb[1])
  
          try:
              out = fn(*args, **kwargs)
          except Exception as exc:
              # We need to cache the traceback here as well. Otherwise, each re-raise will add the internal pytest
              # traceback frames anew, but they will only be removed once. Thus, the traceback will be ginormous hiding
              # the actual information in the noise. See https://github.com/pytest-dev/pytest/issues/10363 for details.
              exc_tb_cache[key] = exc, exc.__traceback__
              raise exc
  
          out_cache[key] = out
          return out
  
      return wrapper
  
imports: import contextlib
  import functools
  import itertools
  import os
  import pathlib
  import random
  import re
  import shutil
  import sys
  import tempfile
  import warnings
  from subprocess import CalledProcessError, check_output, STDOUT
  import numpy
  import PIL.Image
  import pytest
  import torch
  import torch.testing
  from PIL import Image
  from torch.testing._comparison import BooleanPair, NonePair, not_close_error_metas, NumberPair, TensorLikePair
  from torchvision import io, tv_tensors
  from torchvision.transforms._functional_tensor import _max_value
  from torchvision.transforms.v2.functional import to_image, to_pil_image
label_desc: Use image node_id 20 for calling a global function with example usage: cache(fn) and returns: wrapper, out, out