aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/ops/clip_ops.py
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/python/ops/clip_ops.py')
-rw-r--r--tensorflow/python/ops/clip_ops.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/tensorflow/python/ops/clip_ops.py b/tensorflow/python/ops/clip_ops.py
index e2580e8a2e..78b395a6c1 100644
--- a/tensorflow/python/ops/clip_ops.py
+++ b/tensorflow/python/ops/clip_ops.py
@@ -29,6 +29,7 @@ from tensorflow.python.ops import array_ops
from tensorflow.python.ops import gen_array_ops
from tensorflow.python.ops import gen_nn_ops
from tensorflow.python.ops import math_ops
+from tensorflow.python.ops import numerics
from tensorflow.python.util.tf_export import tf_export
@@ -57,7 +58,7 @@ def clip_by_value(t, clip_value_min, clip_value_max,
A clipped `Tensor`.
Raises:
- ValueError: if the clip tensors would trigger array broadcasting
+ ValueError: If the clip tensors would trigger array broadcasting
that would make the returned tensor larger than the input.
"""
with ops.name_scope(name, "clip_by_value",
@@ -246,6 +247,7 @@ def clip_by_global_norm(t_list, clip_norm, use_norm=None, name=None):
Raises:
TypeError: If `t_list` is not a sequence.
+ InvalidArgumentError: If global norm is not finite.
"""
if (not isinstance(t_list, collections.Sequence)
or isinstance(t_list, six.string_types)):
@@ -253,6 +255,8 @@ def clip_by_global_norm(t_list, clip_norm, use_norm=None, name=None):
t_list = list(t_list)
if use_norm is None:
use_norm = global_norm(t_list, name)
+ use_norm = numerics.verify_tensor_all_finite(use_norm,
+ "Found Inf or NaN global norm.")
with ops.name_scope(name, "clip_by_global_norm",
t_list + [clip_norm]) as name: