code: def scheduled(fn):
      @functools.wraps(fn)
      def scheduled_predict(
          self,
          model_file,
          x,
          *args,
          key=None,
          config_overrides=None,
          **kwargs,
      ):
          # this is just for backwards compat, should always have a blob key going forward
          cache_key = kwargs.pop("cache_key", None)
          model = self._rotate_in_model(
              model_file,
              key=key,
              config_overrides=config_overrides,
              cache_key=cache_key,
          )
          try:
              preds = fn(
                  self,
                  model_file=model_file,
                  x=x,
                  *args,
                  model=model,
                  **kwargs,
              )
          except Exception as orig_except:
              LOGGER.warning(
                  "Exception '{}' raised. Closing all models and retrying".format(
                      orig_except
                  )
              )
              # Close everything to make sure we have available memory
              self.close_all()
              try:
                  # Reload in preparation for prediction
                  model = self._rotate_in_model(
                      model_file,
                      key=key,
                      config_overrides=config_overrides,
                      cache_key=cache_key,
                  )
                  preds = fn(
                      self,
                      model_file=model_file,
                      x=x,
                      *args,
                      model=model,
                      **kwargs,
                  )
              except Exception as e:
                  raise FinetuneSchedulerError(
                      "Original Error: {}, Retry Error: {}".format(
                          str(orig_except), str(e)
                      )
                  )
          self._update_memory_limit(model)
          return preds
  
      return scheduled_predict
  
imports: from collections import OrderedDict
  import gc
  import logging
  import functools
  import psutil
  from finetune.target_models.sequence_labeling import SequenceLabeler
  import tensorflow
  from finetune.base import BaseModel
  from finetune.custom_ops import BytesInUse, BytesLimit, MaxBytesInUse
  from finetune.errors import FinetuneSchedulerError
label_desc: Use image node_id 2 for calling a global function with example usage: scheduled(fn) and returns: scheduled_predict, preds