code: def unscale(optimizer_or_trainer):
      """Check and unscale the gradients manually. This function should only be used
      if accessing gradients is necessary, e.g. for gradient clipping.
  
      Parameters
      ----------
      optimizer_or_trainer : Optimizer or Trainer
          MXNet optimizer or Gluon Trainer used when scaling the gradients
      """
      if isinstance(optimizer_or_trainer, trainer.Trainer):
          valid_grads = [
              p._grad
              for p in optimizer_or_trainer._params
              if p._grad is not None
          ]
          for grads in valid_grads:
              # TODO(ptredak): make a bulked unscale
              for g in grads:
                  g[:] *= optimizer_or_trainer._scale
          optimizer_or_trainer._scale = 1.0
      elif isinstance(optimizer_or_trainer, opt.Optimizer):
          # TODO(ptredak): make it work with the optimizer
          raise TypeError(
              "AMP is currently only compatible with Gluon Trainer"
          )
      else:
          raise TypeError(
              "optimizer_or_trainer should be a Gluon Trainer or "
              f"an optimizer, instead is {type(optimizer_or_trainer)}"
          )
  
imports: from array import array
  import ctypes
  import inspect
  import logging
  import contextlib
  import sys
  import numpy
  from mxnet import numpy
  from ..None import symbol
  from ..device import gpu
  from ..symbol import Symbol
  from ..symbol import contrib
  from ..None import ndarray
  from ..ndarray import NDArray, dtype_np_to_mx, get_dtype_type, get_dtype_name, bfloat16
  from .None import lists
  from ..gluon import Block, HybridBlock, trainer
  from ..None import base
  from ..base import _NP_OP_PREFIX, _NP_OP_SUBMODULE_LIST, _NP_EXT_OP_PREFIX, _NP_EXT_OP_SUBMODULE_LIST, _NP_INTERNAL_OP_PREFIX, c_str_array, c_str, c_array_buf, SymbolHandle, check_call, _LIB
  from ..None import optimizer
  from .loss_scaler import LossScaler
  from ..operator import get_all_registered_operators_grouped
  from ..util import wrap_ctx_to_device_func
label_desc: Use image node_id 10 for calling a global function with example usage: unscale(optimizer_or_trainer) without return types