parameters: (grads_and_vars, gradient_multipliers)
return_statement: return multiplied_grads_and_vars
docstring: Multiply specified gradients.
  
    Args:
      grads_and_vars: A list of gradient to variable pairs (tuples).
      gradient_multipliers: A map from either `Variables` or `Variable` op names
        to the coefficient by which the associated gradient should be scaled.
  
    Returns:
      The updated list of gradient to variable pairs.
  
    Raises:
      ValueError: If `grads_and_vars` is not a list or if `gradient_multipliers`
      is empty or None or if `gradient_multipliers` is not a dictionary.
docstring_summary: Multiply specified gradients.
docstring_tokens: Multiply specified gradients .
function: def multiply_gradients(grads_and_vars, gradient_multipliers):
    """Multiply specified gradients.
  
    Args:
      grads_and_vars: A list of gradient to variable pairs (tuples).
      gradient_multipliers: A map from either `Variables` or `Variable` op names
        to the coefficient by which the associated gradient should be scaled.
  
    Returns:
      The updated list of gradient to variable pairs.
  
    Raises:
      ValueError: If `grads_and_vars` is not a list or if `gradient_multipliers`
      is empty or None or if `gradient_multipliers` is not a dictionary.
    """
    if not isinstance(grads_and_vars, list):
      raise ValueError('`grads_and_vars` must be a list.')
    if not gradient_multipliers:
      raise ValueError('`gradient_multipliers` is empty.')
    if not isinstance(gradient_multipliers, dict):
      raise ValueError('`gradient_multipliers` must be a dict.')
  
    multiplied_grads_and_vars = []
    for grad, var in grads_and_vars:
      if var in gradient_multipliers or var.op.name in gradient_multipliers:
        key = var if var in gradient_multipliers else var.op.name
        if grad is None:
          raise ValueError('Requested multiple of `None` gradient.')
  
        if isinstance(grad, ops.IndexedSlices):
          tmp = grad.values * constant_op.constant(gradient_multipliers[key],
                                                   dtype=grad.dtype)
          grad = ops.IndexedSlices(tmp, grad.indices, grad.dense_shape)
        else:
          grad *= constant_op.constant(gradient_multipliers[key],
                                       dtype=grad.dtype)
      multiplied_grads_and_vars.append((grad, var))
    return multiplied_grads_and_vars
function_tokens: def multiply_gradients ( grads_and_vars , gradient_multipliers ) : if not isinstance ( grads_and_vars , list ) : raise ValueError ( '`grads_and_vars` must be a list.' ) if not gradient_multipliers : raise ValueError ( '`gradient_multipliers` is empty.' ) if not isinstance ( gradient_multipliers , dict ) : raise ValueError ( '`gradient_multipliers` must be a dict.' ) multiplied_grads_and_vars = [ ] for grad , var in grads_and_vars : if var in gradient_multipliers or var . op . name in gradient_multipliers : key = var if var in gradient_multipliers else var . op . name if grad is None : raise ValueError ( 'Requested multiple of `None` gradient.' ) if isinstance ( grad , ops . IndexedSlices ) : tmp = grad . values * constant_op . constant ( gradient_multipliers [ key ] , dtype = grad . dtype ) grad = ops . IndexedSlices ( tmp , grad . indices , grad . dense_shape ) else : grad *= constant_op . constant ( gradient_multipliers [ key ] , dtype = grad . dtype ) multiplied_grads_and_vars . append ( ( grad , var ) ) return multiplied_grads_and_vars