TFE: Add errors for classic tf.summary.* ops and FileWriter

PiperOrigin-RevId: 173949980
This commit is contained in:
Shanqing Cai 2017-10-30 14:30:51 -07:00 committed by TensorFlower Gardener
parent 25620825bc
commit e40eb810a6
5 changed files with 73 additions and 1 deletions

View File

@ -41,6 +41,7 @@ cuda_py_test(
"//tensorflow/python:math_ops",
"//tensorflow/python:client_testlib",
"//tensorflow/python:platform_test",
"//tensorflow/python:summary",
],
)

View File

@ -17,6 +17,8 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tempfile
from tensorflow.contrib.eager.python import tfe
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import errors
@ -27,6 +29,8 @@ from tensorflow.python.ops import math_ops
from tensorflow.python.ops import numerics
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.summary import summary
from tensorflow.python.summary.writer import writer
class TFETest(test_util.TensorFlowTestCase):
@ -108,6 +112,28 @@ class TFETest(test_util.TensorFlowTestCase):
r'add_check_numerics_ops\(\) is not compatible with eager execution'):
numerics.add_check_numerics_ops()
def testClassicSummaryOpsErrorOut(self):
x = constant_op.constant(42)
x_summary = summary.scalar('x', x)
y = constant_op.constant([1, 3, 3, 7])
y_summary = summary.histogram('hist', y)
with self.assertRaisesRegexp(
RuntimeError,
r'Merging tf\.summary\.\* ops is not compatible with eager execution'):
summary.merge([x_summary, y_summary])
with self.assertRaisesRegexp(
RuntimeError,
r'Merging tf\.summary\.\* ops is not compatible with eager execution'):
summary.merge_all()
def testClassicSummaryFileWriterErrorsOut(self):
with self.assertRaisesRegexp(
RuntimeError,
r'tf\.summary\.FileWriter is not compatible with eager execution'):
writer.FileWriter(tempfile.mkdtemp())
if __name__ == '__main__':
tfe.enable_eager_execution()

View File

@ -3792,6 +3792,7 @@ py_library(
":summary_op_util",
":summary_ops",
":util",
"//tensorflow/python/eager:context",
"//third_party/py/numpy",
"@six_archive//:six",
],

View File

@ -48,6 +48,7 @@ from tensorflow.core.util.event_pb2 import SessionLog
from tensorflow.core.util.event_pb2 import TaggedRunMetadata
# pylint: enable=unused-import
from tensorflow.python.eager import context as _context
from tensorflow.python.framework import dtypes as _dtypes
from tensorflow.python.framework import ops as _ops
from tensorflow.python.ops import gen_logging_ops as _gen_logging_ops
@ -263,8 +264,20 @@ def merge(inputs, collections=None, name=None):
Returns:
A scalar `Tensor` of type `string`. The serialized `Summary` protocol
buffer resulting from the merging.
Raises:
RuntimeError: If called with eager mode enabled.
@compatibility(eager)
Not compatible with eager execution. To write TensorBoard
summaries under eager execution, use `tf.contrib.summary` instead.
@end_compatbility
"""
# pylint: enable=line-too-long
if _context.in_eager_mode():
raise RuntimeError(
'Merging tf.summary.* ops is not compatible with eager execution. '
'Use tf.contrib.summary instead.')
name = _summary_op_util.clean_tag(name)
with _ops.name_scope(name, 'Merge', inputs):
# pylint: disable=protected-access
@ -284,7 +297,19 @@ def merge_all(key=_ops.GraphKeys.SUMMARIES):
If no summaries were collected, returns None. Otherwise returns a scalar
`Tensor` of type `string` containing the serialized `Summary` protocol
buffer resulting from the merging.
Raises:
RuntimeError: If called with eager execution enabled.
@compatibility(eager)
Not compatible with eager execution. To write TensorBoard
summaries under eager execution, use `tf.contrib.summary` instead.
@end_compatbility
"""
if _context.in_eager_mode():
raise RuntimeError(
'Merging tf.summary.* ops is not compatible with eager execution. '
'Use tf.contrib.summary instead.')
summary_ops = _ops.get_collection(key)
if not summary_ops:
return None
@ -306,6 +331,11 @@ def get_summary_description(node_def):
Raises:
ValueError: if the node is not a summary op.
@compatibility(eager)
Not compatible with eager execution. To write TensorBoard
summaries under eager execution, use `tf.contrib.summary` instead.
@end_compatbility
"""
if node_def.op != 'TensorSummary':
@ -317,7 +347,7 @@ def get_summary_description(node_def):
_allowed_symbols = [
'Summary', 'SummaryDescription', 'Event', 'TaggedRunMetadata', 'SessionLog'
'Summary', 'SummaryDescription', 'Event', 'TaggedRunMetadata', 'SessionLog',
]
remove_undocumented(__name__, _allowed_symbols)

View File

@ -25,6 +25,7 @@ from tensorflow.core.framework import graph_pb2
from tensorflow.core.framework import summary_pb2
from tensorflow.core.protobuf import meta_graph_pb2
from tensorflow.core.util import event_pb2
from tensorflow.python.eager import context
from tensorflow.python.framework import meta_graph
from tensorflow.python.framework import ops
from tensorflow.python.platform import gfile
@ -331,7 +332,20 @@ class FileWriter(SummaryToEventTransformer):
graph_def: DEPRECATED: Use the `graph` argument instead.
filename_suffix: A string. Every event file's name is suffixed with
`suffix`.
Raises:
RuntimeError: If called with eager execution enabled.
@compatibility(eager)
`FileWriter` is not compatible with eager execution. To write TensorBoard
summaries under eager execution, use `tf.contrib.summary` instead.
@end_compatbility
"""
if context.in_eager_mode():
raise RuntimeError(
"tf.summary.FileWriter is not compatible with eager execution. "
"Use tf.contrib.summary instead.")
event_writer = EventFileWriter(logdir, max_queue, flush_secs,
filename_suffix)
super(FileWriter, self).__init__(event_writer, graph, graph_def)