Browse Source

debugger: add ST testcases for graph handler

tags/v1.0.0
zhangyunshu 5 years ago
parent
commit
780e8d2917
11 changed files with 208 additions and 0 deletions
  1. +14
    -0
      tests/st/func/debugger/__init__.py
  2. +40
    -0
      tests/st/func/debugger/conftest.py
  3. +1
    -0
      tests/st/func/debugger/expect_results/graph_handler_get_1_no_filter_condintion.json
  4. +1
    -0
      tests/st/func/debugger/expect_results/graph_handler_get_2_list_nodes.json
  5. +1
    -0
      tests/st/func/debugger/expect_results/graph_handler_get_3_single_node.json
  6. +1
    -0
      tests/st/func/debugger/expect_results/search_node_1.json
  7. +1
    -0
      tests/st/func/debugger/expect_results/search_nodes_0.json
  8. +1
    -0
      tests/st/func/debugger/expect_results/tenor_hist_0.json
  9. +1
    -0
      tests/st/func/debugger/expect_results/tensor_hist_1.json
  10. +147
    -0
      tests/st/func/debugger/test_graph_handler.py
  11. BIN
      tests/utils/resource/graph_pb/lenet.pb

+ 14
- 0
tests/st/func/debugger/__init__.py View File

@@ -0,0 +1,14 @@
# 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.
# ============================================================================

+ 40
- 0
tests/st/func/debugger/conftest.py View File

@@ -0,0 +1,40 @@
# 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.
# ============================================================================
"""
Description: This file is used for some common util.
"""
import os

from mindinsight.debugger.proto import ms_graph_pb2
from mindinsight.debugger.stream_handler.graph_handler import GraphHandler


graph_proto_file = os.path.join(
os.path.dirname(__file__), '../../../utils/resource/graph_pb/lenet.pb'
)


def init_graph_handler():
"""Init graph proto."""
with open(graph_proto_file, 'rb') as f:
content = f.read()

graph = ms_graph_pb2.GraphProto()
graph.ParseFromString(content)

graph_handler = GraphHandler()
graph_handler.put(graph)

return graph_handler

+ 1
- 0
tests/st/func/debugger/expect_results/graph_handler_get_1_no_filter_condintion.json
File diff suppressed because it is too large
View File


+ 1
- 0
tests/st/func/debugger/expect_results/graph_handler_get_2_list_nodes.json
File diff suppressed because it is too large
View File


+ 1
- 0
tests/st/func/debugger/expect_results/graph_handler_get_3_single_node.json
File diff suppressed because it is too large
View File


+ 1
- 0
tests/st/func/debugger/expect_results/search_node_1.json View File

@@ -0,0 +1 @@
{"nodes": [{"name": "Default", "type": null, "nodes": [{"name": "Default/network-WithLossCell", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst1", "type": "Const", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst2", "type": "Const", "nodes": []}]}]}, {"name": "Default/tuple_getitem[10]_0", "type": null, "nodes": [{"name": "Default/tuple_getitem[10]_0/cst3", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst4", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst5", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst6", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst7", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst27", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst28", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst32", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst33", "type": "Const", "nodes": []}, {"name": "Default/tuple_getitem[10]_0/cst37", "type": "Const", "nodes": []}]}, {"name": "Default/optimizer-Momentum", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/tuple_getitem[16]_2", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst9", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst10", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst12", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst13", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst15", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst16", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst18", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst19", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst21", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst22", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst24", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst25", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst29", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst30", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst34", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/tuple_getitem[16]_2/cst35", "type": "Const", "nodes": []}]}, {"name": "Default/optimizer-Momentum/Depend[8]_4", "type": null, "nodes": [{"name": "Default/optimizer-Momentum/Depend[8]_4/cst11", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst14", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst17", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst20", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst23", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst26", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst31", "type": "Const", "nodes": []}, {"name": "Default/optimizer-Momentum/Depend[8]_4/cst36", "type": "Const", "nodes": []}]}]}]}, {"name": "Gradients", "type": null, "nodes": [{"name": "Gradients/Default", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/cst8", "type": "Const", "nodes": []}]}]}]}]}]}]}

