code: def normalize_by_pnorm(x, p=2, small_constant=1e-6):
      """
      Normalize gradients for gradient (not gradient sign) attacks.
      # TODO: move this function to utils
  
      :param x: tensor containing the gradients on the input.
      :param p: (optional) order of the norm for the normalization (1 or 2).
      :param small_constant: (optional float) to avoid dividing by zero.
      :return: normalized gradients.
      """
      # loss is averaged over the batch so need to multiply the batch
      # size to find the actual gradient of each input sample
  
      assert isinstance(p, float) or isinstance(p, int)
      norm = _get_norm_batch(x, p)
      norm = torch.max(norm, torch.ones_like(norm) * small_constant)
      return batch_multiply(1.0 / norm, x)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 22 for calling a global function with example usage: normalize_by_pnorm(x, p, small_constant) and returns: batch_multiply