parameters: (gradients_to_variables, max_norm)
return_statement: return clipped_grads_and_vars
docstring: Clips the gradients by the given value.
  
    Args:
      gradients_to_variables: A list of gradient to variable pairs (tuples).
      max_norm: the maximum norm value.
  
    Returns:
      A list of clipped gradient to variable pairs.
docstring_summary: Clips the gradients by the given value.
docstring_tokens: Clips the gradients by the given value .
function: def clip_gradient_norms(gradients_to_variables, max_norm):
    """Clips the gradients by the given value.
  
    Args:
      gradients_to_variables: A list of gradient to variable pairs (tuples).
      max_norm: the maximum norm value.
  
    Returns:
      A list of clipped gradient to variable pairs.
    """
    clipped_grads_and_vars = []
    for grad, var in gradients_to_variables:
      if grad is not None:
        if isinstance(grad, ops.IndexedSlices):
          tmp = clip_ops.clip_by_norm(grad.values, max_norm)
          grad = ops.IndexedSlices(tmp, grad.indices, grad.dense_shape)
        else:
          grad = clip_ops.clip_by_norm(grad, max_norm)
      clipped_grads_and_vars.append((grad, var))
    return clipped_grads_and_vars
function_tokens: def clip_gradient_norms ( gradients_to_variables , max_norm ) : clipped_grads_and_vars = [ ] for grad , var in gradients_to_variables : if grad is not None : if isinstance ( grad , ops . IndexedSlices ) : tmp = clip_ops . clip_by_norm ( grad . values , max_norm ) grad = ops . IndexedSlices ( tmp , grad . indices , grad . dense_shape ) else : grad = clip_ops . clip_by_norm ( grad , max_norm ) clipped_grads_and_vars . append ( ( grad , var ) ) return clipped_grads_and_vars