From fbdfdb11279412c5d50a22ea302804056e928107 Mon Sep 17 00:00:00 2001 From: xiao_yao1994 Date: Mon, 16 May 2022 20:40:24 +0800 Subject: [PATCH] "change default backend in debug graph mode and set uni folder for ge test" --- tests/st/control/test_ascend_control_sink.py | 17 ----- tests/st/control/test_switch_layer.py | 20 ------ tests/st/ge/run_cell_list_in_while.py | 62 ++++++++++++++++ tests/st/ge/run_cell_list_in_while.sh | 37 ++++++++++ .../st/ge/run_while_by_cell_list_in_while.py | 70 ++++++++++++++++++ .../st/ge/run_while_by_cell_list_in_while.sh | 38 ++++++++++ tests/st/ge/test_cell_list_in_while.py | 32 +++++++++ .../st/ge/test_while_by_cell_list_in_while.py | 32 +++++++++ tests/ut/ge/run_simple_net.py | 71 +++++++++++++++++++ tests/ut/ge/run_simple_net.sh | 38 ++++++++++ tests/ut/ge/test_simple_net.py | 32 +++++++++ tests/ut/python/nn/test_triu.py | 15 ---- .../ut/python/pipeline/parse/test_for_stmt.py | 21 ------ 13 files changed, 412 insertions(+), 73 deletions(-) create mode 100644 tests/st/ge/run_cell_list_in_while.py create mode 100644 tests/st/ge/run_cell_list_in_while.sh create mode 100644 tests/st/ge/run_while_by_cell_list_in_while.py create mode 100644 tests/st/ge/run_while_by_cell_list_in_while.sh create mode 100644 tests/st/ge/test_cell_list_in_while.py create mode 100644 tests/st/ge/test_while_by_cell_list_in_while.py create mode 100644 tests/ut/ge/run_simple_net.py create mode 100644 tests/ut/ge/run_simple_net.sh create mode 100644 tests/ut/ge/test_simple_net.py diff --git a/tests/st/control/test_ascend_control_sink.py b/tests/st/control/test_ascend_control_sink.py index 31630843e57..8957c8ed443 100644 --- a/tests/st/control/test_ascend_control_sink.py +++ b/tests/st/control/test_ascend_control_sink.py @@ -13,7 +13,6 @@ # limitations under the License. # ============================================================================ """ test_ascend_control_sink """ -import os import pytest import numpy as np import mindspore.context as context @@ -387,19 +386,3 @@ def test_control_flow_ref(): input_x = Tensor(6, ms.float32) out = net(input_x) assert out == 4 - - -@pytest.mark.level0 -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_cell_list_in_while_by_while_ge(): - """ - Feature: Control flow(while and case) implement in ge - Description: run the whole graph sink in ascend in ge backend - Expectation: success - """ - os.environ['MS_ENABLE_GE'] = "1" - out = cell_list_in_while_by_while() - assert out == Tensor(172, mstype.int32) - del os.environ['MS_ENABLE_GE'] diff --git a/tests/st/control/test_switch_layer.py b/tests/st/control/test_switch_layer.py index 8c4cb45f8f8..ebd3bda6097 100644 --- a/tests/st/control/test_switch_layer.py +++ b/tests/st/control/test_switch_layer.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -import os import numpy as np import pytest @@ -115,22 +114,3 @@ def test_cell_in_list(): assert out == Tensor(160, mstype.int32) assert grad_out == Tensor(16, mstype.int32) - - -@pytest.mark.level0 -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_cell_in_list_ge(): - """ - Feature: Switch layer in while in ge backend. - Description: test recursive switch layer in ge backend. - Expectation: success. - """ - os.environ['MS_ENABLE_GE'] = "1" - net = CellInList() - t = Tensor(20, mstype.int32) - x = Tensor(0, mstype.int32) - out = net(t, x) - del os.environ['MS_ENABLE_GE'] - assert out == Tensor(320, mstype.int32) diff --git a/tests/st/ge/run_cell_list_in_while.py b/tests/st/ge/run_cell_list_in_while.py new file mode 100644 index 00000000000..e057225c7cd --- /dev/null +++ b/tests/st/ge/run_cell_list_in_while.py @@ -0,0 +1,62 @@ +# Copyright 2022 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. +# ============================================================================ +import mindspore.context as context +from mindspore import Tensor, nn +from mindspore.common import dtype as mstype + +context.set_context(mode=context.GRAPH_MODE) + + +class SingleCell(nn.Cell): + def __init__(self, i): + super().__init__() + self.i = i + + def construct(self, x): + return self.i * x + + +class CellListInWhile(nn.Cell): + def __init__(self): + super().__init__() + self.cell_list = nn.CellList() + self.cell_list.append(SingleCell(4)) + self.cell_list.append(SingleCell(5)) + self.cell_list.append(SingleCell(6)) + + def construct(self, t, x): + out = t + x = 0 + while x < 3: + add = self.cell_list[x](t) + out = out + add + x += 1 + return out + + +def test_cell_list_in_while_ge(): + """ + Feature: Switch layer in while in ge backend. + Description: test recursive switch layer in ge backend. + Expectation: success. + """ + net = CellListInWhile() + t = Tensor(20, mstype.int32) + x = Tensor(0, mstype.int32) + out = net(t, x) + assert out == Tensor(320, mstype.int32) + +if __name__ == "__main__": + test_cell_list_in_while_ge() diff --git a/tests/st/ge/run_cell_list_in_while.sh b/tests/st/ge/run_cell_list_in_while.sh new file mode 100644 index 00000000000..9d4062fdb69 --- /dev/null +++ b/tests/st/ge/run_cell_list_in_while.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Copyright 2022 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. +# ============================================================================ +set -e +BASE_PATH=$(cd "$(dirname $0)"; pwd) +rm -rf ${BASE_PATH}/cell_list_in_while +mkdir ${BASE_PATH}/cell_list_in_while +export MS_ENABLE_GE=1 +unset SLOG_PRINT_TO_STDOUT +cd ${BASE_PATH}/cell_list_in_while +echo "start test cell list in while with ge backend" +env > env.log +python ../run_cell_list_in_while.py > test_cell_list_in_while.log 2>&1 & +process_pid=`echo $!` +wait ${process_pid} +unset MS_ENABLE_GE +status=`echo $?` +if [ "${status}" != "0" ]; then + echo "[ERROR] test cell list in while with ge backend failed. status: ${status}" + exit 1 +else + echo "[INFO] test cell list in while with ge backend success." +fi + +exit 0 diff --git a/tests/st/ge/run_while_by_cell_list_in_while.py b/tests/st/ge/run_while_by_cell_list_in_while.py new file mode 100644 index 00000000000..e0f72f2dfd3 --- /dev/null +++ b/tests/st/ge/run_while_by_cell_list_in_while.py @@ -0,0 +1,70 @@ +# Copyright 2022 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. +# ============================================================================ +import mindspore.context as context +from mindspore import Tensor, nn +from mindspore.common import dtype as mstype + +context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") + + +class OneCell(nn.Cell): + def __init__(self, i): + super().__init__() + self.i = i + + def construct(self, x): + return self.i * x + + +class WhileByCellListInWhile(nn.Cell): + def __init__(self): + super().__init__() + self.cell_list = nn.CellList() + self.cell_list.append(OneCell(4)) + self.cell_list.append(OneCell(5)) + self.cell_list.append(OneCell(6)) + + def construct(self, n, x): + out = n + while x < 3: + out += 4 + x += 1 + x = 0 + while x < 3: + add = self.cell_list[x](n) + out = out + add + x += 1 + return out + + +def while_by_cell_list_in_while(): + net = WhileByCellListInWhile() + n = Tensor(10, mstype.int32) + x = Tensor(0, mstype.int32) + out = net(n, x) + return out + + +def test_while_by_cell_list_in_while_ge(): + """ + Feature: Control flow(while and case) implement in ge + Description: run the whole graph sink in ascend in ge backend + Expectation: success + """ + out = while_by_cell_list_in_while() + assert out == Tensor(172, mstype.int32) + +if __name__ == "__main__": + test_while_by_cell_list_in_while_ge() diff --git a/tests/st/ge/run_while_by_cell_list_in_while.sh b/tests/st/ge/run_while_by_cell_list_in_while.sh new file mode 100644 index 00000000000..42b2e934657 --- /dev/null +++ b/tests/st/ge/run_while_by_cell_list_in_while.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Copyright 2022 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. +# ============================================================================ +set -e +BASE_PATH=$(cd "$(dirname $0)"; pwd) +rm -rf ${BASE_PATH}/while_by_cell_list_in_while +mkdir ${BASE_PATH}/while_by_cell_list_in_while +export PYTHONPATH=${BASE_PATH}/:$PYTHONPATH +export MS_ENABLE_GE=1 +unset SLOG_PRINT_TO_STDOUT +cd ${BASE_PATH}/while_by_cell_list_in_while +echo "start test while by cell list in while with ge backend" +env > env.log +python ../run_while_by_cell_list_in_while.py > test_while_by_cell_list_in_while.log 2>&1 & +process_pid=`echo $!` +wait ${process_pid} +unset MS_ENABLE_GE +status=`echo $?` +if [ "${status}" != "0" ]; then + echo "[ERROR] test while by cell list in while with ge backend failed. status: ${status}" + exit 1 +else + echo "[INFO] test while by cell list in while with ge backend success." +fi + +exit 0 diff --git a/tests/st/ge/test_cell_list_in_while.py b/tests/st/ge/test_cell_list_in_while.py new file mode 100644 index 00000000000..f2da9795527 --- /dev/null +++ b/tests/st/ge/test_cell_list_in_while.py @@ -0,0 +1,32 @@ +# Copyright 2022 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. +# ============================================================================ +import os +import pytest + + +@pytest.mark.level0 +@pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.env_onecard +def test_cell_list_in_while(): + """ + Feature: unify ge and vm backend + Description: test cell in list with ge backend + Expectation: success + """ + sh_path = os.path.split(os.path.realpath(__file__))[0] + ret = os.system(f"sh {sh_path}/run_cell_list_in_while.sh") + os.system(f"grep -E 'ERROR|error' {sh_path}/cell_list_in_while/test_cell*log -C 3") + assert ret == 0 diff --git a/tests/st/ge/test_while_by_cell_list_in_while.py b/tests/st/ge/test_while_by_cell_list_in_while.py new file mode 100644 index 00000000000..c926190215a --- /dev/null +++ b/tests/st/ge/test_while_by_cell_list_in_while.py @@ -0,0 +1,32 @@ +# Copyright 2022 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. +# ============================================================================ +import os +import pytest + + +@pytest.mark.level0 +@pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.env_onecard +def test_while_by_cell_list_in_while(): + """ + Feature: unify ge and vm backend + Description: test cell list in while by while with ge backend + Expectation: success + """ + sh_path = os.path.split(os.path.realpath(__file__))[0] + ret = os.system(f"sh {sh_path}/run_while_by_cell_list_in_while.sh") + os.system(f"grep -E 'ERROR|error' {sh_path}/while_by_cell_list_in_while/test_while*log -C 3") + assert ret == 0 diff --git a/tests/ut/ge/run_simple_net.py b/tests/ut/ge/run_simple_net.py new file mode 100644 index 00000000000..c9127361501 --- /dev/null +++ b/tests/ut/ge/run_simple_net.py @@ -0,0 +1,71 @@ +# Copyright 2022 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. +# ============================================================================ +import numpy as np +import mindspore.nn as nn +from mindspore import Tensor +from mindspore import context +from mindspore.ops import operations as P +from mindspore.nn import Cell + +context.set_context(mode=context.GRAPH_MODE) + + +class SeqNet(Cell): + def __init__(self): + super().__init__() + self.op_seq = (P.Sqrt(), P.Reciprocal(), P.Square()) + + def construct(self, x): + t = x + for op in self.op_seq: + t = op(t) + return t + + +def test_op_seq_net_ge(): + """ + Feature: unify ge and vm backend + Description: test op seq with ge backend + Expectation: success + """ + net = SeqNet() + input_np = np.random.randn(2, 3, 4, 5).astype(np.float32) + input_me = Tensor(input_np) + net(input_me) + + +class TriuNet(nn.Cell): + def __init__(self): + super(TriuNet, self).__init__() + self.value = Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) + + def construct(self): + triu = nn.Triu() + return triu(self.value, 0) + + +def test_triu_ge(): + """ + Feature: unify ge and vm backend + Description: test TriuNet with ge backend + Expectation: success + """ + net = TriuNet() + out = net() + assert np.sum(out.asnumpy()) == 26 + +if __name__ == "__main__": + test_op_seq_net_ge() + test_triu_ge() diff --git a/tests/ut/ge/run_simple_net.sh b/tests/ut/ge/run_simple_net.sh new file mode 100644 index 00000000000..5ec04132f00 --- /dev/null +++ b/tests/ut/ge/run_simple_net.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# 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. +# ============================================================================ +set -e +BASE_PATH=$(cd "$(dirname $0)"; pwd) +rm -rf ${BASE_PATH}/simple_net +mkdir ${BASE_PATH}/simple_net +export MS_ENABLE_GE=1 +export MS_GE_TRAIN=0 +echo "start test simple net with ge backend" +cd ${BASE_PATH}/simple_net +env > env.log +python ../run_simple_net.py > test_simple_net.log 2>&1 & +process_pid=`echo $!` +wait ${process_pid} +unset MS_GE_TRAIN +unset MS_ENABLE_GE +status=`echo $?` +if [ "${status}" != "0" ]; then + echo "[ERROR] test simple net with ge backend failed. status: ${status}" + exit 1 +else + echo "[INFO] test simple net with ge backend success." +fi + +exit 0 diff --git a/tests/ut/ge/test_simple_net.py b/tests/ut/ge/test_simple_net.py new file mode 100644 index 00000000000..de6d00990a5 --- /dev/null +++ b/tests/ut/ge/test_simple_net.py @@ -0,0 +1,32 @@ +# Copyright 2022 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. +# ============================================================================ +import os +import pytest + + +@pytest.mark.level0 +@pytest.mark.platform_x86_ascend_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.env_onecard +def test_simple_net(): + """ + Feature: unify ge and vm backend + Description: test some simple net with ge backend + Expectation: success + """ + sh_path = os.path.split(os.path.realpath(__file__))[0] + ret = os.system(f"sh {sh_path}/run_simple_net.sh") + os.system(f"grep -E 'ERROR|error' {sh_path}/simple_net/test_simple*log -C 3") + assert ret == 0 diff --git a/tests/ut/python/nn/test_triu.py b/tests/ut/python/nn/test_triu.py index 70879c5314d..4003416676b 100644 --- a/tests/ut/python/nn/test_triu.py +++ b/tests/ut/python/nn/test_triu.py @@ -15,7 +15,6 @@ """ test nn.Triu() """ -import os import numpy as np import mindspore.nn as nn @@ -43,20 +42,6 @@ def test_triu(): out = net() assert np.sum(out.asnumpy()) == 26 -def test_triu_ge(): - """ - Feature: unify ge and vm backend - Description: test TriuNet with ge backend - Expectation: None - """ - os.environ['MS_ENABLE_GE'] = "1" - os.environ['MS_GE_TRAIN'] = "0" - net = TriuNet() - out = net() - del os.environ['MS_GE_TRAIN'] - del os.environ['MS_ENABLE_GE'] - assert np.sum(out.asnumpy()) == 26 - def test_triu_1(): class Net(nn.Cell): def __init__(self): diff --git a/tests/ut/python/pipeline/parse/test_for_stmt.py b/tests/ut/python/pipeline/parse/test_for_stmt.py index 6ad0cb73b3e..f339d5217ad 100644 --- a/tests/ut/python/pipeline/parse/test_for_stmt.py +++ b/tests/ut/python/pipeline/parse/test_for_stmt.py @@ -13,7 +13,6 @@ # limitations under the License. # ============================================================================ """ test_for_stmt """ -import os import numpy as np from mindspore import Tensor, Model, context, ms_class @@ -92,16 +91,6 @@ def test_op_seq_test(): input_me = Tensor(input_np) net(input_me) -def test_op_seq_test_ge(): - """ - Feature: unify ge and vm backend - Description: test op seq with ge backend - Expectation: None - """ - os.environ['MS_ENABLE_GE'] = "1" - test_op_seq_test() - del os.environ['MS_ENABLE_GE'] - _grad_fusion = C.MultitypeFuncGraph("grad_fushion") @@ -134,13 +123,3 @@ def test_allreduce_fushio_test(): input_np = np.random.randn(2, 3, 4, 5).astype(np.float32) input_me = Tensor(input_np) net(input_me) - -def test_allreduce_fushio_test_ge(): - """ - Feature: unify ge and vm backend - Description: test allreduce fushio with ge backend - Expectation: None - """ - os.environ['MS_ENABLE_GE'] = "1" - test_allreduce_fushio_test() - del os.environ['MS_ENABLE_GE']