You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_sync_trans_false_watchpoints.py 6.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """
  16. Watchpoints test script for offline debugger APIs.
  17. """
  18. import mindspore.offline_debug.dbg_services as d
  19. import pytest
  20. from dump_test_utils import compare_actual_with_expected
  21. GENERATE_GOLDEN = False
  22. test_name = "sync_trans_false_watchpoints"
  23. @pytest.mark.level0
  24. @pytest.mark.platform_arm_ascend_training
  25. @pytest.mark.platform_x86_ascend_training
  26. @pytest.mark.env_onecard
  27. @pytest.mark.skip(reason="needs updating")
  28. def test_sync_trans_false_watchpoints():
  29. if GENERATE_GOLDEN:
  30. f_write = open(test_name + ".expected", "w")
  31. else:
  32. f_write = open(test_name + ".actual", "w")
  33. debugger_backend = d.DbgServices(
  34. dump_file_path="/home/workspace/mindspore_dataset/dumps/sync_trans_false/alexnet/")
  35. _ = debugger_backend.initialize(
  36. net_name="Network Name goes here!", is_sync_mode=True)
  37. # NOTES:
  38. # -> watch_condition=6 is MIN_LT
  39. # -> watch_condition=18 is CHANGE_TOO_LARGE
  40. # test 1: watchpoint set and hit (watch_condition=6)
  41. param1 = d.Parameter(name="param", disabled=False, value=0.0)
  42. _ = debugger_backend.add_watchpoint(watchpoint_id=1, watch_condition=6,
  43. check_node_list={"Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/"
  44. "Conv2D-op168":
  45. {"device_id": [0], "root_graph_id": [0],
  46. "is_parameter": False
  47. }}, parameter_list=[param1])
  48. watchpoint_hits_test_1 = debugger_backend.check_watchpoints(iteration=2)
  49. if len(watchpoint_hits_test_1) != 1:
  50. f_write.write("ERROR -> test 1: watchpoint set but not hit just once")
  51. print_watchpoint_hits(watchpoint_hits_test_1, 1, f_write)
  52. # test 2: watchpoint remove and ensure it's not hit
  53. _ = debugger_backend.remove_watchpoint(watchpoint_id=1)
  54. watchpoint_hits_test_2 = debugger_backend.check_watchpoints(iteration=2)
  55. if watchpoint_hits_test_2:
  56. f_write.write("ERROR -> test 2: watchpoint removed but hit")
  57. # test 3: watchpoint set and not hit, then remove
  58. param2 = d.Parameter(name="param", disabled=False, value=-1000.0)
  59. _ = debugger_backend.add_watchpoint(watchpoint_id=2, watch_condition=6,
  60. check_node_list={"Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/"
  61. "Conv2D-op308":
  62. {"device_id": [0], "root_graph_id": [0],
  63. "is_parameter": False
  64. }}, parameter_list=[param2])
  65. watchpoint_hits_test_3 = debugger_backend.check_watchpoints(iteration=2)
  66. if watchpoint_hits_test_3:
  67. f_write.write("ERROR -> test 3: watchpoint set but not supposed to be hit")
  68. _ = debugger_backend.remove_watchpoint(watchpoint_id=2)
  69. # test 4: weight change watchpoint set and hit
  70. param_abs_mean_update_ratio_gt = d.Parameter(
  71. name="abs_mean_update_ratio_gt", disabled=False, value=0.0)
  72. param_epsilon = d.Parameter(name="epsilon", disabled=True, value=0.0)
  73. _ = debugger_backend.add_watchpoint(watchpoint_id=3, watch_condition=18,
  74. check_node_list={"Default/network-WithLossCell/_backbone-AlexNet/fc3-Dense/"
  75. "Parameter[6]_11/fc3.bias":
  76. {"device_id": [0], "root_graph_id": [0],
  77. "is_parameter": True
  78. }}, parameter_list=[param_abs_mean_update_ratio_gt,
  79. param_epsilon])
  80. watchpoint_hits_test_4 = debugger_backend.check_watchpoints(iteration=3)
  81. if len(watchpoint_hits_test_4) != 1:
  82. f_write.write("ERROR -> test 4: watchpoint weight change set but not hit just once")
  83. print_watchpoint_hits(watchpoint_hits_test_4, 4, f_write)
  84. f_write.close()
  85. if not GENERATE_GOLDEN:
  86. assert compare_actual_with_expected(test_name)
  87. def print_watchpoint_hits(watchpoint_hits, test_id, f_write):
  88. """Print watchpoint hits."""
  89. for x, _ in enumerate(watchpoint_hits):
  90. f_write.write("-----------------------------------------------------------\n")
  91. f_write.write("watchpoint_hit for test_%u attributes:" % test_id + "\n")
  92. f_write.write("name = " + watchpoint_hits[x].name + "\n")
  93. f_write.write("slot = " + str(watchpoint_hits[x].slot) + "\n")
  94. f_write.write("condition = " + str(watchpoint_hits[x].condition) + "\n")
  95. f_write.write("watchpoint_id = " + str(watchpoint_hits[x].watchpoint_id) + "\n")
  96. for p, _ in enumerate(watchpoint_hits[x].parameters):
  97. f_write.write("parameter " + str(p) + " name = " +
  98. watchpoint_hits[x].parameters[p].name + "\n")
  99. f_write.write("parameter " + str(p) + " disabled = " +
  100. str(watchpoint_hits[x].parameters[p].disabled) + "\n")
  101. f_write.write("parameter " + str(p) + " value = " +
  102. str(watchpoint_hits[x].parameters[p].value) + "\n")
  103. f_write.write("parameter " + str(p) + " hit = " +
  104. str(watchpoint_hits[x].parameters[p].hit) + "\n")
  105. f_write.write("parameter " + str(p) + " actual_value = " +
  106. str(watchpoint_hits[x].parameters[p].actual_value) + "\n")
  107. f_write.write("error code = " + str(watchpoint_hits[x].error_code) + "\n")
  108. f_write.write("device_id = " + str(watchpoint_hits[x].device_id) + "\n")
  109. f_write.write("root_graph_id = " + str(watchpoint_hits[x].root_graph_id) + "\n")