Add migration block for tf.compat.v1.zeros_initializer
PiperOrigin-RevId: 388519680
Change-Id: I6d281d13eaf6a16a9a0340edcbe55221c9c39e22
diff --git a/tensorflow/python/ops/init_ops.py b/tensorflow/python/ops/init_ops.py
index dc3c1c9..00b8831 100644
--- a/tensorflow/python/ops/init_ops.py
+++ b/tensorflow/python/ops/init_ops.py
@@ -100,7 +100,72 @@
@tf_export(v1=["initializers.zeros", "zeros_initializer"])
@deprecation.deprecated_endpoints("initializers.zeros")
class Zeros(Initializer):
- """Initializer that generates tensors initialized to 0."""
+ """Initializer that generates tensors initialized to 0.
+
+ @compatibility(TF2)
+ `tf.compat.v1.zeros_initializer` is compatible with eager execution
+ and `tf.function`.
+
+ To migrate to TF2, please use `tf.zeros_initializer` instead. The `dtype`
+ argument in `tf.compat.v1.zeros_initializer.__init__()` does not exist in
+ `tf.zeros_initializer.__init__()`. However, you can specify the `dtype` in
+ `__call__()` in both cases.
+
+ #### Structural Mapping to Native TF2
+
+ Before:
+
+ ```python
+ initializer = tf.compat.v1.zeros_initializer(dtype=tf.float32)
+ variable = tf.Variable(initializer(shape=[3, 3]))
+ ```
+
+ After:
+
+ ```python
+ initializer = tf.zeros_initializer()
+ variable = tf.Variable(initializer(shape=[3, 3], dtype=tf.float32))
+ ```
+
+ #### How to Map Arguments
+
+ | TF1 Arg Name | TF2 Arg Name | Note |
+ | :------------------- | :--------------- | :------------------------- |
+ | `dtype` | `dtype` | In `__call__()` method |
+ | `partition_info` | - | (`__call__` arg in TF1) Not supported |
+
+
+ #### Before & After Usage Example
+
+ Before:
+
+ >>> initializer = tf.compat.v1.zeros_initializer(dtype=tf.float32)
+ >>> tf.Variable(initializer(shape=[3])).numpy()
+ array([0., 0., 0.], dtype=float32)
+ >>> tf.Variable(initializer(shape=[3, 3])).numpy()
+ array([[0., 0., 0.],
+ [0., 0., 0.],
+ [0., 0., 0.]], dtype=float32)
+ >>> initializer = tf.compat.v1.zeros_initializer()
+ >>> tf.Variable(initializer(shape=[3], dtype=tf.float32)).numpy()
+ array([0., 0., 0.], dtype=float32)
+ >>> tf.Variable(initializer(shape=[3, 3], dtype=tf.float32)).numpy()
+ array([[0., 0., 0.],
+ [0., 0., 0.],
+ [0., 0., 0.]], dtype=float32)
+
+ After:
+
+ >>> initializer = tf.zeros_initializer()
+ >>> tf.Variable(initializer(shape=[3], dtype=tf.float32)).numpy()
+ array([0., 0., 0.], dtype=float32)
+ >>> tf.Variable(initializer(shape=[3, 3], dtype=tf.float32)).numpy()
+ array([[0., 0., 0.],
+ [0., 0., 0.],
+ [0., 0., 0.]], dtype=float32)
+
+ @end_compatibility
+ """
@deprecated_args(None,
"Call initializer instance with the dtype argument instead "