+ 1
- 0
tests/st/func/debugger/expect_results/search_nodes_0.json View File

@@ -0,0 +1 @@
{"nodes": [{"name": "Default", "type": null, "nodes": [{"name": "Default/network-WithLossCell", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/OneHot-op0", "type": "OneHot", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/SoftmaxCrossEntropyWithLogits-op18", "type": "SoftmaxCrossEntropyWithLogits", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/ReduceMean-op60", "type": "ReduceMean", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/args1", "type": "Parameter", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst1", "type": "Const", "nodes": []}, {"name": "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst2", "type": "Const", "nodes": []}]}]}]}, {"name": "Gradients", "type": null, "nodes": [{"name": "Gradients/Default", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits", "type": null, "nodes": [{"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/Mul-op20", "type": "Mul", "nodes": []}, {"name": "Gradients/Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/gradSoftmaxCrossEntropyWithLogits/cst8", "type": "Const", "nodes": []}]}]}]}]}]}]}

+ 1
- 0
tests/st/func/debugger/expect_results/tenor_hist_0.json View File

@@ -0,0 +1 @@
{"tensor_history": [{"name": "Default/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Cast-op190:0", "full_name": "Default/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Cast-op190:0", "node_type": "Cast", "type": "output"}, {"name": "Default/TransData-op99:0", "full_name": "Default/TransData-op99:0", "node_type": "TransData", "type": "input"}]}

+ 1
- 0
tests/st/func/debugger/expect_results/tensor_hist_1.json View File

@@ -0,0 +1 @@
{"tensor_history": [{"name": "Default/optimizer-Momentum/ApplyMomentum[8]_1/ApplyMomentum-op22:0", "full_name": "Default/optimizer-Momentum/ApplyMomentum-op22:0", "node_type": "ApplyMomentum", "type": "output"}, {"name": "Default/optimizer-Momentum/ApplyMomentum[8]_1/ApplyMomentum-op22:1", "full_name": "Default/optimizer-Momentum/ApplyMomentum-op22:1", "node_type": "ApplyMomentum", "type": "output"}, {"name": "Gradients/Default/network-WithLossCell/_backbone-LeNet5/fc3-Dense/gradBiasAdd/BiasAddGrad-op21:0", "full_name": "Gradients/Default/network-WithLossCell/_backbone-LeNet5/fc3-Dense/gradBiasAdd/BiasAddGrad-op21:0", "node_type": "BiasAddGrad", "type": "input"}, {"name": "Default/optimizer-Momentum/Parameter[18]_7/fc3.bias:0", "full_name": "Default/optimizer-Momentum/Parameter[18]_7/fc3.bias:0", "node_type": "Parameter", "type": "input"}, {"name": "Default/optimizer-Momentum/Parameter[18]_7/moments.fc3.bias:0", "full_name": "Default/optimizer-Momentum/Parameter[18]_7/moments.fc3.bias:0", "node_type": "Parameter", "type": "input"}, {"name": "Default/optimizer-Momentum/Parameter[18]_7/learning_rate:0", "full_name": "Default/optimizer-Momentum/Parameter[18]_7/learning_rate:0", "node_type": "Parameter", "type": "input"}, {"name": "Default/optimizer-Momentum/Parameter[18]_7/momentum:0", "full_name": "Default/optimizer-Momentum/Parameter[18]_7/momentum:0", "node_type": "Parameter", "type": "input"}]}

+ 147
- 0
tests/st/func/debugger/test_graph_handler.py View File

@@ -0,0 +1,147 @@
# 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.
# ============================================================================
"""
Description: This file is used for testing graph handler.
"""
import os

