code: def set_training(train_mode):  # pylint: disable=redefined-outer-name
      """Set status to training/predicting. This affects ctx.is_train in operator
      running context. For example, Dropout will drop inputs randomly when
      train_mode=True while simply passing through if train_mode=False.
  
      Parameters
      ----------
      train_mode: bool
  
      Returns
      -------
      previous state before this set.
      """
      prev = ctypes.c_int()
      check_call(
          _LIB.MXAutogradSetIsTraining(
              ctypes.c_int(train_mode), ctypes.byref(prev)
          )
      )
      return bool(prev.value)
  
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 2 for calling a global function with example usage: set_training(train_mode) and returns: bool