class_docstr: Optimizer hook function for gradient clipping.
  
  This hook function scales all gradient arrays to fit to the defined L2 norm
  threshold.
  
  Args:
      threshold (float): L2 norm threshold.
  
  Attributes:
      ~optimizer_hooks.GradientClipping.threshold (float): L2
                       norm threshold of gradient norm.
      ~optimizer_hooks.GradientClipping.timing (string): Specifies
                       when this hook should be
                       called by the Optimizer/UpdateRule. Valid values are
                       'pre' (before any updates) and 'post' (after any
                       updates).
  
  .. versionadded:: 4.0.0
     The *timing* parameter.
code: def __call__(self, opt):
      sqnorm, device = _sum_sqnorm_grads(list(opt.target.params(False)))
      if device is None:
          # Assign a dummy device for using_device.
          device = backend.CpuDevice()
  
      with chainer.using_device(device):
          norm = device.xp.sqrt(sqnorm)
          # TODO(niboshi): Could be inf if norm == 0
          rate = self.threshold / norm
          # In NumPy backend, `rate` is already available on CPU and thus
          # can be compared against 1 without extra overhead.
          # Otherwise `clip` is used to avoid synchronization.
          if device.xp is numpy:
              if rate >= 1:
                  return
          else:
              rate = rate.clip(None, 1)
  
      for param in opt.target.params(False):
          grad = param.grad
          with chainer.using_device(param.device):
              grad *= rate
  
file_path: chainer/chainer/optimizer_hooks/gradient_clipping.py
imports: import collections
  import numpy
  import six
  import chainer
  from chainer import backend
label_desc: Use image node_id 2 for calling the GradientClipping obj's underlying member method code with example usage: obj.__call__(opt) without return types