forked from mindspore-Ecosystem/mindspore
auto_monad ST use case rectification.
This commit is contained in:
parent
2d9260aefd
commit
a322e5a116
|
@ -30,7 +30,7 @@ from mindspore.ops.primitive import constexpr
|
|||
from capture import Capture, capture, check_output
|
||||
from tests.security_utils import security_off_wrap
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
@pytest.fixture(name="pynative_save_graphs")
|
||||
|
@ -41,16 +41,18 @@ def _pynative_save_graphs():
|
|||
clean_all_ir_files('./')
|
||||
|
||||
|
||||
@pytest.fixture(name="with_save_graphs")
|
||||
def _with_save_graphs():
|
||||
context.set_context(save_graphs=True)
|
||||
yield
|
||||
context.set_context(save_graphs=False)
|
||||
clean_all_ir_files('./')
|
||||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -65,7 +67,8 @@ def test_print():
|
|||
input_x = Tensor(3, dtype=ms.int32)
|
||||
input_y = Tensor(4, dtype=ms.int32)
|
||||
net = Print()
|
||||
net(input_x, input_y)
|
||||
out = net(input_x, input_y)
|
||||
np.testing.assert_array_equal(out.asnumpy(), input_x.asnumpy())
|
||||
time.sleep(0.1)
|
||||
|
||||
patterns = {'input_x:\nTensor(shape=[], dtype=Int32, value=3)\n'
|
||||
|
@ -74,7 +77,17 @@ def test_print():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_add():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_Add(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -102,7 +115,17 @@ def test_print_add():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_assign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print and assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_Assign(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -130,7 +153,17 @@ def test_print_assign():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_assign_add():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_Assign_Add(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -161,7 +194,17 @@ def test_print_assign_add():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_while():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_While(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -196,7 +239,17 @@ def test_print_while():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_If(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -227,7 +280,17 @@ def test_print_if():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_assign_while():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print and assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_Assign_While(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -271,7 +334,17 @@ def test_print_assign_while():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_assign_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print and assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_Assign_If(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -309,10 +382,16 @@ def test_print_assign_if():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -330,10 +409,16 @@ def test_assign():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_implicit():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_Implicit(Cell):
|
||||
def __init__(self):
|
||||
super(Assign_Implicit, self).__init__()
|
||||
|
@ -351,10 +436,16 @@ def test_assign_implicit():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_write_after_read():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_WAR(Cell):
|
||||
def __init__(self):
|
||||
super(Assign_WAR, self).__init__()
|
||||
|
@ -380,10 +471,16 @@ def test_assign_write_after_read():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_read_after_write():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator assign_add.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_RAW(Cell):
|
||||
def __init__(self):
|
||||
super(Assign_RAW, self).__init__()
|
||||
|
@ -409,10 +506,16 @@ def test_assign_read_after_write():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_If(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -434,10 +537,16 @@ def test_assign_if():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class If(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -460,10 +569,16 @@ def test_if():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_while():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect with control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class While(Cell):
|
||||
def construct(self, x, y):
|
||||
y = y + 4
|
||||
|
@ -481,10 +596,16 @@ def test_while():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_while():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect with control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_While(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -507,10 +628,16 @@ def test_assign_while():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_for():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect with control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class For(Cell):
|
||||
def construct(self, x, y):
|
||||
y = x + y
|
||||
|
@ -527,7 +654,17 @@ def test_for():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_for():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_For(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -564,7 +701,17 @@ def test_print_for():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_assign_for():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print and assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Print_Assign_For(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -609,10 +756,16 @@ def test_print_assign_for():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_for():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the side effect operator print and assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_For(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -640,10 +793,16 @@ def _check_shape(shape):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_constexpr_check():
|
||||
"""
|
||||
Feature: Verify shape operation.
|
||||
Description: Verify shape operation.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class ConstexprCheck(Cell):
|
||||
def __init__(self):
|
||||
super(ConstexprCheck, self).__init__()
|
||||
|
@ -670,10 +829,16 @@ def test_constexpr_check():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_if_lambda():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify lambda in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class If_Lambda(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -696,10 +861,16 @@ def test_if_lambda():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_multi_assign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify multi assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Multi_Assign(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -724,10 +895,16 @@ def test_multi_assign():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_multi_assign_addn():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify multi assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Multi_Assign_Addn(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -751,16 +928,25 @@ def test_multi_assign_addn():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_multi_assign_print():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify multi assign and print.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Multi_Assign_Print(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.pow = P.Pow()
|
||||
self.print = P.Print()
|
||||
self.assign = P.Assign()
|
||||
self.exponent = Tensor([2.0], ms.float32)
|
||||
self.para1 = Parameter(Tensor(1.0, dtype=ms.float32), name='para1')
|
||||
self.para2 = Parameter(Tensor(3.0, dtype=ms.float32), name='para2')
|
||||
self.exponent = Tensor([2], ms.int32)
|
||||
self.para1 = Parameter(Tensor(1, dtype=ms.int32), name='para1')
|
||||
self.para2 = Parameter(Tensor(3, dtype=ms.int32), name='para2')
|
||||
|
||||
def construct(self, inputs):
|
||||
self.assign(self.para1, inputs)
|
||||
|
@ -770,24 +956,37 @@ def test_multi_assign_print():
|
|||
self.print(self.para2)
|
||||
return inputs
|
||||
|
||||
x = Tensor(9.0, dtype=ms.float32)
|
||||
expect = Tensor(9.0, dtype=ms.float32)
|
||||
expect_para1 = Tensor(9.0, dtype=ms.float32)
|
||||
expect_para2 = Tensor(81.00001, dtype=ms.float32)
|
||||
net = Multi_Assign_Print()
|
||||
out = net(x)
|
||||
np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy())
|
||||
np.testing.assert_almost_equal(
|
||||
net.para1.data.asnumpy(), expect_para1.asnumpy())
|
||||
np.testing.assert_almost_equal(
|
||||
net.para2.data.asnumpy(), expect_para2.asnumpy())
|
||||
cap = Capture()
|
||||
with capture(cap):
|
||||
x = Tensor(9, dtype=ms.int32)
|
||||
expect = Tensor(9, dtype=ms.int32)
|
||||
expect_para1 = Tensor(9, dtype=ms.int32)
|
||||
expect_para2 = Tensor(81, dtype=ms.int32)
|
||||
net = Multi_Assign_Print()
|
||||
out = net(x)
|
||||
np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy())
|
||||
np.testing.assert_almost_equal(
|
||||
net.para1.data.asnumpy(), expect_para1.asnumpy())
|
||||
np.testing.assert_almost_equal(
|
||||
net.para2.data.asnumpy(), expect_para2.asnumpy())
|
||||
|
||||
patterns = {'Tensor(shape=[], dtype=Int32, value=9)\n\n'
|
||||
'Tensor(shape=[], dtype=Int32, value=9)\n\n'
|
||||
'Tensor(shape=[], dtype=Int32, value=81)\n\n'}
|
||||
check_output(cap.output, patterns)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_matmul_assign_biasadd():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify multi assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Matmul_Assign_Biasadd(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -821,10 +1020,16 @@ def test_matmul_assign_biasadd():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_while_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign and assign_sub in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Assign_While_If(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -855,10 +1060,16 @@ def test_assign_while_if():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_isolate_call():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign and assign_sub in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -887,10 +1098,16 @@ def test_isolate_call():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_return_true():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super(Net, self).__init__()
|
||||
|
@ -921,10 +1138,16 @@ def test_assign_return_true():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_unpack_call():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign in unpack call.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class SetPara(Cell):
|
||||
def __init__(self, para):
|
||||
super(SetPara, self).__init__()
|
||||
|
@ -958,10 +1181,16 @@ def test_unpack_call():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_tuple_of_tuple():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign tuple in unpack call.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class SetPara(Cell):
|
||||
def __init__(self, para):
|
||||
super(SetPara, self).__init__()
|
||||
|
@ -997,10 +1226,16 @@ def test_tuple_of_tuple():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_write_read_write():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class MyNet(Cell):
|
||||
def __init__(self):
|
||||
super(MyNet, self).__init__()
|
||||
|
@ -1026,10 +1261,16 @@ def test_write_read_write():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_variable_from_outer_graph():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class MyNet(Cell):
|
||||
def __init__(self):
|
||||
super(MyNet, self).__init__()
|
||||
|
@ -1055,16 +1296,21 @@ def test_variable_from_outer_graph():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_ctrl_while_by_while_and_if_in_first_while():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = P.ReLU()
|
||||
self.sigmoid = P.Sigmoid()
|
||||
self.tanh = P.Tanh()
|
||||
self.add = P.Add()
|
||||
a = np.full((1,), 5, dtype=np.float32)
|
||||
self.a = Parameter(Tensor(a), name="a")
|
||||
|
@ -1088,20 +1334,30 @@ def test_ctrl_while_by_while_and_if_in_first_while():
|
|||
input_np_a = np.random.randn(2, 3, 4, 5).astype(np.float32)
|
||||
input_me_a = Tensor(input_np_a)
|
||||
net = Net()
|
||||
net(input_me_a)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net(input_me_a)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net(input_me_a)
|
||||
assert graph_out == pynative_out
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_ctrl_if_by_while_and_while_in_first_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = P.ReLU()
|
||||
self.sigmoid = P.Sigmoid()
|
||||
self.tanh = P.Tanh()
|
||||
self.add = P.Add()
|
||||
a = np.full((1,), 5, dtype=np.float32)
|
||||
self.a = Parameter(Tensor(a), name="a")
|
||||
|
@ -1116,30 +1372,38 @@ def test_ctrl_if_by_while_and_while_in_first_if():
|
|||
out = self.relu(x)
|
||||
while self.a < 7:
|
||||
self.a += 1
|
||||
|
||||
while self.c > 5:
|
||||
out = self.add(out, out)
|
||||
self.c -= 1
|
||||
return out
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
input_np_a = np.random.randn(2, 3, 4, 5).astype(np.float32)
|
||||
input_me_a = Tensor(input_np_a)
|
||||
net = Net()
|
||||
net(input_me_a)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net(input_me_a)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net(input_me_a)
|
||||
assert graph_out == pynative_out
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_ctrl_while_by_while_and_while_in_first_while():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = P.ReLU()
|
||||
self.sigmoid = P.Sigmoid()
|
||||
self.tanh = P.Tanh()
|
||||
self.add = P.Add()
|
||||
a = np.full((1,), 5, dtype=np.float32)
|
||||
self.a = Parameter(Tensor(a), name="a")
|
||||
|
@ -1155,58 +1419,20 @@ def test_ctrl_while_by_while_and_while_in_first_while():
|
|||
while self.b > 1:
|
||||
self.b -= 1
|
||||
self.a += 1
|
||||
|
||||
while self.c > 5:
|
||||
out = self.add(out, out)
|
||||
self.c -= 1
|
||||
return out
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
input_np_a = np.random.randn(2, 3, 4, 5).astype(np.float32)
|
||||
input_me_a = Tensor(input_np_a)
|
||||
net = Net()
|
||||
net(input_me_a)
|
||||
|
||||
|
||||
def clear_json_info():
|
||||
os.system("rm -rf ./kernel_meta/*.json")
|
||||
os.system("rm -rf ./kernel_meta/*.info")
|
||||
|
||||
|
||||
def find_json_info(file):
|
||||
result = os.system("ls -al ./kernel_meta/%s" % (file))
|
||||
return result
|
||||
|
||||
|
||||
class MultiOutReluBywaySqrt(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = nn.ReLU()
|
||||
self.sqrt = P.Sqrt()
|
||||
|
||||
def construct(self, x):
|
||||
x = self.relu(x)
|
||||
x = self.relu(x)
|
||||
x1 = self.relu(x)
|
||||
x = self.relu(x1)
|
||||
y = self.sqrt(x1)
|
||||
return x, y
|
||||
|
||||
|
||||
class MultiOutReluSqrtBywaySqrt(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = nn.ReLU()
|
||||
self.sqrt = P.Sqrt()
|
||||
self.sin = P.Sin()
|
||||
|
||||
def construct(self, x):
|
||||
x = self.relu(x)
|
||||
x = self.sqrt(x)
|
||||
x1 = self.relu(x)
|
||||
x = self.sin(x1)
|
||||
y = self.sqrt(x1)
|
||||
return x, y
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net(input_me_a)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net(input_me_a)
|
||||
assert graph_out == pynative_out
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
def clean_all_ir_files(folder_path):
|
||||
|
@ -1282,7 +1508,17 @@ class AssignNet(Cell):
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_mixed_precision_train_1(pynative_save_graphs):
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify mixed precision.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = AssignNet()
|
||||
input32 = Tensor(np.ones([1, 3, 2, 2]).astype(np.float32))
|
||||
label32 = Tensor(np.zeros([1, 3]).astype(np.float32))
|
||||
|
@ -1290,7 +1526,17 @@ def test_auto_mixed_precision_train_1(pynative_save_graphs):
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_mixed_precision_train_2(pynative_save_graphs):
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify mixed precision.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = AssignNet()
|
||||
input32 = Tensor(np.ones([1, 3, 2, 2]).astype(np.float32))
|
||||
label32 = Tensor(np.zeros([1, 3]).astype(np.float32))
|
||||
|
@ -1368,7 +1614,17 @@ def use_build_train_network_controlflow_check_cast_num(network, level, input_x,
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_mixed_precision_controlflow_auto(pynative_save_graphs):
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify mixed precision in control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = MixControlNet(3, 5)
|
||||
input_x = Tensor(
|
||||
np.random.randint(2, size=(1, 3, 2, 2)).astype((np.float32)))
|
||||
|
@ -1384,10 +1640,16 @@ def test_auto_mixed_precision_controlflow_auto(pynative_save_graphs):
|
|||
# op_cast should be located in order_list after abstract_specialize.
|
||||
# Besides Ascend, it can work on CPU.
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_if_cast():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(nn.Cell):
|
||||
def __init__(self, cond1):
|
||||
super().__init__()
|
||||
|
@ -1414,10 +1676,16 @@ def test_if_cast():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_while_forward():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class MyWhileNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -1441,10 +1709,16 @@ def test_while_forward():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_multi_add_assign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self, i1):
|
||||
super(Net, self).__init__()
|
||||
|
@ -1481,10 +1755,16 @@ def test_multi_add_assign():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_multi_abs_add_assign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class Net(Cell):
|
||||
def __init__(self, para):
|
||||
super(Net, self).__init__()
|
||||
|
@ -1524,6 +1804,10 @@ def test_multi_abs_add_assign():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_print_assign_print():
|
||||
"""
|
||||
Feature: Auto Monad
|
||||
|
|
|
@ -61,10 +61,16 @@ def allclose_nparray(data_expected, data_me, rtol, atol, equal_nan=True):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_monad_addn_adam():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the optimizer operator adam.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3, 3).astype(np.float32))
|
||||
m = Tensor(np.random.rand(3, 3, 3).astype(np.float32))
|
||||
v = Tensor(np.random.rand(3, 3, 3).astype(np.float32))
|
||||
|
@ -116,10 +122,16 @@ class AutoMonadTwoAssignTwoAddnDependencyBenchmarkNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_monad_read_dependency_two_assign_two_addn():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify the effect operator assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = AutoMonadTwoAssignTwoAddnDependencyNet()
|
||||
benchmarknet = AutoMonadTwoAssignTwoAddnDependencyBenchmarkNet()
|
||||
out1 = net(Tensor([9.0], ms.float32))
|
||||
|
@ -154,6 +166,7 @@ class BackwardNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -187,6 +200,7 @@ class ForwardNet2(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -202,6 +216,7 @@ def test_load_convert_tensormove_2():
|
|||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -232,6 +247,7 @@ def test_load_eliminate():
|
|||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
|
@ -393,6 +409,7 @@ def test_parameter_tuple_assign_addn_inner_net_control_flow():
|
|||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_parameter_value_control_flow_ascend():
|
||||
"""
|
||||
|
@ -410,8 +427,8 @@ def test_parameter_value_control_flow_ascend():
|
|||
|
||||
def construct(self, x):
|
||||
if x > 0:
|
||||
return self.param1.value(), self.tensor1.value()
|
||||
return self.param2.value(), self.tensor2.value()
|
||||
return self.param1.value(), self.tensor1
|
||||
return self.param2.value(), self.tensor2
|
||||
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
|
|
|
@ -31,7 +31,7 @@ from mindspore.common.parameter import Parameter
|
|||
from mindspore.ops.composite import GradOperation
|
||||
from tests.security_utils import security_off_wrap
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class _Grad(Cell):
|
||||
|
@ -58,16 +58,6 @@ class _Grad(Cell):
|
|||
return self.grad(self.network)(*real_inputs, sense_param_inputs)
|
||||
|
||||
|
||||
class GradOfAllInputs(_Grad):
|
||||
'''
|
||||
get grads of all inputs
|
||||
'''
|
||||
|
||||
def __init__(self, network, sens_param=True, real_inputs_count=None):
|
||||
super().__init__(grad=GradOperation(get_all=True, sens_param=sens_param),
|
||||
network=network, real_inputs_count=real_inputs_count)
|
||||
|
||||
|
||||
class GradOfAllInputsAndParams(_Grad):
|
||||
'''
|
||||
get grads of all inputs and params
|
||||
|
@ -132,7 +122,16 @@ class SideEffectCastAll(Cell):
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_side_effect_castall():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify cast all fusion.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
clear_files()
|
||||
context.set_context(mode=context.GRAPH_MODE, save_graphs=True)
|
||||
net = SideEffectCastAll()
|
||||
|
@ -170,6 +169,11 @@ class SideEffectControlFlowAssignDependWhileNet(Cell):
|
|||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_control_flow_assign_depend_while_net():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectControlFlowAssignDependWhileNet()
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
out1 = net(Tensor([9.0], ms.float32), Tensor(
|
||||
|
@ -181,128 +185,6 @@ def test_side_effect_control_flow_assign_depend_while_net():
|
|||
allclose_nparray(out1.asnumpy(), out2.asnumpy(), 0.001, 0.001)
|
||||
|
||||
|
||||
class Addn(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.parameter3 = Parameter(Tensor([1.0], ms.float32),
|
||||
name="parameter3")
|
||||
self.parameter4 = Parameter(Tensor([3.0], ms.float32),
|
||||
name="parameter4")
|
||||
self.addn = P.AddN()
|
||||
|
||||
def construct(self, inputs):
|
||||
out = self.addn((inputs, self.parameter3, self.parameter4))
|
||||
return out
|
||||
|
||||
|
||||
class Relu(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = P.ReLU()
|
||||
|
||||
def construct(self, inputs):
|
||||
out = self.relu(inputs)
|
||||
return out
|
||||
|
||||
|
||||
class SideEffectTwoAssignTwoAddnDependencyNet(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.parameter1 = Parameter(Tensor([1.0], ms.float32),
|
||||
name="parameter1")
|
||||
self.parameter2 = Parameter(Tensor([3.0], ms.float32),
|
||||
name="parameter2")
|
||||
self.assign = P.Assign()
|
||||
self.addN = P.AddN()
|
||||
|
||||
def construct(self, inputs):
|
||||
self.assign(self.parameter1, inputs)
|
||||
out = self.addN((inputs, self.parameter1, self.parameter2))
|
||||
self.assign(self.parameter2, inputs)
|
||||
out = self.addN((out, self.parameter1, self.parameter2))
|
||||
return out
|
||||
|
||||
def grad_mindspore_impl(self, params, grad_ys):
|
||||
grad_net = GradOfAllInputsAndParams(self)
|
||||
grad_net.set_train()
|
||||
grad_out = grad_net(params, grad_ys)
|
||||
return grad_out
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_while_by_while_and_if_in_first_while():
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = P.ReLU()
|
||||
self.sigmoid = P.Sigmoid()
|
||||
self.tanh = P.Tanh()
|
||||
self.add = P.Add()
|
||||
a = np.full((1,), 5, dtype=np.float32)
|
||||
self.a = Parameter(Tensor(a), name="a")
|
||||
b = np.full((1,), 4, dtype=np.float32)
|
||||
self.b = Parameter(Tensor(b), name="b")
|
||||
c = np.full((1,), 7, dtype=np.float32)
|
||||
self.c = Parameter(Tensor(c), name="c")
|
||||
|
||||
def construct(self, x):
|
||||
out = x
|
||||
while self.a < 7:
|
||||
if self.a < self.c:
|
||||
out = self.relu(x)
|
||||
self.a += 1
|
||||
while self.c > 5:
|
||||
out = self.add(out, out)
|
||||
self.c -= 1
|
||||
return out
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
input_np_a = np.random.randn(2, 3, 4, 5).astype(np.float32)
|
||||
input_me_a = Tensor(input_np_a)
|
||||
net = Net()
|
||||
net(input_me_a)
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_while_by_while_and_while_in_first_while():
|
||||
class Net(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.relu = P.ReLU()
|
||||
self.sigmoid = P.Sigmoid()
|
||||
self.tanh = P.Tanh()
|
||||
self.add = P.Add()
|
||||
a = np.full((1,), 5, dtype=np.float32)
|
||||
self.a = Parameter(Tensor(a), name="a")
|
||||
b = np.full((1,), 4, dtype=np.float32)
|
||||
self.b = Parameter(Tensor(b), name="b")
|
||||
c = np.full((1,), 7, dtype=np.float32)
|
||||
self.c = Parameter(Tensor(c), name="c")
|
||||
|
||||
def construct(self, x):
|
||||
out = x
|
||||
while self.a < self.c:
|
||||
out = self.relu(x)
|
||||
while self.b > 1:
|
||||
self.b -= 1
|
||||
self.a += 1
|
||||
|
||||
while self.c > 5:
|
||||
out = self.add(out, out)
|
||||
self.c -= 1
|
||||
return out
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
input_np_a = np.random.randn(2, 3, 4, 5).astype(np.float32)
|
||||
input_me_a = Tensor(input_np_a)
|
||||
net = Net()
|
||||
net(input_me_a)
|
||||
|
||||
|
||||
class InplaceNet(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -338,7 +220,16 @@ class InplaceNet(Cell):
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_ir_fusion_inplace_bn_conv_conv():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ir fusion.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
clear_files()
|
||||
context.set_context(mode=context.GRAPH_MODE, save_graphs=True)
|
||||
input_np = np.random.uniform(0.0, 255.0,
|
||||
|
@ -383,15 +274,6 @@ def read_file():
|
|||
return content
|
||||
|
||||
|
||||
class Add(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.add = P.Add()
|
||||
|
||||
def construct(self, x, y):
|
||||
return self.add(x, y)
|
||||
|
||||
|
||||
class MixControlNet(Cell):
|
||||
def __init__(self, in_channel, x):
|
||||
super().__init__()
|
||||
|
@ -464,7 +346,17 @@ def use_build_train_network_controlflow_check_cast_num(network, level, input_x,
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_mixed_precision_controlflow_auto():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
context.set_context(mode=context.PYNATIVE_MODE, save_graphs=True)
|
||||
net = MixControlNet(3, 5)
|
||||
input_x = Tensor(
|
||||
|
@ -479,7 +371,15 @@ def test_auto_mixed_precision_controlflow_auto():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_updatestate_between_assigns():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify updatestate eliminate.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class UpdateState_Assigns(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -505,7 +405,16 @@ def test_updatestate_between_assigns():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_updatestate_between_maketuple_assign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify updatestate eliminate.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class UpdateState_MakeTuple_Assign(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
@ -533,7 +442,16 @@ def test_updatestate_between_maketuple_assign():
|
|||
|
||||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.skip(reason="No support")
|
||||
def test_updatestate_between_assign_maketuple():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify updatestate eliminate.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class UpdateState_Assign_MakeTuple(Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2021 Huawei Technologies Co., Ltd
|
||||
# Copyright 2021-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.
|
||||
|
@ -12,6 +12,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
import pytest
|
||||
from tqdm import tqdm
|
||||
import numpy as np
|
||||
import mindspore as ms
|
||||
|
@ -19,7 +20,7 @@ import mindspore.nn as nn
|
|||
from mindspore.dataset import NumpySlicesDataset
|
||||
from mindspore import context, Tensor
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
class AutoEncoderTrainNetwork(nn.Cell):
|
||||
def __init__(self):
|
||||
|
@ -59,7 +60,17 @@ class AutoEncoderTrainNetwork(nn.Cell):
|
|||
return transformed_dataset
|
||||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_auto_monad_layer():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify auto monad feature.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
ae_with_loss = AutoEncoderTrainNetwork()
|
||||
transformed_dataset = ae_with_loss.create_synthetic_dataset()
|
||||
dataloader = NumpySlicesDataset(data=(transformed_dataset,), shuffle=True)
|
||||
|
|
|
@ -124,10 +124,16 @@ class ControlGraphSupportNotEqual(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_if_while_graph_support_not_equal_true():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
x = np.array(0).astype(np.float32)
|
||||
y = np.array(3).astype(np.float32)
|
||||
input_shape = (512, 512, 7, 7)
|
||||
|
@ -144,10 +150,16 @@ def test_ctrl_if_while_graph_support_not_equal_true():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_if_while_graph_support_not_equal_false():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
x = np.array(0).astype(np.float32)
|
||||
y = np.array(0).astype(np.float32)
|
||||
z = np.array(3).astype(np.float32)
|
||||
|
@ -187,10 +199,16 @@ class ControlBprop(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_if_while_bprop_true():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
x = np.array(0).astype(np.float32)
|
||||
y = np.array(3).astype(np.float32)
|
||||
input_shape = (512, 512, 7, 7)
|
||||
|
@ -238,10 +256,16 @@ class InlineBpropTwoInput1(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_if_while_bprop_inlinebprop_twoinput():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = InlineBpropTwoInput1()
|
||||
input1 = Tensor(np.array(2).astype(np.float32))
|
||||
input2 = Tensor(np.array(1).astype(np.float32))
|
||||
|
@ -272,10 +296,16 @@ class ControlOneIfOneParaOneAddn(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_ctrl_if_para_addn_true():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
x = Tensor(1, ms.float32)
|
||||
y = Tensor(0, ms.float32)
|
||||
input_shape = (1024, 512, 7, 7)
|
||||
|
@ -317,14 +347,26 @@ class SideEffectMemoryCellAddnNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_grad_memory_addn():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectMemoryCellAddnNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs = Tensor([9.0], ms.float32)
|
||||
net.grad_mindspore_impl(inputs, grad_ys)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
allclose_nparray(graph_out[0][0].asnumpy(), pynative_out[0][0].asnumpy(), 0.0001, 0.0001)
|
||||
allclose_nparray(graph_out[1][0].asnumpy(), pynative_out[1][0].asnumpy(), 0.0001, 0.0001)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class SideEffectIOCellAddnNet(Cell):
|
||||
|
@ -350,14 +392,26 @@ class SideEffectIOCellAddnNet(Cell):
|
|||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_grad_io_addn():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectIOCellAddnNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs = Tensor([9.0], ms.float32)
|
||||
net.grad_mindspore_impl(inputs, grad_ys)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
allclose_nparray(graph_out[0][0].asnumpy(), pynative_out[0][0].asnumpy(), 0.0001, 0.0001)
|
||||
allclose_nparray(graph_out[1][0].asnumpy(), pynative_out[1][0].asnumpy(), 0.0001, 0.0001)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class SideEffectReturnParameterNet(Cell):
|
||||
|
@ -383,14 +437,26 @@ class SideEffectReturnParameterNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_grad_read_dependency_return_parameter():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify parameter.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectReturnParameterNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs = Tensor([9.0], ms.float32)
|
||||
net.grad_mindspore_impl(inputs, grad_ys)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
allclose_nparray(graph_out[0][0].asnumpy(), pynative_out[0][0].asnumpy(), 0.0001, 0.0001)
|
||||
allclose_nparray(graph_out[1][0].asnumpy(), pynative_out[1][0].asnumpy(), 0.0001, 0.0001)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class SideEffectAssignAddnReluReturnParNet(Cell):
|
||||
|
@ -417,10 +483,16 @@ class SideEffectAssignAddnReluReturnParNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_grad_read_dependency_assign_addn_relu_return_parameter():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify parameter.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectAssignAddnReluReturnParNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs = Tensor([9.0], ms.float32)
|
||||
|
@ -466,10 +538,16 @@ class SideEffectPrintInHighOrdeAddnNet(Cell):
|
|||
|
||||
@security_off_wrap
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_high_order_print_in_high_order_net():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify high order net.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
print_file = os.getcwd() + "/test_side_effect_high_order_print_in_high_order_net.data"
|
||||
context.set_context(print_file_path=print_file)
|
||||
net = SideEffectPrintInHighOrdeAddnNet()
|
||||
|
@ -513,15 +591,29 @@ class SideEffectControlFlowAssignDependTwoIfNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_grad_control_flow_assign_depend_of_two_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectControlFlowAssignDependTwoIfNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs1 = Tensor([9.0], ms.float32)
|
||||
inputs2 = Tensor([6.0], ms.float32)
|
||||
net.grad_mindspore_impl(inputs1, inputs2, grad_ys)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
graph_out = net.grad_mindspore_impl(inputs1, inputs2, grad_ys)
|
||||
context.set_context(mode=context.PYNATIVE_MODE)
|
||||
pynative_out = net.grad_mindspore_impl(inputs1, inputs2, grad_ys)
|
||||
allclose_nparray(graph_out[0][0].asnumpy(), pynative_out[0][0].asnumpy(), 0.0001, 0.0001)
|
||||
allclose_nparray(graph_out[0][1].asnumpy(), pynative_out[0][1].asnumpy(), 0.0001, 0.0001)
|
||||
allclose_nparray(graph_out[1][0].asnumpy(), pynative_out[1][0].asnumpy(), 0.0001, 0.0001)
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class SideEffectTwoAddnSwitchNet(Cell):
|
||||
|
@ -545,15 +637,20 @@ class SideEffectTwoAddnSwitchNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_grad_two_addn_switch():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = SideEffectTwoAddnSwitchNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs = Tensor([9.0], ms.float32)
|
||||
out1 = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
net = SideEffectTwoAddnSwitchNet()
|
||||
try:
|
||||
expect = 54.0
|
||||
allclose_nparray(out1[0][0].asnumpy(), expect, 0.001, 0.001)
|
||||
|
@ -586,16 +683,21 @@ class SideEffectGradIfNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_grad_if():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
net = SideEffectGradIfNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
inputs = Tensor([9.0], ms.float32)
|
||||
out1 = net.grad_mindspore_impl(inputs, grad_ys)
|
||||
net = SideEffectGradIfNet()
|
||||
try:
|
||||
expect = 18.0
|
||||
allclose_nparray(out1.asnumpy(), expect, 0.001, 0.001)
|
||||
|
@ -630,10 +732,16 @@ class HighGrad(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_highgrad_one_input_sec_grad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify high grad.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = OneInputBprop()
|
||||
x = Tensor(np.array([2, 2]).astype(np.float32))
|
||||
grad_net = HighGrad(net, [GradOfFirstInput, GradOfFirstInput])
|
||||
|
@ -642,10 +750,16 @@ def test_highgrad_one_input_sec_grad():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_highgrad_one_input_third_grad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify high grad.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
net = OneInputBprop()
|
||||
x = Tensor(np.array([2, 2]).astype(np.float32))
|
||||
grad_net = HighGrad(
|
||||
|
@ -681,10 +795,16 @@ class SideEffectControlFlowAssignDependWhileNet(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_side_effect_grad_control_flow_assign_depend_while_net():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify control flow.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
net = SideEffectControlFlowAssignDependWhileNet()
|
||||
grad_ys = Tensor([18.0], ms.float32)
|
||||
|
@ -724,8 +844,9 @@ class AssignInZipLoop(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_in_zip_loop():
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2019 Huawei Technologies Co., Ltd
|
||||
# Copyright 2019-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.
|
||||
|
@ -25,7 +25,7 @@ from mindspore.nn.wrap.loss_scale import TrainOneStepWithLossScaleCell
|
|||
from mindspore.ops import functional as F
|
||||
from mindspore.common import dtype as mstype
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class Net(Cell):
|
||||
|
@ -62,10 +62,16 @@ class MSELoss(Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_momentum_loss():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify momentum loss.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
inputs = Tensor(np.ones([15, 1]).astype(np.float32))
|
||||
label = Tensor(np.zeros([15, 1]).astype(np.float32))
|
||||
net = Net(1, 1)
|
||||
|
@ -76,4 +82,6 @@ def test_momentum_loss():
|
|||
scale_sense=Tensor(np.full((1), 1.0), dtype=mstype.float32))
|
||||
train_network.set_train()
|
||||
output = train_network(inputs, label)
|
||||
print("the result is ", output)
|
||||
assert output[0].asnumpy() == 4
|
||||
assert str(output[1].asnumpy()) == "False"
|
||||
assert output[2].asnumpy() == 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-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.
|
||||
|
@ -26,7 +26,7 @@ from mindspore.train.summary.summary_record import SummaryRecord
|
|||
from tests.summary_utils import SummaryReader
|
||||
from tests.security_utils import security_off_wrap
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class AssignAddNet(nn.Cell):
|
||||
|
@ -41,10 +41,16 @@ class AssignAddNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_add():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign_add.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
x = Tensor(1, dtype=mstype.int32)
|
||||
y = Tensor(2, dtype=mstype.int32)
|
||||
expect = Tensor(3, dtype=mstype.int32)
|
||||
|
@ -65,10 +71,16 @@ class AssignSubNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_assign_sub():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify assign_sub.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
x = Tensor(3, dtype=mstype.int32)
|
||||
y = Tensor(2, dtype=mstype.int32)
|
||||
expect = Tensor(1, dtype=mstype.int32)
|
||||
|
@ -89,10 +101,16 @@ class ScatterAddNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_add():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_add.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 1], [1, 1]]), mstype.int32)
|
||||
updates = Tensor(np.ones([2, 2, 3]), mstype.float32)
|
||||
|
@ -114,10 +132,16 @@ class ScatterSubNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_sub():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_sub.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 1]]), mstype.int32)
|
||||
updates = Tensor(np.array([[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]]]), mstype.float32)
|
||||
|
@ -139,10 +163,16 @@ class ScatterMulNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_mul():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_mul.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 1]]), mstype.int32)
|
||||
updates = Tensor(np.array([[[2.0, 2.0, 2.0], [2.0, 2.0, 2.0]]]), mstype.float32)
|
||||
|
@ -164,10 +194,16 @@ class ScatterDivNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_div():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_div.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[6.0, 6.0, 6.0], [2.0, 2.0, 2.0]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 1]]), mstype.int32)
|
||||
updates = Tensor(np.array([[[2.0, 2.0, 2.0], [2.0, 2.0, 2.0]]]), mstype.float32)
|
||||
|
@ -189,10 +225,16 @@ class ScatterMaxNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_max():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_max.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 0], [1, 1]]), mstype.int32)
|
||||
updates = Tensor(np.ones([2, 2, 3]) * 88, mstype.float32)
|
||||
|
@ -214,10 +256,16 @@ class ScatterMinNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_min():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_min.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[0.0, 1.0, 2.0], [0.0, 0.0, 0.0]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 0], [1, 1]]), mstype.int32)
|
||||
updates = Tensor(np.ones([2, 2, 3]), mstype.float32)
|
||||
|
@ -243,6 +291,12 @@ class ScatterUpdateNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_update():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_update.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 0], [1, 1]]), mstype.int32)
|
||||
updates = Tensor(np.array([[[1.0, 2.2, 1.0], [2.0, 1.2, 1.0]], [[2.0, 2.2, 1.0], [3.0, 1.2, 1.0]]]), mstype.float32)
|
||||
|
@ -264,10 +318,16 @@ class ScatterNdAddNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_nd_add():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_nd_add.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8]), mstype.float32)
|
||||
indices = Tensor(np.array([[2], [4], [1], [7]]), mstype.int32)
|
||||
updates = Tensor(np.array([6, 7, 8, 9]), mstype.float32)
|
||||
|
@ -289,10 +349,16 @@ class ScatterNdSubNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_nd_sub():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_nd_sub.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8]), mstype.float32)
|
||||
indices = Tensor(np.array([[2], [4], [1], [7]]), mstype.int32)
|
||||
updates = Tensor(np.array([6, 7, 8, 9]), mstype.float32)
|
||||
|
@ -314,10 +380,16 @@ class ScatterNdUpdateNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_nd_update():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_nd_update.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mstype.float32)
|
||||
indices = Tensor(np.array([[0, 0], [1, 1]]), mstype.int32)
|
||||
updates = Tensor(np.array([1.0, 2.2]), mstype.float32)
|
||||
|
@ -343,6 +415,12 @@ class ScatterNonAliasingAddNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_scatter_non_aliasing_add():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify scatter_non_aliasing_add.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
input_x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8]), mstype.float32)
|
||||
indices = Tensor(np.array([[2], [4], [1], [7]]), mstype.int32)
|
||||
updates = Tensor(np.array([6, 7, 8, 9]), mstype.float32)
|
||||
|
@ -382,11 +460,17 @@ def train_summary_record(test_writer, steps):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
@security_off_wrap
|
||||
def test_summary():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify summary operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
steps = 2
|
||||
with SummaryRecord(tmp_dir) as test_writer:
|
||||
|
@ -401,10 +485,16 @@ def test_summary():
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_igamma():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify igamma operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
class IGammaTest(nn.Cell):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-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.
|
||||
|
@ -20,7 +20,7 @@ from mindspore.ops import operations as P
|
|||
from mindspore.common import dtype as mstype
|
||||
from mindspore.common.parameter import Parameter
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
class AdamNet(nn.Cell):
|
||||
|
@ -38,10 +38,16 @@ class AdamNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_adam():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify Adam operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.ones([3, 3, 3]).astype(np.float32))
|
||||
m = Tensor(np.ones([3, 3, 3]).astype(np.float32))
|
||||
v = Tensor(np.ones([3, 3, 3]).astype(np.float32))
|
||||
|
@ -75,10 +81,16 @@ class ApplyAdaMaxNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_ada_max():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyAdaMax operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
m = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
v = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
|
@ -110,10 +122,16 @@ class ApplyAdadeltaNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_adadelta():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyAdadelta operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum_update = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
|
@ -141,10 +159,16 @@ class ApplyAdagrad(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_adagrad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyAdagrad operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyAdagrad(var, accum)
|
||||
|
@ -169,10 +193,16 @@ class ApplyAdagradV2Net(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_adagrad_v2():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyAdagradV2 operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyAdagradV2Net(var, accum)
|
||||
|
@ -198,10 +228,16 @@ class ApplyAddSignNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_add_sign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyAddSign operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
m = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyAddSignNet(var, m)
|
||||
|
@ -229,10 +265,16 @@ class ApplyCenteredRMSPropNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_centered_rms_prop():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyCenteredRMSProp operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(
|
||||
np.arange(-6, 6).astype(np.float32).reshape(2, 3, 2), mstype.float32)
|
||||
net = ApplyCenteredRMSPropNet(var)
|
||||
|
@ -265,10 +307,16 @@ class ApplyFtrlNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_ftrl():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyFtrl operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
linear = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
|
@ -296,10 +344,16 @@ class ApplyGradientDescentNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_gradient_descent():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyGradientDescent operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyGradientDescentNet(var)
|
||||
|
||||
|
@ -322,10 +376,16 @@ class ApplyMomentumNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_momentum():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyMomentum operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.normal(size=(2, 3, 3, 4)).astype(np.float32))
|
||||
accum = Tensor(np.random.normal(size=(2, 3, 3, 4)).astype(np.float32))
|
||||
net = ApplyMomentumNet(var, accum)
|
||||
|
@ -352,10 +412,16 @@ class ApplyPowerSignNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_power_sign():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyPowerSign operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
m = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyPowerSignNet(var, m)
|
||||
|
@ -387,6 +453,11 @@ class ApplyProximalAdagradNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_proximal_adagrad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyProximalAdagrad operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyProximalAdagradNet(var, accum)
|
||||
|
@ -412,10 +483,16 @@ class ApplyProximalGradientDescentNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_proximal_gradient_descent():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyProximalGradientDescent operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyProximalGradientDescentNet(var)
|
||||
|
||||
|
@ -444,6 +521,11 @@ class ApplyRMSPropNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_apply_rms_prop():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify ApplyRMSProp operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(1., mstype.float32)
|
||||
net = ApplyRMSPropNet(var)
|
||||
|
||||
|
@ -474,6 +556,11 @@ class FusedSparseAdamNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_fused_sparse_adam():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify FusedSparseAdam operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.ones([3, 1, 2]).astype(np.float32))
|
||||
m = Tensor(np.ones([3, 1, 2]).astype(np.float32))
|
||||
v = Tensor(np.ones([3, 1, 2]).astype(np.float32))
|
||||
|
@ -513,6 +600,11 @@ class FusedSparseFtrlNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_fused_sparse_ftrl():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify FusedSparseFtrl operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 1, 2).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 1, 2).astype(np.float32))
|
||||
linear = Tensor(np.random.rand(3, 1, 2).astype(np.float32))
|
||||
|
@ -544,6 +636,11 @@ class FusedSparseLazyAdamNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_fused_sparse_lazyadam():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify FusedSparseLazyAdam operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.ones([3, 1, 2]).astype(np.float32))
|
||||
m = Tensor(np.ones([3, 1, 2]).astype(np.float32))
|
||||
v = Tensor(np.ones([3, 1, 2]).astype(np.float32))
|
||||
|
@ -581,6 +678,11 @@ class FusedSparseProximalAdagradNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_fused_sparse_proximal_adagrad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify FusedSparseProximalAdagrad operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 1, 2).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 1, 2).astype(np.float32))
|
||||
net = FusedSparseProximalAdagradNet(var, accum)
|
||||
|
@ -612,6 +714,11 @@ class SparseApplyAdagradNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sparse_apply_adagrad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SparseApplyAdagrad operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = SparseApplyAdagradNet(var, accum)
|
||||
|
@ -637,10 +744,16 @@ class SparseApplyAdagradV2Net(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sparse_apply_adagrad_v2():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SparseApplyAdagradV2 operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = SparseApplyAdagradV2Net(var, accum)
|
||||
|
@ -668,10 +781,16 @@ class SparseApplyFtrlNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sparse_apply_ftrl():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SparseApplyFtrl operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
linear = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
|
@ -704,6 +823,11 @@ class SparseApplyFtrlV2Net(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sparse_apply_ftrl_v2():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SparseApplyFtrlV2 operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
linear = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
|
@ -730,10 +854,16 @@ class SparseApplyProximalAdagradNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sparse_apply_proximal_adagrad():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SparseApplyProximalAdagrad operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = SparseApplyProximalAdagradNet(var, accum)
|
||||
|
@ -760,10 +890,16 @@ class SGDNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sgd():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SGD operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.array([2, -0.5, 1.7, 4]), mstype.float32)
|
||||
net = SGDNet(var)
|
||||
|
||||
|
@ -791,10 +927,16 @@ class ApplyProximalAdagradConstantNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sparse_apply_proximal_adagrad_constant():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify SparseApplyProximalAdagrad operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
accum = Tensor(np.random.rand(3, 3).astype(np.float32))
|
||||
net = ApplyProximalAdagradConstantNet(var, accum)
|
||||
|
@ -822,10 +964,16 @@ class MulSGDNet(nn.Cell):
|
|||
|
||||
|
||||
@pytest.mark.level1
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_mul_sgd():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify sgd operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
var = Tensor(np.array([2, -0.5, 1.7, 4]), mstype.float32)
|
||||
net = MulSGDNet(var)
|
||||
gradient = Tensor(np.array([1, -1, 0.5, 2]), mstype.float32)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-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.
|
||||
|
@ -47,6 +47,11 @@ class Sampling(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_sample_graph():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify normal distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (2, 3)
|
||||
seed = 0
|
||||
samp = Sampling(shape, seed=seed)
|
||||
|
@ -73,6 +78,11 @@ class CompositeNormalNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_composite_normal():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify normal distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (3, 2, 4)
|
||||
mean = Tensor(0.0, mstype.float32)
|
||||
stddev = Tensor(1.0, mstype.float32)
|
||||
|
@ -100,6 +110,11 @@ class CompositeLaplaceNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_composite_laplace():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify laplace distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (3, 2, 4)
|
||||
mean = Tensor(1.0, mstype.float32)
|
||||
lambda_param = Tensor(1.0, mstype.float32)
|
||||
|
@ -127,6 +142,11 @@ class CompositeGammaNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_composite_gamma():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify gamma distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (3, 2, 4)
|
||||
alpha = Tensor(1.0, mstype.float32)
|
||||
beta = Tensor(1.0, mstype.float32)
|
||||
|
@ -154,6 +174,11 @@ class CompositePoissonNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_composite_poisson():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify poisson distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (3, 2, 4)
|
||||
mean = Tensor(2.0, mstype.float32)
|
||||
net = CompositePoissonNet(shape)
|
||||
|
@ -180,6 +205,11 @@ class CompositeUniformNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_composite_uniform():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify uniform distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (3, 2, 4)
|
||||
a = Tensor(0.0, mstype.float32)
|
||||
b = Tensor(1.0, mstype.float32)
|
||||
|
@ -209,6 +239,11 @@ class StandardNormalNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_standard_normal():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify standard normal distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (4, 16)
|
||||
net = StandardNormalNet(shape)
|
||||
s1, s2, s3 = net()
|
||||
|
@ -236,6 +271,11 @@ class StandardLaplaceNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_standard_laplace():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify standard laplace distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (4, 16)
|
||||
net = StandardLaplaceNet(shape)
|
||||
s1, s2, s3 = net()
|
||||
|
@ -265,6 +305,11 @@ class GammaNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_gamma():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify gamma distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (4, 16)
|
||||
alpha = Tensor(1.0, mstype.float32)
|
||||
beta = Tensor(1.0, mstype.float32)
|
||||
|
@ -294,6 +339,11 @@ class PoissonNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_poisson():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify poisson distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (4, 16)
|
||||
mean = Tensor(5.0, mstype.float32)
|
||||
net = PoissonNet(shape=shape)
|
||||
|
@ -322,6 +372,11 @@ class UniformIntNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_uniform_int():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify uniform int distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (4, 16)
|
||||
minval = Tensor(1, mstype.int32)
|
||||
maxval = Tensor(5, mstype.int32)
|
||||
|
@ -351,6 +406,11 @@ class UniformRealNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_uniform_real():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify uniform real distribution.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (4, 16)
|
||||
net = UniformRealNet(shape)
|
||||
s1, s2, s3 = net()
|
||||
|
@ -376,6 +436,11 @@ class DropoutGenMaskNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_dropout_gen_mask():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify DropoutGenMask.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
shape = (2, 4, 5)
|
||||
keep_prob = Tensor(0.5, mstype.float32)
|
||||
net = DropoutGenMaskNet(shape)
|
||||
|
@ -401,6 +466,11 @@ class RandomChoiceWithMaskNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_random_choice_with_mask():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify RandomChoiceWithMask.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
mode = context.get_context('mode')
|
||||
assert (mode == context.GRAPH_MODE), 'GRAPH_MODE required but got ' + str(mode)
|
||||
net = RandomChoiceWithMaskNet()
|
||||
|
@ -428,6 +498,11 @@ class RandomCategoricalNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_random_categorical():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify RandomCategorical.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
num_sample = 8
|
||||
net = RandomCategoricalNet(num_sample)
|
||||
x = Tensor(np.random.random((10, 5)).astype(np.float32))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
# Copyright 2020-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.
|
||||
|
@ -64,6 +64,11 @@ class NpuFloatNet(nn.Cell):
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_float_not_overflow():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify overflow operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_data = Tensor(np.full((8, 5, 3, 1), 655, dtype=np.float16), dtype=mstype.float16)
|
||||
net = NpuFloatNet()
|
||||
out = net(input_data)
|
||||
|
@ -78,6 +83,11 @@ def test_float_not_overflow():
|
|||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
def test_float_overflow():
|
||||
"""
|
||||
Feature: Auto monad feature.
|
||||
Description: Verify overflow operator.
|
||||
Expectation: No exception.
|
||||
"""
|
||||
input_data = Tensor(np.full((8, 5, 3, 1), 65504, dtype=np.float16), dtype=mstype.float16)
|
||||
net = NpuFloatNet()
|
||||
out = net(input_data)
|
||||
|
|
Loading…
Reference in New Issue