Updates the tf.print docstring for TF 2.0.
PiperOrigin-RevId: 264181110
diff --git a/tensorflow/python/ops/logging_ops.py b/tensorflow/python/ops/logging_ops.py
index cf70404..4ec4158 100644
--- a/tensorflow/python/ops/logging_ops.py
+++ b/tensorflow/python/ops/logging_ops.py
@@ -139,18 +139,11 @@
def print_v2(*inputs, **kwargs):
"""Print the specified inputs.
- Returns an operator that prints the specified inputs to a desired
+ A TensorFlow operator that prints the specified inputs to a desired
output stream or logging level. The inputs may be dense or sparse Tensors,
- primitive python objects, data structures that contain Tensors, and printable
- python objects. Printed tensors will recursively show the first and last
- `summarize` elements of each dimension.
-
- With eager execution enabled and/or inside a `tf.contrib.eager.defun` this
- operator will automatically execute, and users only need to call `tf.print`
- without using the return value. When constructing graphs outside of a
- `tf.contrib.eager.defun`, one must either include the returned op
- in the input to `session.run`, or use the operator as a control dependency for
- executed ops by specifying `with tf.control_dependencies([print_op])`.
+ primitive python objects, data structures that contain tensors, and printable
+ Python objects. Printed tensors will recursively show the first and last
+ elements of each dimension to summarize.
@compatibility(python2)
In python 2.7, make sure to import the following:
@@ -161,7 +154,6 @@
Single-input usage:
```python
- tf.compat.v1.enable_eager_execution()
tensor = tf.range(10)
tf.print(tensor, output_stream=sys.stderr)
```
@@ -171,7 +163,6 @@
Multi-input usage:
```python
- tf.compat.v1.enable_eager_execution()
tensor = tf.range(10)
tf.print("tensors:", tensor, {2: tensor * 2}, output_stream=sys.stdout)
```
@@ -179,12 +170,19 @@
(This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to
sys.stdout)
- Usage in a defun:
+ Changing the input separator:
+ ```python
+ tensor_a = tf.range(2)
+ tensor_b = tensor_a * 2
+ tf.print(tensor_a, tensor_b, output_stream=sys.stderr, sep=',')
+ ```
+
+ (This prints "[0 1],[0 2]" to sys.stderr)
+
+ Usage in a `tf.function`:
```python
- tf.compat.v1.enable_eager_execution()
-
- @tf.contrib.eager.defun
+ @tf.function
def f():
tensor = tf.range(10)
tf.print(tensor, output_stream=sys.stderr)
@@ -195,7 +193,16 @@
(This prints "[0 1 2 ... 7 8 9]" to sys.stderr)
- Usage when constructing graphs:
+ @compatibility(TF 1.x Graphs and Sessions)
+ In graphs manually created outside of `tf.function`, this method returns
+ the created TF operator that prints the data. To make sure the
+ operator runs, users need to pass the produced op to
+ `tf.compat.v1.Session`'s run method, or to use the op as a control
+ dependency for executed ops by specifying
+ `with tf.compat.v1.control_dependencies([print_op])`.
+ @end_compatibility
+
+ Compatibility usage in TF 1.x graphs:
```python
sess = tf.compat.v1.Session()
@@ -211,7 +218,7 @@
(This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to
sys.stdout)
- Note: In Jupyter notebooks and colabs, this operator prints to the notebook
+ Note: In Jupyter notebooks and colabs, `tf.print` prints to the notebook
cell outputs. It will not write to the notebook kernel's console logs.
Args:
@@ -236,8 +243,10 @@
name: A name for the operation (optional).
Returns:
- A print operator that prints the specified inputs in the specified output
- stream or logging level.
+ None when executing eagerly. During graph tracing this returns
+ a TF operator that prints the specified inputs in the specified output
+ stream or logging level. This operator will be automatically executed
+ except inside of `tf.compat.v1` graphs and sessions.
Raises:
ValueError: If an unsupported output stream is specified.