code: def compute_clip_weights(
      l2_norm_clip: float, gradient_norms: tf.Tensor
  ):
      """Computes the per-example loss/clip weights for clipping.
  
      When the sum of the per-example losses is replaced a weighted sum, where
      the weights are generated by this method, then the gradients of each
      term in the weighted sum are clipped by the given clip value.
  
      Args:
        l2_norm_clip: A `float` indicating the norm to which per-example gradients
          will be clipped. That is, all gradients of the per-example loss functions
          will have norm at most `l2_norm_clip`.
        gradient_norms: A 1D `tf.Tensor` whose i-th entry is the norm of the
          gradient of the loss function for the i-th input.
  
      Returns:
        A 1D `tf.Tensor` representing whose i-th entry `C[i]` is either `1.0` if the
        norm of the gradient of i-th per-example loss `G[i]` is less than
        `l2_norm_clip` or a number less than `1.0` so that
        `|G[i]| * C[i] == l2_norm_clip` otherwise.
      """
      if l2_norm_clip is None:
          return None
      return l2_norm_clip / tf.math.maximum(
          l2_norm_clip, gradient_norms
      )
  
file_path: privacy/tensorflow_privacy/privacy/fast_gradient_clipping/clip_grads.py
imports: from collections.abc import Sequence
  from typing import Optional
  import tensorflow
  from tensorflow_privacy.privacy.fast_gradient_clipping import common_manip_utils
  from tensorflow_privacy.privacy.fast_gradient_clipping import gradient_clipping_utils
  from tensorflow_privacy.privacy.fast_gradient_clipping import layer_registry
  from tensorflow_privacy.privacy.fast_gradient_clipping import type_aliases
label_desc: Use image node_id 3 for calling a global function with example usage: compute_clip_weights(l2_norm_clip, gradient_norms) and returns: unknown, None