code: def cache_net_infer(net, use_caching, y_preds):
      """Caching context for ``skorch.NeuralNet`` instance.
  
      Returns a modified version of the net whose ``infer`` method will
      subsequently return cached predictions. Leaving the context will
      undo the overwrite of the ``infer`` method.
  
      Deprecated.
  
      """
      # TODO: remove this function
  
      warnings.warn(
          "cache_net_infer is no longer uesd to provide caching for "
          "the scoring callbacks and will hence be removed in a "
          "future release.",
          DeprecationWarning,
      )
  
      if not use_caching:
          yield net
          return
      y_preds = iter(y_preds)
      net.infer = lambda *a, **kw: next(y_preds)
  
      try:
          yield net
      finally:
          # By setting net.infer we define an attribute `infer`
          # that precedes the bound method `infer`. By deleting
          # the entry from the attribute dict we undo this.
          del net.__dict__["infer"]
  
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 1 for calling a global function with example usage: cache_net_infer(net, use_caching, y_preds) without return types