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

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