def testOneTag(self): one_tag_string = "^^node:Two:${file}^^" interpolated_string = error_interpolation.interpolate(one_tag_string, self.graph) self.assertTrue(interpolated_string.endswith("constant_op.py"), "interpolated_string '%s' did not end with constant_op.py" % interpolated_string)
def testNodeThreeHasColocationInterpolation(self): with ops.Graph().as_default(): self._set_up_graph() message = "{{colocation_node Three_with_one}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertIn("colocate_with(One)", result)
def testNodeZeroHasNoDeviceSummaryInfo(self): with ops.Graph().as_default(): self.zero = constant_op.constant([0.0], name="zero") message = "{{colocation_node zero}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertIn("No device assignments were active", result)
def testNothingToDo(self): with ops.Graph().as_default(): constant_op.constant(1, name="One") normal_string = "This is just a normal string" interpolated_string = error_interpolation.interpolate( normal_string, ops.get_default_graph()) self.assertIn(normal_string, interpolated_string)
def testNodeFourHasColocationInterpolationForNodeThreeOnly(self): message = "^^colocation_node:Four_with_three^^" result = error_interpolation.interpolate(message, self.graph) self.assertIn("colocate_with(Three_with_one)", result) self.assertNotIn( "One", result, "Node One should not appear in Four_with_three's summary:\n%s" % result)
def testOneTag(self): one_tag_string = "^^node:Two:${file}^^" interpolated_string = error_interpolation.interpolate(one_tag_string, self.graph) self.assertTrue(interpolated_string.endswith("constant_op.py"), "interpolated_string '%s' did not end with constant_op.py" % interpolated_string)
def testNoInputs(self): two_tags_with_seps = ";;;{{node One}},,,{{node Two}};;;" interpolated_string = error_interpolation.interpolate( two_tags_with_seps, self.graph) expected_regex = ( r"^;;;.*constant_op.py:[0-9]+\) ,,,.*constant_op.py:[0-9]+\) ;;;$") self.assertRegexpMatches(interpolated_string, expected_regex)
def testBasicInputs(self): tag = ";;;{{node Three}};;;" interpolated_string = error_interpolation.interpolate(tag, self.graph) expected_regex = re.compile( r"^;;;.*op_def_library.py:[0-9]+\) ;;;.*Input.*constant_op.py:[0-9]+\)", re.DOTALL) self.assertRegexpMatches(interpolated_string, expected_regex)
def testNoInputs(self): two_tags_with_seps = ";;;{{node One}},,,{{node Two}};;;" interpolated_string = error_interpolation.interpolate( two_tags_with_seps, self.graph) expected_regex = ( r"^;;;.*constant_op.py:[0-9]+\) ,,,.*constant_op.py:[0-9]+\) ;;;$") self.assertRegexpMatches(interpolated_string, expected_regex)
def testBasicInputs(self): tag = ";;;{{node Three}};;;" interpolated_string = error_interpolation.interpolate(tag, self.graph) expected_regex = re.compile( r"^;;;.*op_def_library.py:[0-9]+\) ;;;.*Input.*constant_op.py:[0-9]+\)", re.DOTALL) self.assertRegexpMatches(interpolated_string, expected_regex)
def testTwoTagsWithSeps(self): two_tags_with_seps = ";;;^^node:Two^^,,,^^node:Three^^;;;" interpolated_string = error_interpolation.interpolate( two_tags_with_seps, self.graph) expected_regex = ( r"^;;;.*constant_op.py:[0-9]+\) ,,,.*constant_op.py:[0-9]*\) ;;;$") self.assertRegexpMatches(interpolated_string, expected_regex)
def testTwoTagsNoSeps(self): two_tags_no_seps = "{{node One}}{{node Three}}" interpolated_string = error_interpolation.interpolate( two_tags_no_seps, self.graph) self.assertRegexpMatches( interpolated_string, "constant_op.py:[0-9]+.*constant_op.py:[0-9]+")
def testColocationInterpolationForNodeLackingColocation(self): with ops.Graph().as_default(): self._set_up_graph() message = "{{colocation_node One}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertIn("No node-device colocations", result) self.assertNotIn("Two", result)
def testNodeOneHasExactlyOneInterpolatedDevice(self): with ops.Graph().as_default(): with ops.device("/cpu"): self.one = constant_op.constant([1.0], name="one") message = "{{colocation_node one}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertEqual(2, result.count("tf.device(/cpu)"))
def testNodeFiveHasColocationInterpolationForNodeOneAndTwo(self): with ops.Graph().as_default(): self._set_up_graph() message = "{{colocation_node Five_with_one_with_two}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertIn("colocate_with(One)", result) self.assertIn("colocate_with(Two)", result)
def testNodeTwoHasTwoInterpolatedDevice(self): message = "^^node:two:${devices}^^" result = error_interpolation.interpolate(message, self.graph) num_devices = result.count("tf.device") self.assertEqual(2, num_devices) self.assertIn("tf.device(/cpu)", result) self.assertIn("tf.device(/cpu:0)", result)
def testTwoTagsNoSeps(self): two_tags_no_seps = "{{node One}}{{node Three}}" interpolated_string = error_interpolation.interpolate( two_tags_no_seps, self.graph) self.assertRegex( interpolated_string, r"error_interpolation_test\.py:[0-9]+." r"*error_interpolation_test\.py:[0-9]+")
def testBasicInputs(self): tag = ";;;{{node Three}};;;" interpolated_string = error_interpolation.interpolate(tag, self.graph) expected_regex = re.compile( r"^;;;.*error_interpolation_test\.py:[0-9]+\) " r";;;.*Input.*error_interpolation_test\.py:[0-9]+\)", re.DOTALL) self.assertRegex(interpolated_string, expected_regex)
def testTwoTagsWithSeps(self): two_tags_with_seps = ";;;{{node Two}},,,{{node Three}};;;" interpolated_string = error_interpolation.interpolate( two_tags_with_seps, self.graph) expected_regex = (r"^;;;.*error_interpolation_test\.py:[0-9]+\) " r",,,.*error_interpolation_test\.py:[0-9]+\) ;;;$") self.assertRegexpMatches(interpolated_string, expected_regex)
def testNodeTwoHasTwoInterpolatedDevice(self): message = "^^node:two:${devices}^^" result = error_interpolation.interpolate(message, self.graph) num_devices = result.count("tf.device") self.assertEqual(2, num_devices) self.assertIn("tf.device(/cpu)", result) self.assertIn("tf.device(/cpu:0)", result)
def testNodeThreeHasFancyFunctionDisplayNameForInterpolatedDevice(self): message = "^^colocation_node:three^^" result = error_interpolation.interpolate(message, self.graph) num_devices = result.count("tf.device") self.assertEqual(2, num_devices) name_re = r"_fancy_device_function<.*error_interpolation_test.py, [0-9]+>" expected_re = r"with tf.device\(.*%s\)" % name_re self.assertRegexpMatches(result, expected_re)
def testNodeFourHasColocationInterpolationForNodeThreeOnly(self): message = "^^node:Four_with_three:${colocations}^^" result = error_interpolation.interpolate(message, self.graph) assert_node_in_colocation_summary(self, result, name="Three_with_one") self.assertNotIn( "One", result, "Node One should not appear in Four_with_three's summary:\n%s" % result)
def testNodeTwoHasTwoInterpolatedDevice(self): with ops.Graph().as_default(): with ops.device("/cpu"): with ops.device("/cpu:0"): self.two = constant_op.constant([2.0], name="two") message = "{{colocation_node two}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertEqual(2, result.count("tf.device(/cpu)")) self.assertEqual(2, result.count("tf.device(/cpu:0)"))
def testNewLine(self): with ops.Graph().as_default(): constant_op.constant(1, name="One") constant_op.constant(2, name="Two") newline = "\n\n{{node One}}" interpolated_string = error_interpolation.interpolate( newline, ops.get_default_graph()) self.assertRegex(interpolated_string, r"error_interpolation_test\.py:[0-9]+.*")
def testNewLine(self): defined_at = r"\(defined at .*error_interpolation_test\.py:[0-9]+\)" with ops.Graph().as_default(): constant_op.constant(1, name="One") constant_op.constant(2, name="Two") newline = "\n\n;;;{{node One}};;;" interpolated_string = error_interpolation.interpolate( newline, ops.get_default_graph()) expected_regex = re.compile(r".*;;;.*" + defined_at + r".*;;;", re.DOTALL) self.assertRegex(interpolated_string, expected_regex)
def testNodeFourHasColocationInterpolationForNodeThreeOnly(self): with ops.Graph().as_default(): self._set_up_graph() message = "{{colocation_node Four_with_three}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) self.assertIn("colocate_with(Three_with_one)", result) self.assertNotIn( "One", result, "Node One should not appear in Four_with_three's summary:\n%s" % result)
def testNoInputs(self): with ops.Graph().as_default(): one = constant_op.constant(1, name="One") two = constant_op.constant(2, name="Two") _ = math_ops.add(one, two, name="Three") two_tags_with_seps = ";;;{{node One}},,,{{node Two}};;;" interpolated_string = error_interpolation.interpolate( two_tags_with_seps, ops.get_default_graph()) expected_regex = (r"^;;;.*error_interpolation_test\.py:[0-9]+\) " r",,,.*error_interpolation_test\.py:[0-9]+\) ;;;$") self.assertRegex(interpolated_string, expected_regex)
def testTwoTagsNoSeps(self): with ops.Graph().as_default(): constant_op.constant(1, name="One") constant_op.constant(2, name="Two") constant_op.constant(3, name="Three") two_tags_no_seps = "{{node One}}{{node Three}}" interpolated_string = error_interpolation.interpolate( two_tags_no_seps, ops.get_default_graph()) self.assertRegex( interpolated_string, r"error_interpolation_test\.py:[0-9]+." r"*error_interpolation_test\.py:[0-9]+")
def testNodeThreeHasFancyFunctionDisplayNameForInterpolatedDevice(self): with ops.Graph().as_default(): with ops.device(self._fancy_device_function): self.three = constant_op.constant(3.0, name="three") message = "{{colocation_node three}}" result = error_interpolation.interpolate(message, ops.get_default_graph()) num_devices = result.count("tf.device") self.assertEqual(2, num_devices) name_re = r"_fancy_device_function<.*error_interpolation_test.py, [0-9]+>" expected_re = r"with tf.device\(.*%s\)" % name_re self.assertRegex(result, expected_re)
def testTwoTagsNoSeps(self): defined_at = r"\(defined at .*error_interpolation_test\.py:[0-9]+\)" with ops.Graph().as_default(): constant_op.constant(1, name="One") constant_op.constant(2, name="Two") constant_op.constant(3, name="Three") two_tags_no_seps = "{{node One}}{{node Three}}" interpolated_string = error_interpolation.interpolate( two_tags_no_seps, ops.get_default_graph()) # Fragments the expression to avoid matching the pattern itself. expected_regex = re.compile(defined_at + r".*" + defined_at, re.DOTALL) self.assertRegex(interpolated_string, expected_regex)
def testBasicInputs(self): with ops.Graph().as_default(): one = constant_op.constant(1, name="One") two = constant_op.constant(2, name="Two") _ = math_ops.add(one, two, name="Three") tag = ";;;{{node Three}};;;" interpolated_string = error_interpolation.interpolate( tag, ops.get_default_graph()) expected_regex = re.compile( r"^;;;.*error_interpolation_test\.py:[0-9]+\) " r";;;.*Input.*error_interpolation_test\.py:[0-9]+\)", re.DOTALL) self.assertRegex(interpolated_string, expected_regex)
def testOperatorInputs(self): defined_at = r"\(defined at .*error_interpolation_test\.py:[0-9]+\)" with ops.Graph().as_default(): one = constant_op.constant(1, name="One") two = constant_op.constant(2, name="Two") _ = math_ops.add(one, two, name="Three") tag = ";;;{{node Three}};;;" interpolated_string = error_interpolation.interpolate( tag, ops.get_default_graph()) # Fragments the expression to avoid matching the pattern itself. expected_regex = re.compile( r"In\[0\] One " + defined_at + r".*" r"In\[1\] Two " + defined_at + r".*", re.DOTALL) self.assertRegex(interpolated_string, expected_regex)
def testTwoTagsWithSeps(self): defined_at = r"defined at.*error_interpolation_test\.py" with ops.Graph().as_default(): constant_op.constant(1, name="One") constant_op.constant(2, name="Two") constant_op.constant(3, name="Three") two_tags_with_seps = ";;;{{node Two}},,,{{node Three}};;;" interpolated_string = error_interpolation.interpolate( two_tags_with_seps, ops.get_default_graph()) # Fragments the expression to avoid matching the pattern itself. expected_regex = re.compile( rf"node 'Two'.*{defined_at}.*node 'Three'.*{defined_at}", re.DOTALL) self.assertRegex(interpolated_string, expected_regex)
def testOneTagWithAFakeFunctionTag(self): defined_at = r"defined at.*error_interpolation_test\.py" with ops.Graph().as_default(): constant_op.constant(1, name="One") constant_op.constant(2, name="Two") one_tag_with_a_fake_function_tag = "{{function_node fake}}{{node One}}" interpolated_string = error_interpolation.interpolate( one_tag_with_a_fake_function_tag, ops.get_default_graph()) # Fragments the expression to avoid matching the pattern itself. expected_regex = re.compile(rf"node 'One'.*{defined_at}", re.DOTALL) self.assertRegex(interpolated_string, expected_regex) self.assertNotIn("function_node", interpolated_string) self.assertNotIn("node 'Two'", interpolated_string)
def testOneTag(self): one_tag_string = "^^node:Foo:${file}^^" interpolated_string = error_interpolation.interpolate(one_tag_string) self.assertEqual(interpolated_string, "${file}")
def testTwoTagsWithSeps(self): two_tags_with_seps = "123^^node:Foo:${file}^^456^^node:Bar:${line}^^789" interpolated_string = error_interpolation.interpolate(two_tags_with_seps) self.assertEqual(interpolated_string, "123${file}456${line}789")
def testNodeFiveHasColocationInterpolationForNodeOneAndTwo(self): message = "^^colocation_node:Five_with_one_with_two^^" result = error_interpolation.interpolate(message, self.graph) self.assertIn("colocate_with(One)", result) self.assertIn("colocate_with(Two)", result)
def testColocationInterpolationForNodeLackingColocation(self): message = "^^colocation_node:One^^" result = error_interpolation.interpolate(message, self.graph) self.assertIn("No node-device colocations", result) self.assertNotIn("Two", result)
def testNodeThreeHasColocationInterpolation(self): message = "^^colocation_node:Three_with_one^^" result = error_interpolation.interpolate(message, self.graph) self.assertIn("colocate_with(One)", result)
def testTwoTagsWithSeps(self): two_tags_with_seps = ";;;^^node:Two:${file}^^,,,^^node:Three:${line}^^;;;" interpolated_string = error_interpolation.interpolate(two_tags_with_seps, self.graph) expected_regex = "^;;;.*constant_op.py,,,[0-9]*;;;$" self.assertRegexpMatches(interpolated_string, expected_regex)
def testNodeTwoHasTwoInterpolatedDevice(self): message = "^^colocation_node:two^^" result = error_interpolation.interpolate(message, self.graph) self.assertEqual(2, result.count("tf.device(/cpu)")) self.assertEqual(2, result.count("tf.device(/cpu:0)"))
def testNodeOneHasExactlyOneInterpolatedDevice(self): message = "^^node:one:${devices}^^" result = error_interpolation.interpolate(message, self.graph) num_devices = result.count("tf.device") self.assertEqual(1, num_devices) self.assertIn("tf.device(/cpu)", result)
def testNodeZeroHasNoDeviceSummaryInfo(self): message = "^^colocation_node:zero^^" result = error_interpolation.interpolate(message, self.graph) self.assertIn("No device assignments were active", result)
def testNodeOneHasExactlyOneInterpolatedDevice(self): message = "^^colocation_node:one^^" result = error_interpolation.interpolate(message, self.graph) self.assertEqual(2, result.count("tf.device(/cpu)"))
def testTwoTagsNoSeps(self): two_tags_no_seps = "^^node:Foo:${file}^^^^node:Bar:${line}^^" interpolated_string = error_interpolation.interpolate(two_tags_no_seps) self.assertEqual(interpolated_string, "${file}${line}")
def testTwoTagsNoSeps(self): two_tags_no_seps = "^^node:One^^^^node:Three^^" interpolated_string = error_interpolation.interpolate( two_tags_no_seps, self.graph) self.assertRegexpMatches(interpolated_string, "constant_op.py:[0-9]+.*constant_op.py:[0-9]+")
def testOneTagWithAFakeNameResultsInPlaceholders(self): one_tag_string = "^^node:MinusOne^^" interpolated_string = error_interpolation.interpolate( one_tag_string, self.graph) self.assertEqual(one_tag_string, interpolated_string)
def testNothingToDo(self): normal_string = "This is just a normal string" interpolated_string = error_interpolation.interpolate( normal_string, self.graph) self.assertEqual(interpolated_string, normal_string)
def testNewLine(self): newline = "\n\n{{node One}}" interpolated_string = error_interpolation.interpolate(newline, self.graph) self.assertRegexpMatches(interpolated_string, "constant_op.py:[0-9]+.*")