diff --git a/tensorflow/python/keras/mixed_precision/experimental/policy.py b/tensorflow/python/keras/mixed_precision/experimental/policy.py index c4b414d7bf5..33f6562f796 100644 --- a/tensorflow/python/keras/mixed_precision/experimental/policy.py +++ b/tensorflow/python/keras/mixed_precision/experimental/policy.py @@ -32,11 +32,6 @@ from tensorflow.python.training.experimental import mixed_precision_global_state from tensorflow.python.util.tf_export import keras_export -# Default value of certain arguments, indicating the default behavior for -# that argument should be used. -USE_DEFAULT = 'USE_DEFAULT' - - @keras_export('keras.mixed_precision.experimental.Policy', v1=[]) class Policy(object): """A dtype policy for a Keras layer. @@ -293,7 +288,7 @@ class Policy(object): layer would only work if the inputs were float32. """ - def __init__(self, name, loss_scale=USE_DEFAULT): + def __init__(self, name, loss_scale='auto'): """Constructs the policy. The `name` argument determines the compute and variable dtype, the default @@ -310,9 +305,10 @@ class Policy(object): a dynamic loss scale is used. These policies are used for mixed precision training. loss_scale: A `tf.mixed_precision.experimental.LossScale`, an int (which - uses a `FixedLossScale`), or the string "dynamic" (which uses a - `DynamicLossScale`). Defaults to using no loss scaling unless `name` is - "mixed_float16", in which case this defaults to "dynamic". Only + uses a `FixedLossScale`), the string "dynamic" (which uses a + `DynamicLossScale`), or None (which uses no loss scale). Defaults to + `"auto"`. In the `"auto"` case: 1) if `name` is `"mixed_float16"`, then + use `loss_scale="dynamic"`. 2) otherwise, do not use a loss scale. Only `tf.keras.Model`s, not layers, use the loss scale, and it is only used during `Model.fit`, `Model.train_on_batch`, and other similar methods. """ @@ -324,7 +320,7 @@ class Policy(object): self._name = name self._compute_dtype, self._variable_dtype = self._parse_name(name) - if loss_scale == USE_DEFAULT: + if loss_scale == 'auto': loss_scale = 'dynamic' if name == 'mixed_float16' else None self._using_default_loss_scale = True else: diff --git a/tensorflow/tools/api/golden/v2/tensorflow.keras.mixed_precision.experimental.-policy.pbtxt b/tensorflow/tools/api/golden/v2/tensorflow.keras.mixed_precision.experimental.-policy.pbtxt index c37ee31da6b..e3435a32bef 100644 --- a/tensorflow/tools/api/golden/v2/tensorflow.keras.mixed_precision.experimental.-policy.pbtxt +++ b/tensorflow/tools/api/golden/v2/tensorflow.keras.mixed_precision.experimental.-policy.pbtxt @@ -24,7 +24,7 @@ tf_class { } member_method { name: "__init__" - argspec: "args=[\'self\', \'name\', \'loss_scale\'], varargs=None, keywords=None, defaults=[\'USE_DEFAULT\'], " + argspec: "args=[\'self\', \'name\', \'loss_scale\'], varargs=None, keywords=None, defaults=[\'auto\'], " } member_method { name: "from_config"