code: def base_closure(x, model, y_pred, y_true, crit, loss, opt):
      """Function to create a standard pytorch closure using objects taken from state under the given keys.
  
      Args:
          x: State key under which the input data is stored
          model: State key under which the pytorch model is stored
          y_pred: State key under which the predictions will be stored
          y_true: State key under which the targets are stored
          crit: State key under which the criterion function is stored (function of state or (y_pred, y_true))
          loss: State key under which the loss will be stored
          opt: State key under which the optimsiser is stored
  
      Returns:
          function: Standard closure function
      """
  
      def closure(state):
          # Zero grads
          state[opt].zero_grad()
  
          _forward_with_exceptions(x, model, y_pred, state)
  
          state[torchbearer.CALLBACK_LIST].on_forward(state)
  
          # Loss Calculation
          try:
              state[loss] = state[crit](state)
          except TypeError:
              loss_function_params = _get_param_list(
                  state[y_pred]
              ) + _get_param_list(state[y_true])
              state[loss] = state[crit](*loss_function_params)
  
          state[torchbearer.CALLBACK_LIST].on_criterion(state)
  
          # Backwards pass
          state[loss].backward(**state[torchbearer.BACKWARD_ARGS])
  
          state[torchbearer.CALLBACK_LIST].on_backward(state)
  
      return closure
  
imports: import functools
  import traceback
  import warnings
  import torch
  from packaging import version
  import torchbearer
  import sys
label_desc: Use image node_id 6 for calling a global function with example usage: base_closure(x, model, y_pred, y_true, crit, loss, opt) and returns: closure