Skip to content

Commit 8bd4927

Browse files
nfelttensorflower-gardener
authored andcommitted
Convert summary_ops_test.py to use create_file_writer_v2() exclusively
The tests in this file should cover the standard TF 2.0 behavior, which means using `create_file_writer_v2()`, rather than `create_file_writer()` which is only invoked for the legacy `tf.contrib.summary` API. We'll still have some coverage for contrib in the tests under `tensorflow/contrib/summary/`. PiperOrigin-RevId: 365928408 Change-Id: I3314e4aca9db224928173ae27da93bd30ee5ca84
1 parent 6dbf898 commit 8bd4927

1 file changed

Lines changed: 23 additions & 24 deletions

File tree

‎tensorflow/python/kernel_tests/summary_ops_test.py‎

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def testWrite_stringTensor(self):
150150
def testWrite_gpuDeviceContext(self):
151151
logdir = self.get_temp_dir()
152152
with context.eager_mode():
153-
with summary_ops.create_file_writer(logdir).as_default():
153+
with summary_ops.create_file_writer_v2(logdir).as_default():
154154
with ops.device('/GPU:0'):
155155
value = constant_op.constant(42.0)
156156
step = constant_op.constant(12, dtype=dtypes.int64)
@@ -172,26 +172,25 @@ def testWrite_noStep_okayIfAlsoNoDefaultWriter(self):
172172
# Use assertAllEqual instead of assertFalse since it works in a defun.
173173
self.assertAllEqual(False, summary_ops.write('tag', 42))
174174

175-
@test_util.also_run_as_tf_function
176175
def testWrite_noStep(self):
177176
logdir = self.get_temp_dir()
178-
with summary_ops.create_file_writer(logdir).as_default():
179-
with self.assertRaisesRegex(ValueError, 'No step set'):
180-
summary_ops.write('tag', 42)
177+
with context.eager_mode():
178+
with summary_ops.create_file_writer_v2(logdir).as_default():
179+
with self.assertRaisesRegex(ValueError, 'No step set'):
180+
summary_ops.write('tag', 42)
181181

182-
@test_util.also_run_as_tf_function
183182
def testWrite_noStep_okayIfNotRecordingSummaries(self):
184183
logdir = self.get_temp_dir()
185-
with summary_ops.create_file_writer(logdir).as_default():
186-
with summary_ops.record_if(False):
187-
# Use assertAllEqual instead of assertFalse since it works in a defun.
188-
self.assertAllEqual(False, summary_ops.write('tag', 42))
184+
with context.eager_mode():
185+
with summary_ops.create_file_writer_v2(logdir).as_default():
186+
with summary_ops.record_if(False):
187+
self.assertFalse(summary_ops.write('tag', 42))
189188

