TF error message fixit: keras/optimizer_v2/utils.
@@ -69,8 +69,9 @@ def filter_empty_gradients(grads_and_vars):
filtered = tuple(filtered)
if not filtered:
- raise ValueError("No gradients provided for any variable: %s." %
- ([v.name for _, v in grads_and_vars],))
+ variable = ([v.name for _, v in grads_and_vars],)
+ raise ValueError(f"No gradients provided for any variable: {variable}. "
+ f"Provided `grads_and_vars` is {grads_and_vars}.")
if vars_with_empty_grads:
logging.warning(
("Gradients do not exist for variables %s when minimizing the loss. "
@@ -91,7 +92,8 @@ def make_gradient_clipnorm_fn(clipnorm):
(tf.distribute.experimental.CentralStorageStrategy,
tf.compat.v1.distribute.experimental.CentralStorageStrategy)):
raise ValueError(
- "`clipnorm` is not supported with `CenteralStorageStrategy`")
+ "`clipnorm` is not supported with `CenteralStorageStrategy`. "
+ f"The strategy used is {tf.distribute.get_strategy()}.")
clipped_grads_and_vars = [
(tf.clip_by_norm(g, clipnorm), v) for g, v in grads_and_vars
@@ -112,7 +114,8 @@ def make_global_gradient_clipnorm_fn(clipnorm):
(tf.distribute.experimental.CentralStorageStrategy,
tf.compat.v1.distribute.experimental.CentralStorageStrategy)):
raise ValueError(
- "`global_clipnorm` is not supported with `CenteralStorageStrategy`")
+ "`global_clipnorm` is not supported with `CenteralStorageStrategy`. "
+ f"The strategy used is {tf.distribute.get_strategy()}.")
grads, variables = zip(*grads_and_vars)
clipped_grads, _ = tf.clip_by_global_norm(grads, clipnorm)
@@ -133,7 +136,8 @@ def make_gradient_clipvalue_fn(clipvalue):
(tf.distribute.experimental.CentralStorageStrategy,
tf.compat.v1.distribute.experimental.CentralStorageStrategy)):
raise ValueError(
- "`clipvalue` is not supported with `CenteralStorageStrategy`")
+ "`clipvalue` is not supported with `CenteralStorageStrategy`. "
+ f"The strategy used is {tf.distribute.get_strategy()}.")
clipped_grads_and_vars = [(tf.clip_by_value(g, -clipvalue,
clipvalue), v)
