code: def _unscale(self, optimizer):
      if not self._enable:
          return
  
      param_grads_dict = defaultdict(list)
      dist_param_grads_dict = defaultdict(list)
      if getattr(optimizer, "_param_groups", None) and isinstance(
          optimizer._param_groups[0], dict
      ):
          for group in optimizer._param_groups:
              for param in group["params"]:
                  if not param.is_distributed:
                      if param._grad_ivar() is not None:
                          param_grads_dict[
                              param._grad_ivar().dtype
                          ].append(param._grad_ivar())
                  else:
                      if param._grad_ivar() is not None:
                          dist_param_grads_dict[
                              param._grad_ivar().dtype
                          ].append(param._grad_ivar())
      else:
          for param in optimizer._parameter_list:
              if not param.is_distributed:
                  if param._grad_ivar() is not None:
                      param_grads_dict[param._grad_ivar().dtype].append(
                          param._grad_ivar()
                      )
              else:
                  if param._grad_ivar() is not None:
                      dist_param_grads_dict[
                          param._grad_ivar().dtype
                      ].append(param._grad_ivar())
      for dtype in dist_param_grads_dict:
          for grad in dist_param_grads_dict[dtype]:
              self._found_inf = paddle.logical_not(
                  paddle.all(paddle.isfinite(grad))
              )
              if self._found_inf:
                  print(
                      "Found inf or nan in classifier, dtype is", dtype
                  )
                  return
  
      for dtype in param_grads_dict:
          param_grads = param_grads_dict[dtype]
          _C_ops.check_finite_and_unscale(
              param_grads, self._scale, param_grads, self._found_inf
          )
          if self._found_inf:
              print("Found inf or nan in backbone, dtype is", dtype)
              break
  
file_path: insightface/recognition/arcface_paddle/dynamic/utils/amp.py
imports: from collections import defaultdict
  from paddle.amp import GradScaler
  from paddle import _C_ops
  import paddle
label_desc: Use image node_id 3 for calling the LSCGradScaler obj's underlying member method code with example usage: obj._unscale(optimizer) without return types