190189
def testWrite_usingDefaultStep(self):
191190
logdir = self.get_temp_dir()
192191
try:
193192
with context.eager_mode():
194-
with summary_ops.create_file_writer(logdir).as_default():
193+
with summary_ops.create_file_writer_v2(logdir).as_default():
195194
summary_ops.set_step(1)
196195
summary_ops.write('tag', 1.0)
197196
summary_ops.set_step(2)
@@ -215,7 +214,7 @@ def testWrite_usingDefaultStepConstant_fromFunction(self):
215214
logdir = self.get_temp_dir()
216215
try:
217216
with context.eager_mode():
218-
writer = summary_ops.create_file_writer(logdir)
217+
writer = summary_ops.create_file_writer_v2(logdir)
219218
@def_function.function
220219
def f():
221220
with writer.as_default():
@@ -238,7 +237,7 @@ def testWrite_usingDefaultStepVariable_fromFunction(self):
238237
logdir = self.get_temp_dir()
239238
try:
240239
with context.eager_mode():
241-
writer = summary_ops.create_file_writer(logdir)
240+
writer = summary_ops.create_file_writer_v2(logdir)
242241
@def_function.function
243242
def f():
244243
with writer.as_default():
@@ -263,7 +262,7 @@ def testWrite_usingDefaultStepConstant_fromLegacyGraph(self):
263262
logdir = self.get_temp_dir()
264263
try:
265264
with context.graph_mode():
266-
writer = summary_ops.create_file_writer(logdir)
265+
writer = summary_ops.create_file_writer_v2(logdir)
267266
summary_ops.set_step(1)
268267
with writer.as_default():
269268
write_op = summary_ops.write('tag', 1.0)
@@ -287,7 +286,7 @@ def testWrite_usingDefaultStepVariable_fromLegacyGraph(self):
287286
logdir = self.get_temp_dir()
288287
try:
289288
with context.graph_mode():
290-
writer = summary_ops.create_file_writer(logdir)
289+
writer = summary_ops.create_file_writer_v2(logdir)
291290
mystep = variables.Variable(0, dtype=dtypes.int64)
292291
summary_ops.set_step(mystep)
293292
with writer.as_default():
@@ -316,7 +315,7 @@ def testWrite_usingDefaultStep_fromAsDefault(self):
316315
logdir = self.get_temp_dir()
317316
try:
318317
with context.eager_mode():
319-
writer = summary_ops.create_file_writer(logdir)
318+
writer = summary_ops.create_file_writer_v2(logdir)
320319
with writer.as_default(step=1):
321320
summary_ops.write('tag', 1.0)
322321
with writer.as_default():
@@ -336,7 +335,7 @@ def testWrite_usingDefaultStepVariable_fromAsDefault(self):
336335
logdir = self.get_temp_dir()
337336
try:
338337
with context.eager_mode():
339-
writer = summary_ops.create_file_writer(logdir)
338+
writer = summary_ops.create_file_writer_v2(logdir)
340339
mystep = variables.Variable(1, dtype=dtypes.int64)
341340
with writer.as_default(step=mystep):
342341
summary_ops.write('tag', 1.0)
@@ -358,7 +357,7 @@ def testWrite_usingDefaultStep_fromSetAsDefault(self):
358357
logdir = self.get_temp_dir()
359358
try:
360359
with context.eager_mode():
361-
writer = summary_ops.create_file_writer(logdir)
360+
writer = summary_ops.create_file_writer_v2(logdir)
362361
mystep = variables.Variable(1, dtype=dtypes.int64)
363362
writer.set_as_default(step=mystep)
364363
summary_ops.write('tag', 1.0)
@@ -377,7 +376,7 @@ def testWrite_usingDefaultStepVariable_fromSetAsDefault(self):
377376
logdir = self.get_temp_dir()
378377
try:
379378
with context.eager_mode():
380-
writer = summary_ops.create_file_writer(logdir)
379+
writer = summary_ops.create_file_writer_v2(logdir)
381380
writer.set_as_default(step=1)
382381
summary_ops.write('tag', 1.0)
383382
writer.set_as_default(step=2)
@@ -967,7 +966,7 @@ def tearDown(self):
967966
def exec_summary_op(self, summary_op_fn):
968967
assert context.executing_eagerly()
969968
logdir = self.get_temp_dir()
970-
writer = summary_ops.create_file_writer(logdir)
969+
writer = summary_ops.create_file_writer_v2(logdir)
971970
with writer.as_default():
972971
summary_op_fn()
973972
writer.close()
@@ -977,7 +976,7 @@ def exec_summary_op(self, summary_op_fn):
977976
def run_metadata(self, *args, **kwargs):
978977
assert context.executing_eagerly()
979978
logdir = self.get_temp_dir()
980-
writer = summary_ops.create_file_writer(logdir)
979+
writer = summary_ops.create_file_writer_v2(logdir)
981980
with writer.as_default():
982981
summary_ops.run_metadata(*args, **kwargs)
983982
writer.close()
@@ -987,7 +986,7 @@ def run_metadata(self, *args, **kwargs):
987986
def run_metadata_graphs(self, *args, **kwargs):
988987
assert context.executing_eagerly()
989988
logdir = self.get_temp_dir()
990-
writer = summary_ops.create_file_writer(logdir)
989+
writer = summary_ops.create_file_writer_v2(logdir)
991990
with writer.as_default():
992991
summary_ops.run_metadata_graphs(*args, **kwargs)
993992
writer.close()
@@ -1011,7 +1010,7 @@ def create_run_metadata(self):
10111010
def run_trace(self, f, step=1):
10121011
assert context.executing_eagerly()
10131012
logdir = self.get_temp_dir()
1014-
writer = summary_ops.create_file_writer(logdir)
1013+
writer = summary_ops.create_file_writer_v2(logdir)
10151014
summary_ops.trace_on(graph=True, profiler=False)
10161015
with writer.as_default():
10171016
f()
@@ -1235,7 +1234,7 @@ def f():
12351234

12361235
assert context.executing_eagerly()
12371236
logdir = self.get_temp_dir()
1238-
writer = summary_ops.create_file_writer(logdir)
1237+
writer = summary_ops.create_file_writer_v2(logdir)
12391238
summary_ops.trace_on(graph=True, profiler=True)
12401239
profiler_outdir = self.get_temp_dir()
12411240
with writer.as_default():

0 commit comments

Comments
 (0)