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_op_analyser.py 8.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # Copyright 2020 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. Fuction:
  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 mock
  23. import pytest
  24. from mindinsight.profiler import Profiler
  25. from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
  26. from mindinsight.profiler.parser.framework_parser import FrameworkParser
  27. from tests.st.func.profiler.conftest import BASE_SUMMARY_DIR
  28. from tests.ut.profiler import RAW_DATA_BASE
  29. OP_GATHER_V2_INFO = {
  30. 'col_name': [
  31. 'op_name', 'op_type', 'avg_execution_time (ms)', 'subgraph', 'full_op_name',
  32. 'op_info'
  33. ],
  34. 'object': [
  35. [
  36. 'GatherV2-op55', 'GatherV2', 42.220212142857136, 'Default',
  37. 'Default/network-TrainStepWrap/network-VirtualDatasetCellTriple/'
  38. '_backbone-NetWithLossClass/network-WideDeepModel/GatherV2-op55',
  39. {
  40. 'input_0': {
  41. 'format': 'DefaultFormat',
  42. 'data_type': 'NUMBER_TYPE_FLOAT32',
  43. 'shape': '184696,8'
  44. },
  45. 'input_1': {
  46. 'format': 'DefaultFormat',
  47. 'data_type': 'NUMBER_TYPE_INT32',
  48. 'shape': '128000,39'
  49. },
  50. 'output_0': {
  51. 'format': 'DefaultFormat',
  52. 'data_type': 'NUMBER_TYPE_FLOAT32',
  53. 'shape': '128000,39,8'
  54. }
  55. }
  56. ],
  57. [
  58. 'GatherV2-op33', 'GatherV2', 0.9352293333333332, 'Default',
  59. 'Default/network-TrainStepWrap/network-VirtualDatasetCellTriple/'
  60. '_backbone-NetWithLossClass/network-WideDeepModel/GatherV2-op33',
  61. {
  62. 'input_0': {
  63. 'format': 'DefaultFormat',
  64. 'data_type': 'NUMBER_TYPE_FLOAT32',
  65. 'shape': '184696,1'
  66. },
  67. 'input_1': {
  68. 'format': 'DefaultFormat',
  69. 'data_type': 'NUMBER_TYPE_INT32',
  70. 'shape': '16000,39'
  71. },
  72. 'output_0': {
  73. 'format': 'DefaultFormat',
  74. 'data_type': 'NUMBER_TYPE_FLOAT32',
  75. 'shape': '16000,39,1'
  76. }
  77. }
  78. ]
  79. ],
  80. 'size': 2
  81. }
  82. @pytest.mark.usefixtures('create_summary_dir')
  83. class TestOpAnalyser:
  84. """Test AICORE and AICPU analyser module."""
  85. JOB_ID = 'JOB3'
  86. @classmethod
  87. def setup_class(cls):
  88. """Generate parsed files."""
  89. cls.generate_parsed_files()
  90. def setup_method(self):
  91. """Create analyser."""
  92. self._analyser_aicore_type = AnalyserFactory.instance().get_analyser(
  93. 'aicore_type', self.profiler, '1')
  94. self._analyser_aicore_detail = AnalyserFactory.instance().get_analyser(
  95. 'aicore_detail', self.profiler, '1')
  96. @classmethod
  97. def generate_parsed_files(cls):
  98. """Test parse raw info about profiler."""
  99. cls.summary_dir = os.path.join(BASE_SUMMARY_DIR, 'normal_run')
  100. cls.profiler = os.path.join(cls.summary_dir, 'profiler')
  101. FrameworkParser._raw_data_dir = RAW_DATA_BASE
  102. if not os.path.exists(cls.summary_dir):
  103. os.makedirs(cls.summary_dir)
  104. Profiler._base_profiling_container_path = os.path.join(RAW_DATA_BASE, 'container')
  105. with mock.patch('mindinsight.profiler.profiling.PROFILING_LOG_BASE_PATH', RAW_DATA_BASE):
  106. profiler = Profiler(subgraph='all', is_detail=True, is_show_op_path=False,
  107. output_path=cls.summary_dir, job_id=cls.JOB_ID)
  108. profiler.analyse()
  109. @pytest.mark.level0
  110. @pytest.mark.env_single
  111. @pytest.mark.platform_x86_cpu
  112. @pytest.mark.platform_arm_ascend_training
  113. @pytest.mark.platform_x86_gpu_training
  114. @pytest.mark.platform_x86_ascend_training
  115. def test_query_aicore_type_1(self):
  116. """Test the function of querying AICORE operator type infomation."""
  117. expect_result = {
  118. 'col_name': ['op_type', 'execution_time (ms)', 'execution_frequency', 'percent'],
  119. 'object': [
  120. ['UnsortedSegmentSum', 44.607826, 2, 35.28],
  121. ['GatherV2', 43.155441, 2, 34.13],
  122. ['Slice', 20.376315, 16, 16.12],
  123. ['Concat', 5.808454, 4, 4.59],
  124. ['Split', 2.714277, 2, 2.15],
  125. ['MatMul', 1.936681, 15, 1.53],
  126. ['Mul', 1.902949, 32, 1.51],
  127. ['StridedSliceGrad', 1.506834, 2, 1.19],
  128. ['TransData', 1.115158, 30, 0.88],
  129. ['ReluGrad', 0.854069, 5, 0.68],
  130. ['Cast', 0.484685, 15, 0.38],
  131. ['ReLU', 0.483282, 5, 0.38],
  132. ['RealDiv', 0.422807, 15, 0.33],
  133. ['StridedSlice', 0.345569, 2, 0.27],
  134. ['Adam', 0.285936, 11, 0.23],
  135. ['BiasAdd', 0.189663, 5, 0.15],
  136. ['BiasAddGrad', 0.071681, 5, 0.06],
  137. ['Tile', 0.044158, 4, 0.03],
  138. ['ReduceSum', 0.030765, 5, 0.02],
  139. ['ApplyFtrl', 0.025454, 2, 0.02],
  140. ['AtomicAddrClean', 0.019369, 8, 0.02],
  141. ['AddN', 0.012836, 1, 0.01],
  142. ['Square', 0.009799, 1, 0.01],
  143. ['SigmoidCrossEntropyWithLogitsGrad', 0.009582, 2, 0.01],
  144. ['TensorAdd', 0.009218, 3, 0.01],
  145. ['SigmoidCrossEntropyWithLogits', 0.004809, 1, 0.0],
  146. ['ReduceMean', 0.004535, 1, 0.0],
  147. ['Assign', 0.002477, 2, 0.0],
  148. ['AssignAdd', 0.001688, 1, 0.0]
  149. ],
  150. 'size': 29
  151. }
  152. condition = {
  153. 'sort_condition': {
  154. 'name': 'execution_time',
  155. 'type': 'descending'
  156. }
  157. }
  158. result = self._analyser_aicore_type.query(condition)
  159. assert expect_result == result
  160. @pytest.mark.level0
  161. @pytest.mark.env_single
  162. @pytest.mark.platform_x86_cpu
  163. @pytest.mark.platform_arm_ascend_training
  164. @pytest.mark.platform_x86_gpu_training
  165. @pytest.mark.platform_x86_ascend_training
  166. def test_query_aicore_type_2(self):
  167. """Test the function of querying AICORE operator type infomation."""
  168. expect_result = {
  169. 'col_name': ['op_type', 'execution_time (ms)', 'execution_frequency', 'percent'],
  170. 'object': [
  171. ['MatMul', 1.936681, 15, 1.53],
  172. ['Mul', 1.902949, 32, 1.51]
  173. ],
  174. 'size': 2
  175. }
  176. condition = {
  177. 'filter_condition': {
  178. 'op_type': {
  179. 'partial_match_str_in': ['Mul']
  180. }
  181. },
  182. 'sort_condition': {
  183. 'name': 'execution_time',
  184. 'type': 'descending'
  185. }
  186. }
  187. result = self._analyser_aicore_type.query(condition)
  188. assert expect_result == result
  189. @pytest.mark.level0
  190. @pytest.mark.env_single
  191. @pytest.mark.platform_x86_cpu
  192. @pytest.mark.platform_arm_ascend_training
  193. @pytest.mark.platform_x86_gpu_training
  194. @pytest.mark.platform_x86_ascend_training
  195. def test_query_aicore_detail_1(self):
  196. """Test the function of querying AICORE operator detail infomation."""
  197. expect_result = OP_GATHER_V2_INFO
  198. condition = {
  199. 'filter_condition': {
  200. 'op_type': {
  201. 'in': ['GatherV2']
  202. }
  203. },
  204. 'sort_condition': {
  205. 'name': 'avg_execution_time',
  206. 'type': 'descending'
  207. },
  208. 'group_condition': {
  209. 'limit': 10,
  210. 'offset': 0
  211. }
  212. }
  213. result = self._analyser_aicore_detail.query(condition)
  214. assert expect_result == result