import pytest

from ....utils.tools import compare_result_with_file
from .conftest import init_graph_handler


class TestGraphHandler:
"""Test GraphHandler."""
graph_results_dir = os.path.join(os.path.dirname(__file__), 'expect_results')
graph_handler = init_graph_handler()

@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
@pytest.mark.parametrize("filter_condition, result_file", [
(None, "graph_handler_get_1_no_filter_condintion.json"),
({'name': 'Default'}, "graph_handler_get_2_list_nodes.json"),
({'name': 'Default/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Cast-op190', 'single_node': True},
"graph_handler_get_3_single_node.json")
])
def test_get(self, filter_condition, result_file):
"""Test get."""
result = self.graph_handler.get(filter_condition)
file_path = os.path.join(self.graph_results_dir, result_file)
compare_result_with_file(result, file_path)

@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
@pytest.mark.parametrize("node_name, result_file", [
("Default/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Cast-op190",
"tenor_hist_0.json"),
("Default/optimizer-Momentum/ApplyMomentum[8]_1/ApplyMomentum-op22",
"tensor_hist_1.json")
])
def test_get_tensor_history(self, node_name, result_file):
"""Test get tensor history."""
result = self.graph_handler.get_tensor_history(node_name)
file_path = os.path.join(self.graph_results_dir, result_file)
compare_result_with_file(result, file_path)

@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
@pytest.mark.parametrize("pattern, result_file", [
("withlogits", "search_nodes_0.json"),
("cst", "search_node_1.json")
])
def test_search_nodes(self, pattern, result_file):
"""Test search nodes."""
result = self.graph_handler.search_nodes(pattern)
file_path = os.path.join(self.graph_results_dir, result_file)
compare_result_with_file(result, file_path)

@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
@pytest.mark.parametrize("node_name, expect_type", [
("Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/cst1", 'Const'),
("Default/TransData-op99", "TransData")
])
def test_get_node_type(self, node_name, expect_type):
"""Test get node type."""
node_type = self.graph_handler.get_node_type(node_name)
assert node_type == expect_type

@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
@pytest.mark.parametrize("node_name, expect_full_name", [
(None, ""),
("Default/make_tuple[9]_3/make_tuple-op284", "Default/make_tuple-op284"),
("Default/args0", "Default/args0")
])
def test_get_full_name(self, node_name, expect_full_name):
"""Test get full name."""
full_name = self.graph_handler.get_full_name(node_name)
assert full_name == expect_full_name

@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
@pytest.mark.parametrize("full_name, expect_node_name", [
(None, ""),
("Default/make_tuple-op284", "Default/make_tuple[9]_3/make_tuple-op284"),
("Default/args0", "Default/args0")
])
def test_get_node_name_by_full_name(self, full_name, expect_node_name):
"""Test get node name by full name."""
node_name = self.graph_handler.get_node_name_by_full_name(full_name)
assert node_name == expect_node_name

@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
@pytest.mark.parametrize("node_name, ascend, expect_next", [
(None, True, "Default/network-WithLossCell/_loss_fn-SoftmaxCrossEntropyWithLogits/OneHot-op0"),
(None, False, None),
("Default/tuple_getitem[10]_0/tuple_getitem-op206", True,
"Default/network-WithLossCell/_backbone-LeNet5/relu-ReLU/ReLUV2-op89"),
("Default/tuple_getitem[10]_0/tuple_getitem-op206", False,
"Default/network-WithLossCell/_backbone-LeNet5/max_pool2d-MaxPool2d/Cast-op205")
])
def test_get_node_by_bfs_order(self, node_name, ascend, expect_next):
"""Test get node by BFS order."""
next_node = self.graph_handler.get_node_by_bfs_order(node_name, ascend)
assert next_node == expect_next

BIN
tests/utils/resource/graph_pb/lenet.pb View File


Loading…
Cancel
Save