def l2_distance(t1, t2, epsilon=1e-12, name=None):
  """l2 distance between t1 and t2 and caps the gradient of the Square Root.

  Args:
    t1: A tensor.
    t2: A tensor that is the same size as t1.
    epsilon: A lower bound for distance, useful to avoid sqrt of very small
      values that can blow up gradients.
    name: Optional name for this op.
  Returns:
    The l2 distance between t1 and t2.
  """
  with tf.name_scope(name, 'l2_distance', [t1, t2]) as scope:
    t1 = tf.convert_to_tensor(t1, name='t1')
    t2 = tf.convert_to_tensor(t2, name='t2')
    return tf.sqrt(tf.maximum(l2_distance_sq(t1, t2, scope), epsilon))