"change default backend in debug graph mode and set uni folder for ge

test"
This commit is contained in:
xiao_yao1994 2022-05-16 20:40:24 +08:00
parent f47f97d24b
commit fbdfdb1127
13 changed files with 412 additions and 73 deletions

View File

@ -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']

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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']