code: def backward(
      heads, head_grads=None, retain_graph=False, train_mode=True
  ):  # pylint: disable=redefined-outer-name
      """Compute the gradients of heads w.r.t previously marked variables.
  
      Parameters
      ----------
      heads: NDArray or list of NDArray
          Output NDArray(s)
      head_grads: NDArray or list of NDArray or None
          Gradients with respect to heads.
      train_mode: bool, optional
          Whether to do backward for training or predicting.
      """
      head_handles, hgrad_handles = _parse_head(heads, head_grads)
  
      check_call(
          _LIB.MXAutogradBackwardEx(
              len(head_handles),
              head_handles,
              hgrad_handles,
              0,
              ctypes.c_void_p(0),
              ctypes.c_int(retain_graph),
              ctypes.c_int(0),
              ctypes.c_int(train_mode),
              ctypes.c_void_p(0),
              ctypes.c_void_p(0),
          )
      )
  
imports: from array import array
  from threading import Lock
  import traceback
  import ctypes
  from ctypes import c_int, c_void_p, CFUNCTYPE, POINTER, cast
  from .base import _LIB, check_call, string_types, mx_uint
  from .base import NDArrayHandle, c_array, c_handle_array, c_array_buf, MXCallbackList, SymbolHandle
  from .ndarray import NDArray, _ndarray_cls
  from .ndarray import _GRAD_REQ_MAP
  from .symbol import Symbol
  from .util import is_np_array
label_desc: Use image node_id 11 for calling a global function with example usage: backward(heads, head_grads, retain_graph, train_mode) without return types