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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. from tests.security_utils import security_off_wrap
  22. GENERATE_GOLDEN = False
  23. test_name = "sync_trans_false_watchpoints"
  24. @pytest.mark.level0
  25. @pytest.mark.platform_arm_ascend_training
  26. @pytest.mark.platform_x86_ascend_training
  27. @pytest.mark.env_onecard
  28. @pytest.mark.skip(reason="needs updating")
  29. @security_off_wrap
  30. def test_sync_trans_false_watchpoints():
  31. if GENERATE_GOLDEN:
  32. f_write = open(test_name + ".expected", "w")
  33. else:
  34. f_write = open(test_name + ".actual", "w")
  35. debugger_backend = d.DbgServices(
  36. dump_file_path="/home/workspace/mindspore_dataset/dumps/sync_trans_false/alexnet/")
  37. _ = debugger_backend.initialize(
  38. net_name="Network Name goes here!", is_sync_mode=True)
  39. # NOTES:
  40. # -> watch_condition=6 is MIN_LT
  41. # -> watch_condition=18 is CHANGE_TOO_LARGE
  42. # test 1: watchpoint set and hit (watch_condition=6)
  43. param1 = d.Parameter(name="param", disabled=False, value=0.0)
  44. _ = debugger_backend.add_watchpoint(watchpoint_id=1, watch_condition=6,
  45. check_node_list={"Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/"
  46. "Conv2D-op168":
  47. {"device_id": [0], "root_graph_id": [0],
  48. "is_parameter": False
  49. }}, parameter_list=[param1])
  50. watchpoint_hits_test_1 = debugger_backend.check_watchpoints(iteration=2)
  51. if len(watchpoint_hits_test_1) != 1:
  52. f_write.write("ERROR -> test 1: watchpoint set but not hit just once")
  53. print_watchpoint_hits(watchpoint_hits_test_1, 1, f_write)
  54. # test 2: watchpoint remove and ensure it's not hit
  55. _ = debugger_backend.remove_watchpoint(watchpoint_id=1)
  56. watchpoint_hits_test_2 = debugger_backend.check_watchpoints(iteration=2)
  57. if watchpoint_hits_test_2:
  58. f_write.write("ERROR -> test 2: watchpoint removed but hit")
  59. # test 3: watchpoint set and not hit, then remove
  60. param2 = d.Parameter(name="param", disabled=False, value=-1000.0)
  61. _ = debugger_backend.add_watchpoint(watchpoint_id=2, watch_condition=6,
  62. check_node_list={"Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/"
  63. "Conv2D-op308":
  64. {"device_id": [0], "root_graph_id": [0],
  65. "is_parameter": False
  66. }}, parameter_list=[param2])
  67. watchpoint_hits_test_3 = debugger_backend.check_watchpoints(iteration=2)
  68. if watchpoint_hits_test_3:
  69. f_write.write("ERROR -> test 3: watchpoint set but not supposed to be hit")
  70. _ = debugger_backend.remove_watchpoint(watchpoint_id=2)
  71. # test 4: weight change watchpoint set and hit
  72. param_abs_mean_update_ratio_gt = d.Parameter(
  73. name="abs_mean_update_ratio_gt", disabled=False, value=0.0)
  74. param_epsilon = d.Parameter(name="epsilon", disabled=True, value=0.0)
  75. _ = debugger_backend.add_watchpoint(watchpoint_id=3, watch_condition=18,
  76. check_node_list={"Default/network-WithLossCell/_backbone-AlexNet/fc3-Dense/"
  77. "Parameter[6]_11/fc3.bias":
  78. {"device_id": [0], "root_graph_id": [0],
  79. "is_parameter": True
  80. }}, parameter_list=[param_abs_mean_update_ratio_gt,
  81. param_epsilon])
  82. watchpoint_hits_test_4 = debugger_backend.check_watchpoints(iteration=3)
  83. if len(watchpoint_hits_test_4) != 1:
  84. f_write.write("ERROR -> test 4: watchpoint weight change set but not hit just once")
  85. print_watchpoint_hits(watchpoint_hits_test_4, 4, f_write)
  86. f_write.close()
  87. if not GENERATE_GOLDEN:
  88. assert compare_actual_with_expected(test_name)
  89. def print_watchpoint_hits(watchpoint_hits, test_id, f_write):
  90. """Print watchpoint hits."""
  91. for x, _ in enumerate(watchpoint_hits):
  92. f_write.write("-----------------------------------------------------------\n")
  93. f_write.write("watchpoint_hit for test_%u attributes:" % test_id + "\n")
  94. f_write.write("name = " + watchpoint_hits[x].name + "\n")
  95. f_write.write("slot = " + str(watchpoint_hits[x].slot) + "\n")
  96. f_write.write("condition = " + str(watchpoint_hits[x].condition) + "\n")
  97. f_write.write("watchpoint_id = " + str(watchpoint_hits[x].watchpoint_id) + "\n")
  98. for p, _ in enumerate(watchpoint_hits[x].parameters):
  99. f_write.write("parameter " + str(p) + " name = " +
  100. watchpoint_hits[x].parameters[p].name + "\n")
  101. f_write.write("parameter " + str(p) + " disabled = " +
  102. str(watchpoint_hits[x].parameters[p].disabled) + "\n")
  103. f_write.write("parameter " + str(p) + " value = " +
  104. str(watchpoint_hits[x].parameters[p].value) + "\n")
  105. f_write.write("parameter " + str(p) + " hit = " +
  106. str(watchpoint_hits[x].parameters[p].hit) + "\n")
  107. f_write.write("parameter " + str(p) + " actual_value = " +
  108. str(watchpoint_hits[x].parameters[p].actual_value) + "\n")
  109. f_write.write("error code = " + str(watchpoint_hits[x].error_code) + "\n")
  110. f_write.write("device_id = " + str(watchpoint_hits[x].device_id) + "\n")
  111. f_write.write("root_graph_id = " + str(watchpoint_hits[x].root_graph_id) + "\n")