parameters: (target_dtype='float16', target_precision_ops=None,
           conditional_fp32_ops=None, fp32_ops=None, layout_optimization=False)
docstring: Initialize AMP (automatic mixed precision).
  
      This needs to be done before model creation.
  
      Parameters
      ----------
      target_dtype : {'float16', 'bfloat16'}
          Target low precision type for AMP. Currently only float16 and bfloat16 are supported.
      target_precision_ops : list of string
          Override the list of functions casted to target_dtype. Entries in this list
          are names of the functions casted to target_dtype.
      conditional_fp32_ops : list of (string, string, list of string)
          Override the list of functions conditionally casted to FP32. The format
          of the list is (name of the function, name of the parameter, list of
          values of the parameter that make the function be casted to FP32).
      fp32_ops : list of string
          Override the list of functions casted to FP32. Entries in this list
          are names of the functions casted to FP32.
docstring_summary: Initialize AMP (automatic mixed precision).
docstring_tokens: Initialize AMP ( automatic mixed precision ) .
function: def init(target_dtype='float16', target_precision_ops=None,
           conditional_fp32_ops=None, fp32_ops=None, layout_optimization=False):
      """Initialize AMP (automatic mixed precision).
  
      This needs to be done before model creation.
  
      Parameters
      ----------
      target_dtype : {'float16', 'bfloat16'}
          Target low precision type for AMP. Currently only float16 and bfloat16 are supported.
      target_precision_ops : list of string
          Override the list of functions casted to target_dtype. Entries in this list
          are names of the functions casted to target_dtype.
      conditional_fp32_ops : list of (string, string, list of string)
          Override the list of functions conditionally casted to FP32. The format
          of the list is (name of the function, name of the parameter, list of
          values of the parameter that make the function be casted to FP32).
      fp32_ops : list of string
          Override the list of functions casted to FP32. Entries in this list
          are names of the functions casted to FP32.
      """
      global _amp_initialized
      global _loss_scaler
      if not _amp_initialized:
          assert target_dtype in ['float16', np.float16, 'bfloat16', bfloat16], \
                 "AMP currently supports only float16 or bfloat16 as a target_dtype"
          _amp_initialized = True
          log_msg = "Using AMP"
          if layout_optimization:
              log_msg += "\n - layout optimization: enabled"
              check_call(_LIB.MXSetOptimizeLayout(ctypes.c_bool(True)))
          logging.info(log_msg)
          if target_dtype == "bfloat16":
              target_dtype = bfloat16
          else:
              target_dtype = np.dtype(target_dtype)
  
          warn_if_model_exists()
  
          ops = get_all_registered_operators_grouped()
          get_aliases_nd = lambda l: [a for op in l for a in ops[op] if not base._is_np_op(a)]
          get_aliases_np = lambda l: [a for op in l for a in ops[op] if base._is_np_op(a)]
          get_aliases_np_pub = lambda l: [a for op in l for a in ops[op]
                                          if a.startswith(('_np_', '_npx_'))]
          get_cond_aliases_nd = lambda l: [(a, *rest) for op, *rest in l for a in ops[op]
                                           if not base._is_np_op(a)]
          get_cond_aliases_np = lambda l: [(a, *rest) for op, *rest in l for a in ops[op]
                                           if base._is_np_op(a)]
          get_cond_aliases_np_pub = lambda l: [(a, *rest) for op, *rest in l for a in ops[op]
                                               if a.startswith(('_np_', '_npx_'))]
          sy_submodules = {p:getattr(symbol, p[1:-1]) for p in base._OP_NAME_PREFIX_LIST}
          get_sy_fun = lambda fun, mod: _get_nd_fun_to_wrap(fun, mod, sy_submodules)
          nd_submodules = {p:getattr(ndarray, p[1:-1]) for p in base._OP_NAME_PREFIX_LIST}
          get_nd_fun = lambda fun, mod: _get_nd_fun_to_wrap(fun, mod, nd_submodules)
          get_np_sy_fun = lambda fun, mod: _get_np_fun_to_wrap(fun, "mxnet.symbol")
          get_np_nd_fun = lambda fun, mod: _get_np_fun_to_wrap(fun, "mxnet.ndarray")
          get_np_fun = lambda fun, mode: _get_np_fun_to_wrap(fun, "mxnet")
          todo = [
              (symbol, False, get_aliases_nd, get_cond_aliases_nd, get_sy_fun),
              (ndarray, False, get_aliases_nd, get_cond_aliases_nd, get_nd_fun),
              (symbol.numpy, True, get_aliases_np, get_cond_aliases_np, get_np_sy_fun),
              (ndarray.numpy, True, get_aliases_np, get_cond_aliases_np, get_np_nd_fun),
              (numpy, True, get_aliases_np_pub, get_cond_aliases_np_pub, get_np_fun),
          ]
          _loss_scaler = LossScaler()
          for module, is_numpy, get_aliases, get_cond_aliases, get_fun in todo:
              _wrap_module_functions(module, is_numpy, target_dtype, get_aliases, get_cond_aliases,
                                     get_fun, target_precision_ops, conditional_fp32_ops, fp32_ops)
              _wrap_loss_output_functions(module, _loss_scaler, target_dtype)
