code: def _cache_net_forward_iter(net, use_caching, y_preds):
      """Caching context for ``skorch.NeuralNet`` instance.
  
      Returns a modified version of the net whose ``forward_iter``
      method will subsequently return cached predictions. Leaving the
      context will undo the overwrite of the ``forward_iter`` method.
  
      Note that the net may override the use of caching.
  
      """
      if net.use_caching != "auto":
          use_caching = net.use_caching
  
      if not use_caching:
          yield net
          return
      y_preds = iter(y_preds)
  
      # pylint: disable=unused-argument
      def cached_forward_iter(*args, device=net.device, **kwargs):
          for yp in y_preds:
              yield to_device(yp, device=device)
  
      net.forward_iter = cached_forward_iter
      try:
          yield net
      finally:
          # By setting net.forward_iter we define an attribute
          # `forward_iter` that precedes the bound method
          # `forward_iter`. By deleting the entry from the attribute
          # dict we undo this.
          del net.__dict__["forward_iter"]
  
imports: from contextlib import contextmanager
  from contextlib import suppress
  from functools import partial
  import warnings
  import numpy
  import sklearn
  from sklearn.metrics import make_scorer, check_scoring
  from skorch.callbacks import Callback
  from skorch.dataset import unpack_data
  from sklearn.metrics._scorer import _BaseScorer
  from skorch.utils import data_from_dataset
  from skorch.utils import is_skorch_dataset
  from skorch.utils import to_numpy
  from skorch.utils import check_indexing
  from skorch.utils import to_device
label_desc: Use image node_id 2 for calling a global function with example usage: _cache_net_forward_iter(net, use_caching, y_preds) without return types