Browse Source

!752 Add some mindinsight.profiler tests code

Merge pull request !752 from 张毅辉/zyh_mindinsight_profiler_st_6
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
ea4c747a52
3 changed files with 167 additions and 0 deletions
  1. +78
    -0
      tests/st/func/profiler/test_aicpu_analyser.py
  2. +78
    -0
      tests/ut/profiler/analyser/test_aicpu_analyser.py
  3. +11
    -0
      tests/ut/profiler/analyser/test_training_trace_analyse.py

+ 78
- 0
tests/st/func/profiler/test_aicpu_analyser.py View File

@@ -0,0 +1,78 @@
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""
Fuction:
Test profiler to watch the performance of training.
Usage:
pytest tests/st/func/profiler
"""
import os
import pytest

from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
from tests.st.func.profiler.conftest import BASE_SUMMARY_DIR_RUN_2


class TestAicpuAnalyser:
"""Test AICPU analyser module."""
@classmethod
def setup_class(cls):
"""Generate parsed files."""
cls.summary_dir = os.path.join(BASE_SUMMARY_DIR_RUN_2, 'normal_run')
cls.profiler = os.path.join(cls.summary_dir, 'profiler')

def setup_method(self):
"""Create analyser."""
self._analyser_aicpu_type = AnalyserFactory.instance().get_analyser(
'aicpu_type', self.profiler, '1')
self._analyser_aicpu_detail = AnalyserFactory.instance().get_analyser(
'aicpu_detail', self.profiler, '1')

@pytest.mark.level0
@pytest.mark.env_single
@pytest.mark.platform_x86_cpu
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_ascend_training
def test_query_aicpu_type(self):
"""Test the function of querying AICPU operator type infomation."""
expect_result = {
'col_name': ['op_type', 'execution_time', 'execution_frequency', 'percent'],
'object': [
['InitData', 7.906, 1, 89.84],
['GetNext', 0.5905, 2, 6.71],
['EndOfSequence', 0.3035, 2, 3.45]
],
'size': 3
}
result = self._analyser_aicpu_type.query()
assert expect_result == result

@pytest.mark.level0
@pytest.mark.env_single
@pytest.mark.platform_x86_cpu
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_ascend_training
def test_query_aicpu_detail(self):
"""Test the function of querying AICPU operator type infomation."""
expect_result = {
'col_name': ['serial_number', 'op_type', 'total_time',
'dispatch_time', 'run_start', 'run_end'],
'size': 5
}
result = self._analyser_aicpu_detail.query()
del result["object"]
assert expect_result == result

+ 78
- 0
tests/ut/profiler/analyser/test_aicpu_analyser.py View File

@@ -0,0 +1,78 @@
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""
Fuction:
Test profiler to watch the performance of training.
Usage:
pytest tests/ut/func/profiler
"""
import os

from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
from tests.ut.profiler import BASE_SUMMARY_DIR


class TestAicpuAnalyser:
"""Test AICPU analyser module."""
@classmethod
def setup_class(cls):
"""Generate parsed files."""
cls.summary_dir = os.path.join(BASE_SUMMARY_DIR, 'normal_run')
cls.profiler = os.path.join(cls.summary_dir, 'profiler')

def setup_method(self):
"""Create analyser."""
self._analyser_aicpu_type = AnalyserFactory.instance().get_analyser(
'aicpu_type', self.profiler, '1')
self._analyser_aicpu_detail = AnalyserFactory.instance().get_analyser(
'aicpu_detail', self.profiler, '1')

def test_query_aicpu_type(self):
"""Test the function of querying AICPU operator type infomation."""
expect_result = {
'col_name': ['op_type', 'execution_time', 'execution_frequency', 'percent'],
'object': [
['InitData', 7.906, 1, 89.84],
],
'size': 1
}
condition = {
'filter_condition': {
'op_type': {
'partial_match_str_in': ['init']
}
}
}
result = self._analyser_aicpu_type.query(condition)
assert expect_result == result

def test_query_aicpu_detail(self):
"""Test the function of querying AICPU operator detail infomation."""
expect_result = {
'col_name': ['serial_number', 'op_type', 'total_time',
'dispatch_time', 'run_start', 'run_end'],
'size': 2
}

condition = {
'filter_condition': {
'op_type': {
'partial_match_str_in': ['get']
}
}
}
result = self._analyser_aicpu_detail.query(condition)
del result["object"]
assert expect_result == result

+ 11
- 0
tests/ut/profiler/analyser/test_training_trace_analyse.py View File

@@ -19,8 +19,10 @@ Usage:
pytest tests/ut/profiler pytest tests/ut/profiler
""" """
import os import os
import pytest


from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
from mindinsight.profiler.common.exceptions.exceptions import StepNumNotSupportedException
from tests.ut.profiler import BASE_SUMMARY_DIR from tests.ut.profiler import BASE_SUMMARY_DIR




@@ -80,3 +82,12 @@ class TestTrainingTraceAnalyser:
'proc_name': proc_name 'proc_name': proc_name
}}) }})
assert expect_result == result assert expect_result == result

def test_analyse_get_training_trace_graph_with_wrong_id(self):
with pytest.raises(StepNumNotSupportedException) as exc:
self._analyser.query({
'filter_condition': {
'mode': 'step',
'step_id': 10
}})
assert exc.value.message == 'The step num must be in [0, 1]'

Loading…
Cancel
Save