function_tokens: def init ( target_dtype = 'float16' , target_precision_ops = None , conditional_fp32_ops = None , fp32_ops = None , layout_optimization = False ) : global _amp_initialized global _loss_scaler if not _amp_initialized : assert target_dtype in [ 'float16' , np . float16 , 'bfloat16' , bfloat16 ] , "AMP currently supports only float16 or bfloat16 as a target_dtype" _amp_initialized = True log_msg = "Using AMP" if layout_optimization : log_msg += "\n - layout optimization: enabled" check_call ( _LIB . MXSetOptimizeLayout ( ctypes . c_bool ( True ) ) ) logging . info ( log_msg ) if target_dtype == "bfloat16" : target_dtype = bfloat16 else : target_dtype = np . dtype ( target_dtype ) warn_if_model_exists ( ) ops = get_all_registered_operators_grouped ( ) get_aliases_nd = lambda l : [ a for op in l for a in ops [ op ] if not base . _is_np_op ( a ) ] get_aliases_np = lambda l : [ a for op in l for a in ops [ op ] if base . _is_np_op ( a ) ] get_aliases_np_pub = lambda l : [ a for op in l for a in ops [ op ] if a . startswith ( ( '_np_' , '_npx_' ) ) ] get_cond_aliases_nd = lambda l : [ ( a , * rest ) for op , * rest in l for a in ops [ op ] if not base . _is_np_op ( a ) ] get_cond_aliases_np = lambda l : [ ( a , * rest ) for op , * rest in l for a in ops [ op ] if base . _is_np_op ( a ) ] get_cond_aliases_np_pub = lambda l : [ ( a , * rest ) for op , * rest in l for a in ops [ op ] if a . startswith ( ( '_np_' , '_npx_' ) ) ] sy_submodules = { p : getattr ( symbol , p [ 1 : - 1 ] ) for p in base . _OP_NAME_PREFIX_LIST } get_sy_fun = lambda fun , mod : _get_nd_fun_to_wrap ( fun , mod , sy_submodules ) nd_submodules = { p : getattr ( ndarray , p [ 1 : - 1 ] ) for p in base . _OP_NAME_PREFIX_LIST } get_nd_fun = lambda fun , mod : _get_nd_fun_to_wrap ( fun , mod , nd_submodules ) get_np_sy_fun = lambda fun , mod : _get_np_fun_to_wrap ( fun , "mxnet.symbol" ) get_np_nd_fun = lambda fun , mod : _get_np_fun_to_wrap ( fun , "mxnet.ndarray" ) get_np_fun = lambda fun , mode : _get_np_fun_to_wrap ( fun , "mxnet" ) todo = [ ( symbol , False , get_aliases_nd , get_cond_aliases_nd , get_sy_fun ) , ( ndarray , False , get_aliases_nd , get_cond_aliases_nd , get_nd_fun ) , ( symbol . numpy , True , get_aliases_np , get_cond_aliases_np , get_np_sy_fun ) , ( ndarray . numpy , True , get_aliases_np , get_cond_aliases_np , get_np_nd_fun ) , ( numpy , True , get_aliases_np_pub , get_cond_aliases_np_pub , get_np_fun ) , ] _loss_scaler = LossScaler ( ) for module , is_numpy , get_aliases , get_cond_aliases , get_fun in todo : _wrap_module_functions ( module , is_numpy , target_dtype , get_aliases , get_cond_aliases , get_fun , target_precision_ops , conditional_fp32_ops , fp32_ops ) _wrap_loss_output_functions ( module , _loss_scaler , target_dtype )