code: def apex_closure():
      from apex import amp
  
      def _apex_closure(state):
          # Zero grads
          state[torchbearer.OPTIMIZER].zero_grad()
  
          _forward_with_exceptions(
              torchbearer.X,
              torchbearer.MODEL,
              torchbearer.Y_PRED,
              state,
          )
  
          state[torchbearer.CALLBACK_LIST].on_forward(state)
  
          # Loss Calculation
          try:
              state[torchbearer.LOSS] = state[torchbearer.CRITERION](
                  state
              )
          except TypeError:
              loss_function_params = _get_param_list(
                  state[torchbearer.Y_PRED]
              ) + _get_param_list(state[torchbearer.Y_TRUE])
              state[torchbearer.LOSS] = state[torchbearer.CRITERION](
                  *loss_function_params
              )
  
          state[torchbearer.CALLBACK_LIST].on_criterion(state)
  
          # Backwards pass
          with amp.scale_loss(
              state[torchbearer.LOSS], state[torchbearer.OPTIMIZER]
          ) as scaled_loss:
              scaled_loss.backward(**state[torchbearer.BACKWARD_ARGS])
  
          state[torchbearer.CALLBACK_LIST].on_backward(state)
  
      return _apex_closure
  
imports: import functools
  import traceback
  import warnings
  import torch
  from packaging import version
  import torchbearer
  import sys
label_desc: Use image node_id 7 for calling a global function with example usage: apex_closure() and returns: _apex_closure