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_analyse.py 6.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # Copyright 2019 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. Function:
  17. Test profiler to watch the performance of training.
  18. Usage:
  19. pytest tests/st/func/profiler
  20. """
  21. import os
  22. from unittest import TestCase
  23. import pytest
  24. from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
  25. from mindinsight.profiler.common.exceptions.exceptions import StepNumNotSupportedException, \
  26. ProfilerParamValueErrorException
  27. from tests.st.func.profiler.conftest import BASE_SUMMARY_DIR
  28. class TestProfilerAnalyse(TestCase):
  29. """Test Converter module."""
  30. JOB_ID = 'JOB3'
  31. @classmethod
  32. def setup_class(cls):
  33. """Generate parsed files."""
  34. cls.step_trace_file = 'step_trace_raw_1_detail_time.csv'
  35. cls.summary_dir = os.path.join(BASE_SUMMARY_DIR, 'normal_run')
  36. cls.profiler = os.path.join(cls.summary_dir, 'profiler')
  37. def setUp(self):
  38. """Setup before each test."""
  39. self.step_trace_analyser = AnalyserFactory.instance().get_analyser(
  40. 'step_trace', self.profiler, '1')
  41. @pytest.mark.level0
  42. @pytest.mark.env_single
  43. @pytest.mark.platform_x86_cpu
  44. @pytest.mark.platform_arm_ascend_training
  45. @pytest.mark.platform_x86_gpu_training
  46. @pytest.mark.platform_x86_ascend_training
  47. def test_step_trace_file_exist(self):
  48. """Test the step trace file has been generated"""
  49. output_files = os.listdir(self.profiler)
  50. assert self.step_trace_file in output_files
  51. @pytest.mark.level0
  52. @pytest.mark.env_single
  53. @pytest.mark.platform_x86_cpu
  54. @pytest.mark.platform_arm_ascend_training
  55. @pytest.mark.platform_x86_gpu_training
  56. @pytest.mark.platform_x86_ascend_training
  57. def test_step_trace_point_info(self):
  58. """Test the step trace file has been generated"""
  59. point_info = self.step_trace_analyser.point_info
  60. assert point_info == {
  61. 'fp_start': 'Default/Cast-op6',
  62. 'bp_end': 'Default/TransData-op7'
  63. }
  64. @pytest.mark.level0
  65. @pytest.mark.env_single
  66. @pytest.mark.platform_x86_cpu
  67. @pytest.mark.platform_arm_ascend_training
  68. @pytest.mark.platform_x86_gpu_training
  69. @pytest.mark.platform_x86_ascend_training
  70. def test_graph_api(self):
  71. """Test step trace restful api."""
  72. condition = {
  73. 'filter_condition': {
  74. 'mode': 'step',
  75. 'step_id': 0
  76. }
  77. }
  78. analyser = self.step_trace_analyser
  79. res = analyser.query(condition)
  80. assert res['size'] == 322
  81. assert len(res['training_trace_graph']) == 13
  82. assert res['training_trace_graph'][-1] == [
  83. {'name': '', 'start': 0.2038, 'duration': 118.1667},
  84. {'name': 'stream_540_parallel_0', 'start': 118.3705, 'duration': 49.281},
  85. {'name': '', 'start': 167.6515, 'duration': 37.7294}]
  86. @pytest.mark.level0
  87. @pytest.mark.env_single
  88. @pytest.mark.platform_x86_cpu
  89. @pytest.mark.platform_arm_ascend_training
  90. @pytest.mark.platform_x86_gpu_training
  91. @pytest.mark.platform_x86_ascend_training
  92. def test_graph_api_error(self):
  93. """Test graph api without mode."""
  94. condition = {
  95. 'filter_condition': {
  96. 'step_id': -1
  97. }}
  98. self.assertRaisesRegex(
  99. StepNumNotSupportedException,
  100. 'The step num must be in',
  101. self.step_trace_analyser.query,
  102. condition
  103. )
  104. @pytest.mark.level0
  105. @pytest.mark.env_single
  106. @pytest.mark.platform_x86_cpu
  107. @pytest.mark.platform_arm_ascend_training
  108. @pytest.mark.platform_x86_gpu_training
  109. @pytest.mark.platform_x86_ascend_training
  110. def test_target_info_api(self):
  111. """Test step trace restful api."""
  112. condition = {
  113. 'filter_condition': {
  114. 'mode': 'proc',
  115. 'step_id': None
  116. }
  117. }
  118. analyser = AnalyserFactory.instance().get_analyser('step_trace', self.profiler, '1')
  119. for proc_name in ['iteration_interval', 'fp_and_bp', 'tail']:
  120. condition['filter_condition']['proc_name'] = proc_name
  121. res = analyser.query(condition)
  122. assert res['size'] == 322
  123. assert len(res['info'][proc_name]) == res['size']
  124. @pytest.mark.level0
  125. @pytest.mark.env_single
  126. @pytest.mark.platform_x86_cpu
  127. @pytest.mark.platform_arm_ascend_training
  128. @pytest.mark.platform_x86_gpu_training
  129. @pytest.mark.platform_x86_ascend_training
  130. def test_summary_for_step_trace(self):
  131. """Test summary for step trace."""
  132. analyser = AnalyserFactory.instance().get_analyser('step_trace', self.profiler, '1')
  133. summary = analyser.summary
  134. assert summary == {
  135. 'total_time': 205.3809,
  136. 'iteration_interval': 0.2038,
  137. 'iteration_interval_percent': '0.1%',
  138. 'fp_and_bp': 118.054,
  139. 'fp_and_bp_percent': '57.48%',
  140. 'tail': 87.1231,
  141. 'tail_percent': '42.42%',
  142. 'total_steps': 322}
  143. @pytest.mark.level0
  144. @pytest.mark.env_single
  145. @pytest.mark.platform_x86_cpu
  146. @pytest.mark.platform_arm_ascend_training
  147. @pytest.mark.platform_x86_gpu_training
  148. @pytest.mark.platform_x86_ascend_training
  149. def test_target_info_api_error(self):
  150. """Test graph api without mode."""
  151. condition = {
  152. 'filter_condition': {
  153. 'proc_name': 'fake name'
  154. }}
  155. self.assertRaisesRegex(
  156. ProfilerParamValueErrorException,
  157. 'Param value error',
  158. self.step_trace_analyser.query,
  159. condition
  160. )