[Fallback][Control_flow] Remove fallback testcase from ST to UT.

This commit is contained in:
Margaret_wangrui 2022-06-01 10:07:45 +08:00
parent 2838edf7a5
commit afe3d2a161
78 changed files with 2428 additions and 2426 deletions

View File

@ -15,77 +15,11 @@
""" test graph fallback control flow."""
import pytest
from mindspore import Tensor, ms_function, context
from mindspore import dtype as mstype
import numpy as np
context.set_context(mode=context.GRAPH_MODE)
@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
def test_single_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(1)
if x > Tensor(7):
return x
return x * 2
res = control_flow_if()
assert res == 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
def test_single_if_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1, 2, 3, 4, 5])
y = x % 2
z = Tensor(y)
if (x < y).any():
z = Tensor(x)
return z
res = control_flow_if()
assert np.all(res.asnumpy() == np.array([1, 0, 1, 0, 1]))
@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
def test_single_if_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1])
if x <= 1:
x += 1
return Tensor(x)
res = control_flow_if()
assert res == 2
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -109,53 +43,7 @@ def test_single_if_4():
assert res == 42
@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
def test_single_if_else_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_else():
x = Tensor(1)
if x > Tensor(7):
return x
x += Tensor(3)
return x * 2
res = control_flow_if_else()
assert res == 8
@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
def test_single_if_else_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_else():
x = np.array([1, 2, 3, 4, 5])
y = x % 2
if (x < y).any():
z = Tensor(x)
else:
z = Tensor(y)
return z
res = control_flow_if_else()
assert np.all(res.asnumpy() == np.array([1, 0, 1, 0, 1]))
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -175,114 +63,3 @@ def test_single_if_two_cond():
return x * 2
res = control_flow_if()
assert res == 1
@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
def test_single_if_builtin_function_abs():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(-11, mstype.float32)
if abs(x) > Tensor(np.array(2)):
return x - Tensor(np.array(2))
return x * 2
res = control_flow_if()
assert res == -13
@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
def test_single_if_builtin_function_abs_min():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(-11, mstype.float32)
y = Tensor(12, mstype.float32)
if abs(x) > Tensor(np.array(2)) and min(x, y) == x + y:
return x - Tensor(np.array(2))
return x * 2
res = control_flow_if()
assert res == -22
@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
def test_single_if_builtin_function_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(-11, mstype.float32)
y = Tensor(12, mstype.float32)
if x + y > 0:
return sum([x, y, 2 * x])
return x * 2
res = control_flow_if()
assert res == -21
@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
def test_single_if_change_variable_value():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1, 2, 3, 4])
y = np.array([4, 5, 6])
if max(x) <= min(y):
x += 3
return Tensor(x)
return Tensor(0)
res = control_flow_if()
assert np.all(res.asnumpy() == np.array([4, 5, 6, 7]))
@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
def test_single_if_np_all():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1, 2, 3, 4])
y = np.array([4, 5, 6])
if np.all(x == np.array([1, 2, 3, 4])) and np.any(y == np.array([4, 4, 4])):
x += 3
return Tensor(x)
return Tensor(0)
res = control_flow_if()
assert np.all(res.asnumpy() == np.array([4, 5, 6, 7]))

View File

@ -17,7 +17,6 @@ import pytest
import numpy as np
import mindspore as ms
from mindspore import Tensor, ms_function, context, Parameter
from mindspore import dtype as mstype
from mindspore.nn import Cell
context.set_context(mode=context.GRAPH_MODE)
@ -44,7 +43,7 @@ def test_single_while_1():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -66,7 +65,7 @@ def test_single_while_2():
assert res == 14
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -89,28 +88,6 @@ def test_single_while_3():
assert res == 7
@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
def test_single_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
z = np.array(0)
while z <= 3:
z += 1
return Tensor(z)
res = control_flow_while()
assert res == 4
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_single_while_5():
"""
@ -129,7 +106,7 @@ def test_single_while_5():
assert res == 3
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -153,7 +130,7 @@ def test_single_while_two_cond_1():
assert res == 25
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -176,29 +153,7 @@ def test_single_while_two_cond_2():
assert res == 8
@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
def test_single_while_two_cond_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = np.array([1, 2, 3, 4, 5])
y = Tensor(1)
while sum(x) > 0 and y >= 0:
x -= 3
return Tensor(sum(x))
res = control_flow_while()
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -244,113 +199,3 @@ def test_single_while_numpy():
return Tensor(x)
res = control_flow_while()
assert (res.asnumpy() == [1, 1, 3, 4, 5]).all()
def test_single_while_builtin_function_abs_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = Tensor(-11, mstype.float32)
y = Tensor(0)
while abs(x) > Tensor(2):
x += Tensor(4)
y += Tensor(1)
return x, y
res_x, res_y = control_flow_while()
assert res_x == 1
assert res_y == 3
@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
def test_single_while_builtin_function_abs_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = np.array(-11)
y = np.array(0)
while abs(x) > 2:
x += np.array(4)
y += np.array(1)
return Tensor(x), Tensor(y)
res_x, res_y = control_flow_while()
assert res_x == 1
assert res_y == 3
@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
def test_single_while_builtin_function_abs():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = -11
y = 0
while abs(x) > 2:
x += 4
y += 1
return Tensor(x), Tensor(y)
res_x, res_y = control_flow_while()
assert res_x == 1
assert res_y == 3
def test_single_while_builtin_function_max_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = Tensor(3)
y = Tensor(5)
while max(x, y) > 3:
x -= Tensor(4)
y -= Tensor(1)
return x, y
res_x, res_y = control_flow_while()
assert res_x == -5
assert res_y == 3
@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
def test_single_while_builtin_function_max_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = np.array(3)
y = np.array(5)
while max(x, y) > 3:
x -= np.array(4)
y -= np.array(1)
return Tensor(x), Tensor(y)
res_x, res_y = control_flow_while()
assert res_x == -5
assert res_y == 3

View File

@ -43,7 +43,7 @@ def test_single_for_1():
assert res == 21
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -67,7 +67,7 @@ def test_single_for_2():
assert res == 21
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -90,99 +90,7 @@ def test_single_for_zip():
assert res == 9
@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
def test_single_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 3, 5])
y = np.array([0, 2, 4])
for _ in range(3):
x = x + y
return Tensor(x)
res = control_flow_for()
assert (res.asnumpy() == [1, 9, 17]).all()
@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
def test_single_for_builtin_function_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 3, 5, 7, 9])
result = x
for _ in range(3):
result = sum(x)
return Tensor(result)
res = control_flow_for()
assert res == 25
@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
def test_single_for_builtin_function_numpy_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 3, 5, 7, 9])
y = np.array([0, 2, 4, 6, 8])
result = x
for _ in range(3):
x = x + y
result = sum(x, 1)
return Tensor(result)
res = control_flow_for()
assert res == 86
@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
def test_single_for_builtin_function_tensor_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = Tensor(np.array([1, 3, 5, 7, 9]))
y = Tensor(np.array([0, 2, 4, 6, 8]))
result = x
for _ in range(3):
x = x + y
result = sum(x, 1)
return result
res = control_flow_for()
assert res == 86
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -201,24 +109,3 @@ def test_single_for_builtin_function_int():
return Tensor(x, mstype.float32)
res = control_flow_for()
assert res == 8.1
@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
def test_single_for_builtin_function_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1.1, 2.2])
for _ in range(3):
x = x + list(x)
return Tensor(x)
res = control_flow_for()
assert (res.asnumpy() == [8.8, 17.6]).all()

View File

@ -20,102 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_if_in_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(1)
y = Tensor(2)
if x > Tensor(0):
if y > Tensor(1):
return y + 1
return x + 1
return x + y
res = control_flow_if_in_if()
assert res == 3
@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
def test_if_in_if_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(1)
y = Tensor(0)
if x > Tensor(0):
if y > Tensor(1):
return y + 1
return x + 1
return x + y
res = control_flow_if_in_if()
assert res == 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
def test_if_in_if_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(-2)
y = Tensor(-3)
if x > Tensor(0):
if y > Tensor(1):
return y + 1
return x + 1
return x + y
res = control_flow_if_in_if()
assert res == -5
@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
def test_if_in_if_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = np.array([1, 2, 3, 4, 5])
y = x % 2
z = Tensor(y)
if (x >= y).all():
if sum(z) > Tensor(2):
z = Tensor(x) + 1
return z
res = control_flow_if_in_if()
assert np.all(res.asnumpy() == np.array([2, 3, 4, 5, 6]))
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -140,34 +44,7 @@ def test_if_in_if_5():
assert res == 4
@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
def test_if_else_in_if_else_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(10)
y = Tensor(7)
if x - y > Tensor(np.array([0])):
x = x - Tensor(3)
if x - y > Tensor(0):
x = x - Tensor(4)
else:
x = x + Tensor(4)
x = x * 2
return x - 1
res = control_flow_if_in_if()
assert res == 21
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -202,37 +79,7 @@ def test_if_else_in_if_else_2():
assert res == -16
@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
def test_if_in_if_multi_conds():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = np.array([1, 2, 3, 4])
y = np.array([4, 5, 6])
if max(x) <= min(y) and sum(x) == 10:
x += 3
if max(x) <= max(y):
m = Tensor(10)
elif min(x) != max(y) or x.size > y.size:
m = Tensor(20)
else:
m = Tensor(0)
else:
m = Tensor(1)
return m
res = control_flow_if_in_if()
assert res == 20
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -44,7 +44,7 @@ def test_if_in_while_1():
assert res == 7
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -67,7 +67,7 @@ def test_if_in_while_2():
assert res == 3
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -93,7 +93,7 @@ def test_if_in_while_3():
assert res == 6
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -124,58 +124,7 @@ def test_if_in_while_4():
assert res == 5
@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
def test_if_in_while_built_in_func():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_while():
x = np.array([1, 2, 3, 4])
y = 0
while sum(x) <= 40 and y % 2 == 0:
if min(x) % 2 == 0:
x += 1
else:
x += 3
return Tensor(sum(x))
res = control_flow_if_in_while()
assert res == 42
@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
def test_if_in_while_built_in_func_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_while():
x = np.array([1, 2, 3, 4])
while sum(x) <= 40:
if min(x) % 2 == 0:
x += 1
else:
x += 3
if max(x) == 8:
break
return Tensor(sum(x))
res = control_flow_if_in_while()
assert res == 26
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -43,7 +43,7 @@ def test_if_in_for_tensor():
assert res == 14
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -68,7 +68,7 @@ def test_if_in_for_tensor_2():
assert res == 19
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -92,152 +92,7 @@ def test_if_in_for_tensor_3():
assert res == 17
@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
def test_if_in_for_tensor_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = Tensor(7)
y = Tensor(0.0)
for _ in range(3):
x = x + y/2
if y < Tensor(10) and x < Tensor(20):
y += x
y += Tensor(1)
return x + y
res = control_flow_for()
assert res == 42
@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
def test_if_in_for_tensor_5():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = Tensor(7)
y = Tensor(0.0)
for _ in range(3):
x = x + y/2
if y < Tensor(10):
y += x
if x < Tensor(15):
x += y/2
y += Tensor(1)
return x + y
res = control_flow_for()
assert res == 62
@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
def test_if_in_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
for _ in range(3):
if sum(x) <= 15:
x += 1
return Tensor(sum(x))
res = control_flow_for()
assert res == 18
@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
def test_if_in_for_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
for _ in range(3):
if sum(x) <= 15:
x += 1
else:
x -= 3
return Tensor(sum(x))
res = control_flow_for()
assert res == 6
@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
def test_if_in_for_numpy_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
for _ in range(3):
if sum(x) <= 15:
x += 2
x -= 1
return Tensor(sum(x))
res = control_flow_for()
assert res == 14
@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
def test_if_in_for_numpy_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = np.array([1])
for _ in range(3):
if sum(x) <= 15:
y += 1
x += y
return Tensor(sum(x) + y)
res = control_flow_for()
assert res == 36
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -260,82 +115,3 @@ def test_if_in_for_numpy_5():
return a
res = control_flow_for()
assert res == 47
@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
def test_if_in_for_with_break():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = (Tensor(1), Tensor(3), Tensor(5))
a = Tensor(0)
for e in y:
if a > 15:
break
a += Tensor(sum(x)) + e
return a
res = control_flow_for()
assert res == 24
@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
def test_if_in_for_with_continue():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = (Tensor(1), Tensor(3), Tensor(5))
a = Tensor(0)
for e in y:
if a > 15:
continue
a += Tensor(sum(x)) + e
return a
res = control_flow_for()
assert res == 24
@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
def test_if_in_for_with_break_continue():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = (Tensor(1), Tensor(2), Tensor(4), Tensor(5))
a = Tensor(0)
for e in y:
a += Tensor(sum(x)) + e
if e == Tensor(2):
continue
if a > 15:
a -= Tensor(1)
break
a += Tensor(1)
return a
res = control_flow_for()
assert res == 37

View File

@ -46,7 +46,7 @@ def test_while_in_if_1():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -72,7 +72,7 @@ def test_while_in_if_2():
assert res == 12
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -99,7 +99,7 @@ def test_while_in_if_3():
assert res == 7
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -126,7 +126,7 @@ def test_while_two_cond_in_if_1():
assert res == 21
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -152,7 +152,7 @@ def test_while_two_cond_in_if_2():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_x86_ascend_training

View File

@ -48,7 +48,7 @@ def test_while_in_while_1():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -74,7 +74,7 @@ def test_while_in_while_2():
assert res == 4
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -102,7 +102,7 @@ def test_while_in_while_3():
assert res == 7
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -129,7 +129,7 @@ def test_while_in_while_with_two_cond_1():
assert res == 27
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -155,7 +155,7 @@ def test_while_in_while_with_two_cond_2():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_ascend_training
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -181,7 +181,7 @@ def test_while_in_while_with_two_cond_3():
assert res == -1
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -46,7 +46,7 @@ def test_for_in_if_tensor():
assert res == 10
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -70,30 +70,7 @@ def test_for_in_if_tensor_2():
assert res == -5
@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
def test_for_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = np.array([1, 2, 3, 4, 5])
y = np.array([1, 2, 3, 4, 5])
if (x == y).all():
for _ in range(2):
y += x
return Tensor(y)
res = control_flow_for_in_if()
assert np.all(res.asnumpy() == np.array([3, 6, 9, 12, 15]))
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -127,75 +104,7 @@ def test_for_in_if_param():
assert res2 == 12
@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
def test_for_in_if_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = list((1, 2, 3, 4, 5))
if len(x) == 5:
for _ in range(2):
x.append(10)
return Tensor(x)
res = control_flow_for_in_if()
assert np.all(res.asnumpy() == np.array([1, 2, 3, 4, 5, 10, 10]))
@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
def test_for_in_if_tuple_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = tuple([1, 2, 3, 4, 5])
y = list((0, 1))
if x[4] == 5 and len(y) < 3:
for _ in range(2):
y.append(x[1])
return Tensor(y)
res = control_flow_for_in_if()
assert np.all(res.asnumpy() == np.array([0, 1, 2, 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
def test_for_in_if_numpy_list_len_max():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = np.array([1, 2, 3, 1, 1])
y = list((4, 6, -2))
if len(y) <= max(x):
for i in range(2, 4):
y += x[i]
return Tensor(y)
out = control_flow_for_in_if()
np.all(out.asnumpy() == np.array([9, 11, 3]))
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -220,7 +129,7 @@ def test_for_in_if_numpy_print():
np.all(out.asnumpy() == np.array([7, 9, 1]))
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -69,7 +69,7 @@ def test_for_in_while_numpy_append():
assert res == 54
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -104,7 +104,7 @@ def test_for_in_while_sum():
assert res == 26
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -130,7 +130,7 @@ def test_for_in_while_print():
assert res2 == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow if after if scenario"""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -44,7 +43,7 @@ def test_if_after_if_tensor():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -74,7 +73,7 @@ def test_if_after_if_tensor_2():
assert res == 9
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -96,31 +95,3 @@ def test_if_after_if_tensor_3():
return a
res = control_flow_if_after_if(Tensor(10))
assert res == 11
@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
def test_if_after_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if():
x = np.array([1, 2, 3, 4])
a = sum(x)
if a > 15:
y = np.array([1, 2, 3, 4])
else:
y = np.array([4, 5, 6])
if np.all(y == np.array([1, 2, 3, 4])):
ret = Tensor(1)
else:
ret = Tensor(2)
return ret
res = control_flow_if_after_if()
assert res == 2

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow if after while scenario"""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -46,7 +45,7 @@ def test_if_after_while_tensor():
assert res == 6
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -71,107 +70,3 @@ def test_if_after_while_tensor_2():
return x + y
res = control_flow_if_after_while()
assert res == 11
@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
def test_if_after_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = np.array([5, 6])
while sum(x) < 20:
x += 1
y += 1
if max(y) == 9:
return Tensor(sum(y))
y = y - 2
return Tensor(sum(y))
res = control_flow_if_after_while()
assert res == 17
@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
def test_if_after_while_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = np.array([5, 6])
while sum(x) < 20:
x += 1
y += 1
if max(y) == 8:
return Tensor(sum(y))
y = y - 2
return Tensor(sum(y))
res = control_flow_if_after_while()
assert res == 13
@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
def test_if_after_while_tensor_and_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = Tensor(5)
while sum(x) < 20:
x += 1
y += 1
if max(x) == 7:
return y
y = y - 2
return y
res = control_flow_if_after_while()
assert res == 8
@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
def test_if_after_while_tensor_and_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = Tensor(5)
while sum(x) < 20:
x += 1
y += 1
if max(x) == 6:
return y
y = y - 2
return y
res = control_flow_if_after_while()
assert res == 6

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow."""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -46,93 +45,3 @@ def test_if_after_if_in_if_tensor():
return y
res = control_flow_if_after_if_in_if()
assert res == 22
@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
def test_if_after_if_in_if_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_if():
x = Tensor(1)
y = Tensor(10)
z = x + y
if x > Tensor(3):
if y > x:
y += x
else:
z = x * 2
if x + y >= z:
y = y * 2 - x
else:
y = z * 2 - x
return y
res = control_flow_if_after_if_in_if()
assert res == 19
@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
def test_if_after_if_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_if():
x = np.array([1, 3, 5])
y = np.array([1, 3, 5])
z = x + y
if sum(x, 1) > Tensor(3):
x += 1
if (y > x).all():
y += x
else:
z = x * 2
if (x + y >= z).all():
y = y * 2 - x
return Tensor(y)
res = control_flow_if_after_if_in_if()
assert (res.asnumpy() == [0, 2, 4]).all()
@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
def test_if_after_if_in_if_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_if():
x = np.array([1, 3, 5])
y = np.array([1, 3, 5])
if sum(x, 1) > 2:
z = x + y
x += 1
if (y > x - z).all():
y += x
else:
y -= x
else:
z = x * 2
if (x + y >= z).all():
y = y * 2 - x
return Tensor(y)
res = control_flow_if_after_if_in_if()
assert (res.asnumpy() == [4, 10, 16]).all()

View File

@ -49,35 +49,7 @@ def test_if_after_if_in_while_tensor():
assert res == 54
@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
def test_if_after_if_in_while_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_while():
x = Tensor(5)
y = Tensor(2)
z = x - y
while x >= Tensor(3):
if y > x:
y += x
z = x * 2 + y
x -= 2
if x + y >= z:
return y * x - z
return y
res = control_flow_if_after_if_in_while()
assert res == 2
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -14,41 +14,11 @@
# ============================================================================
""" test graph fallback control flow."""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_if_after_if_in_for_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = Tensor(1)
y = Tensor(2)
z = Tensor(0)
for _ in range(3):
if y > x:
y += x
else:
z = x * 2 - y
z = z + Tensor(1)
if x + y >= z:
y = y * x - z
return y
res = control_flow_if_after_if_in_for()
assert res == 4
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -77,84 +47,3 @@ def test_if_after_if_in_for_tensor_2():
return y + z
res = control_flow_if_after_if_in_for()
assert res == -37
@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
def test_if_after_if_in_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = Tensor(1)
y = np.array(1)
z = Tensor(0)
tensor_y = Tensor(y)
for _ in range(3):
if tensor_y > x:
z = x * 2 - tensor_y
z = z + Tensor(1)
tensor_y += 2
if x + Tensor(y) >= z:
return tensor_y * x - z
return tensor_y * x + z
res = control_flow_if_after_if_in_for()
assert res == 9
@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
def test_if_after_if_in_for_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = np.array([1, 3, 5, 7])
y = np.array([9, 8, 7, 6])
z = Tensor(1)
for i in range(4):
if x[i] > y[i]:
z = x * 2 - y
y += 2
if (x > y).all():
return Tensor(y * x) - z
return Tensor(y)
res = control_flow_if_after_if_in_for()
assert (res.asnumpy() == [17, 16, 15, 14]).all()
@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
def test_if_after_if_in_for_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = [1, 3, 5, 7]
y = [9, 8, 7, 6]
for i in range(4):
if x[i] > y[i]:
y = x * 2
if len(x) < len(y):
return Tensor(x + y)
return Tensor(y)
res = control_flow_if_after_if_in_for()
assert (res.asnumpy() == [1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7]).all()

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow."""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -47,7 +46,7 @@ def test_if_after_while_in_if_tensor():
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -75,60 +74,3 @@ def test_if_after_while_in_if_tensor_2():
return y
res = control_flow_if_after_while_in_if()
assert res == 1
@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
def test_if_after_while_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while_in_if():
x = np.array([1])
y = np.array([5])
z = np.array([9])
if z < 6:
while y > x:
y -= x
z = z + np.array([1])
if x + y <= z:
y = y * x - z
return Tensor(y)
res = control_flow_if_after_while_in_if()
assert (res.asnumpy() == [-5]).all()
@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
def test_if_after_while_in_if_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while_in_if():
x = np.array([1])
y = np.array([5])
z = np.array([9])
if z > 6 and x < y:
while y > x:
y -= x
z = z + np.array([1])
x = x + y
if x + y <= z:
y = y * x - z
else:
y = z
return Tensor(y)
res = control_flow_if_after_while_in_if()
assert (res.asnumpy() == [-8]).all()

View File

@ -47,7 +47,7 @@ def test_if_after_while_in_while_tensor():
assert res == 1
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -75,7 +75,7 @@ def test_if_after_while_in_while_tensor_2():
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -47,7 +47,7 @@ def test_if_after_while_in_for_tensor():
assert res == 13
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -75,7 +75,7 @@ def test_if_after_while_in_for_tensor_2():
assert res == 4
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -98,28 +98,3 @@ def test_if_after_while_in_for_numpy():
return y
res = control_flow_if_after_while_in_for()
assert res == 11
@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
def test_if_after_while_in_for_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while_in_for():
x = np.array([1, 2, 3, 4])
y = np.array([4])
for _ in range(4):
while y > x[0]:
y -= x[1]
if y != 0:
y = y + sum(x)
return Tensor(y)
res = control_flow_if_after_while_in_for()
assert res == 0

View File

@ -47,36 +47,6 @@ def test_if_after_for_in_if_tensor():
assert res == 5
@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
def test_if_after_for_in_if_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_if():
x = Tensor([1])
y = Tensor([2])
z = Tensor([7])
if y > x:
z = Tensor([1])
for _ in range(3):
y -= z
z = x + y
if x + y >= z:
y = y * x - z
else:
y = y * x + z
return y
res = control_flow_if_after_for_in_if()
assert (res.asnumpy() == [-1]).all()
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_if_after_for_in_if_numpy():
"""
@ -98,30 +68,3 @@ def test_if_after_for_in_if_numpy():
return Tensor(z)
res = control_flow_if_after_for_in_if()
assert (res.asnumpy() == [6, 10]).all()
@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
def test_if_after_for_in_if_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_for():
x = np.array([3, 2])
y = Tensor(np.array([0, 2, 4, 6, 8]))
z = Tensor([0])
if 5 in x:
for j in range(5):
y[j] -= j
z = Tensor(x[1] + y[j])
if sum(y) >= z:
z = Tensor(sum(y)) - Tensor([9])
return z
res = control_flow_if_after_for_in_for()
assert res == 11

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow."""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -47,7 +46,7 @@ def test_if_after_for_in_while_tensor():
assert res == 13
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -73,56 +72,3 @@ def test_if_after_for_in_while_tensor_2():
return y + z
res = control_flow_if_after_for_in_while()
assert res == 48
@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
def test_if_after_for_in_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_while():
x = np.array([5, 4, 3, 2, 1])
y = np.zeros(5)
z = np.ones(5)
while sum(x) > y[0]:
for _ in range(3):
y -= 1
x = y + 2
if (x != z).all():
y = y - z[2]
return Tensor(y + z[0])
res = control_flow_if_after_for_in_while()
assert (res.asnumpy() == [-3, -3, -3, -3, -3]).all()
@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
def test_if_after_for_in_while_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_while():
x = np.array([5, 4, 3, 2, 1])
y = (Tensor(1), Tensor(3), Tensor(5))
while sum(x) >= 15:
for _ in range(3):
x -= 4
x = x + 2
if sum(y) == 9:
return Tensor(x)
return y[2]
res = control_flow_if_after_for_in_while()
assert (res.asnumpy() == [-5, -6, -7, -8, -9]).all()

View File

@ -46,7 +46,7 @@ def test_while_after_if_tensor():
assert res == 11
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -76,7 +76,7 @@ def test_while_after_if_tensor_2():
assert res_z == 1
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -46,7 +46,7 @@ def test_while_after_while_tensor():
assert res == -3
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -71,33 +71,6 @@ def test_while_after_while_tensor_2():
assert res == 6
@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
def test_while_after_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while():
x = [1, 2, 3, 4]
y = Tensor([8])
z = 2
while Tensor([sum(x)]) > y:
x.append(z)
y = Tensor([18])
while y >= 0:
y -= Tensor([x[0]])
return Tensor(x), y
res_x, res_y = control_flow_while_after_while()
assert (res_x.asnumpy() == [1, 2, 3, 4, 2]).all()
assert res_y == -1
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_while_after_while_numpy_2():
"""

View File

@ -20,32 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_while_after_for_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_for():
x = Tensor([1])
y = Tensor([2])
for _ in range(5):
y = y * x - Tensor([3])
z = y + x
while y > x and x < z:
y -= x
z = z + y
return z
res = control_flow_while_after_for()
assert res == -12
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -72,31 +46,6 @@ def test_while_after_for_tensor_2():
assert res == 5
@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
def test_while_after_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_for():
x = [1, 2, 3, 4, 5]
y = Tensor([3])
for i in range(4):
x[i] += i
while y >= 0:
y -= Tensor(x[0])
return Tensor(x), y
res_x, res_y = control_flow_while_after_for()
assert (res_x.asnumpy() == [1, 3, 5, 7, 5]).all()
assert res_y == -1
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_while_after_for_numpy_2():
"""

View File

@ -52,7 +52,7 @@ def test_while_after_if_in_if_tensor():
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -53,39 +53,6 @@ def test_while_after_if_in_while_tensor():
assert res == 33
@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
def test_while_after_if_in_while_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_if_in_while():
x = Tensor([1])
y = Tensor([2])
z = x + y
while x >= y:
if x * y < z:
x = y + z
elif x < y:
x = y - 1
else:
x = y - z
while y > x:
y -= x
z = z + y
return x, y, z
res_x, res_y, res_z = control_flow_while_after_if_in_while()
assert res_x == 1
assert res_y == 1
assert res_z == 4
@pytest.mark.skip(reason='Not support graph fallback feature yet')
def test_while_after_if_in_while_numpy():
"""

View File

@ -52,7 +52,7 @@ def test_while_after_if_in_for_tensor():
assert res == 73
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -49,7 +49,7 @@ def test_while_after_while_in_if_tensor():
assert res == (1, 1, 16)
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -84,34 +84,7 @@ def test_while_after_while_in_if_tensor_2():
assert res == (2, 1, 15)
@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
def test_while_after_while_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while_in_if():
x = Tensor([1])
y = Tensor([2])
z = np.array([1]) + np.array([2])
if Tensor(z) >= x + y:
y = y * x + Tensor([3])
while np.array([5]) > z:
z += 1
while y > x:
y -= x
return x, y, Tensor(z)
res = control_flow_while_after_while_in_if()
assert res == (1, 1, 5)
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -20,61 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_while_after_while_in_for_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while_in_for():
x = Tensor([1])
y = Tensor([-2])
z = [Tensor([2]), Tensor([4]), Tensor([6])]
for index in z:
while (x * y) > (x + y - index):
x = x + 1
while y >= -x:
y -= x
z = z + y
return x, y, z
res_x, res_y, res_z = control_flow_while_after_while_in_for()
assert res_x == 3
assert res_y == -5
assert (res_z.asnumpy() == [[-3], [-1], [1]]).all()
@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
def test_while_after_while_in_for_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while_in_for():
x = Tensor([1])
y = Tensor([2])
z = [Tensor([2]), Tensor([4]), Tensor([6])]
for index in range(2):
while (x * y) > z[index]:
x = y * x
while y >= x:
y -= x
return x, y
res = control_flow_while_after_while_in_for()
assert res == (1, 0)
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training

View File

@ -52,7 +52,7 @@ def test_while_after_for_in_if_1():
assert res == 11
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -88,7 +88,7 @@ def test_while_after_for_in_if_2():
assert res_z == 1
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow."""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -50,7 +49,7 @@ def test_while_after_for_in_while_1():
assert res == 6
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -78,65 +77,3 @@ def test_while_after_for_in_while_2():
res = func2312()
assert res == -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
def test_while_after_for_in_while_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2313():
x = [1, 2, 3, 4]
y = Tensor([8])
z = 2
while Tensor([sum(x)]) > y:
for _ in range(1):
x.append(z)
y = Tensor([18])
while y >= 0:
y -= Tensor(np.array([x[0]]))
return Tensor(np.array(x)), y
res_x, res_y = func2313()
assert (res_x.asnumpy() == [1, 2, 3, 4, 2]).all()
assert res_y == -1
@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
def test_while_after_for_in_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2314():
x = Tensor([1])
y = Tensor([2])
z = []
while max(x, y) == Tensor([2]):
y = y + min(x, y)
for _ in range(3):
z.append(Tensor([2]))
i = 0
while i < len(z):
x = x * z[i]
i = i + 1
return x
res = func2314()
assert res == 8

View File

@ -15,43 +15,11 @@
""" test graph fallback control flow."""
import pytest
import numpy as np
import mindspore
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_while_after_for_in_for_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2321():
x = Tensor([0])
y = np.array([1])
for _ in range(2):
for _ in range(2):
x = x + 1
i = np.array([1])
while i < 3:
y = y + i
i += 1
return x + Tensor(y, dtype=mindspore.int64)
res = func2321()
assert res == 8
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -88,7 +56,7 @@ def test_while_after_for_in_for_2():
assert res_y == 6
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -118,33 +86,3 @@ def test_while_after_for_in_for_3():
res = func2323()
assert res == 9
@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
def test_while_after_for_in_for_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2324():
x = Tensor([0])
for i in range(2):
for j in range(2):
x = x - Tensor([i + j])
z = [np.array([0]), np.array([2]), np.array([2])]
i = 0
while i < len(z):
x = x + Tensor(z[i])
i += 1
return x
res = func2324()
assert res == 0

View File

@ -20,32 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_after_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([0])
y = Tensor([0])
if x == y:
x = x + 3
for _ in range(3):
y = y + 1
return x + y
res = func()
assert res == 6
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -78,7 +52,7 @@ def test_for_after_if_2():
assert res_y == 5
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -107,31 +81,3 @@ def test_for_after_if_3():
res = func()
assert res == 12
@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
def test_for_after_if_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([1])
y = Tensor([2])
if max(x, y) == Tensor([2]):
x = x + min(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x
res = func()
assert res == 12

View File

@ -47,7 +47,7 @@ def test_for_after_while_1():
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -77,7 +77,7 @@ def test_for_after_while_2():
assert res_y == 5
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -105,31 +105,3 @@ def test_for_after_while_3():
res = func()
assert res == 27
@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
def test_for_after_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([1])
y = Tensor([2])
while max(x, y) == Tensor([1]):
x = x + min(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x
res = func()
assert res == 6

View File

@ -15,38 +15,11 @@
""" test graph fallback control flow."""
import pytest
import numpy as np
import mindspore
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_after_for_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([0])
y = np.array([1])
for _ in range(2):
x = x + 1
for i in range(3):
y = y + i
return x + Tensor(y, dtype=mindspore.int64)
res = func()
assert res == 6
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -100,30 +73,3 @@ def test_for_after_for_3():
res = func()
assert res == 9
@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
def test_for_after_for_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([0])
for i in range(3):
x = x - Tensor([i])
z = (Tensor(0), Tensor(1), Tensor(2))
for i in zip(z):
x = x + i
return x
res = func()
assert res == 0

View File

@ -14,7 +14,6 @@
# ============================================================================
""" test graph fallback control flow for after if in while scenario"""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@ -50,7 +49,7 @@ def test_for_after_if_in_while_tensor():
assert res == 13
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -79,58 +78,3 @@ def test_for_after_if_in_while_tensor_2():
return x - y
res = control_flow_for_after_if_in_while()
assert res == 4
@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
def test_for_after_if_in_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_after_if_in_while():
x = np.array([1, 2, 3, 4])
y = np.array([9, 10, 11, 12])
while sum(x) < 20:
x += 2
if max(y) % 2 == 0:
y -= 3
a = Tensor(0)
for i in range(4):
a += Tensor(x[i] - y[i])
return a
res = control_flow_for_after_if_in_while()
assert res == -4
@pytest.mark.skip(reason='Not support to get attribute for InterpretObject.')
@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
def test_for_after_if_in_while_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_after_if_in_while():
x = np.array([1, 2, 3, 4])
y = np.array([1, 2, 3, 4])
while sum(x) < 20:
x += 1
if max(x) == 7:
break
x += 1
for i in x:
y += i - 20
return sum(y)
res = control_flow_for_after_if_in_while()
assert res == 18

View File

@ -26,7 +26,7 @@ context.set_context(mode=context.GRAPH_MODE)
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard
def test_for_after_if_in_if_1():
def test_for_after_while_in_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
@ -51,7 +51,7 @@ def test_for_after_if_in_if_1():
assert res == 8
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -89,7 +89,7 @@ def test_for_after_while_in_if_2():
assert res_y == 5
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -120,32 +120,3 @@ def test_for_after_while_in_if_3():
res = func3203()
assert res == 15
@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
def test_for_after_while_in_if_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3204():
x = Tensor([1])
y = Tensor([2])
if y - x == Tensor([1]):
while min(x, y) == Tensor([1]):
x = x + min(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x
res = func3204()
assert res == 12

View File

@ -49,7 +49,7 @@ def test_for_after_while_in_while_1():
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -81,7 +81,7 @@ def test_for_after_while_in_while_2():
assert y == 10
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -111,33 +111,3 @@ def test_for_after_while_in_while_3():
res = func3213()
assert res == 27
@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
def test_for_after_while_in_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3214():
x = Tensor([1])
y = Tensor([2])
while max(x, y) == Tensor([2]):
while min(x, y) == Tensor([1]):
x = x - min(x, y)
y = y + max(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x + y
res = func3214()
assert res == 4

View File

@ -49,7 +49,7 @@ def test_for_after_while_in_for_1():
assert res == 7
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training

View File

@ -49,7 +49,7 @@ def test_for_after_for_in_while_1():
assert res == 0
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -80,7 +80,7 @@ def test_for_after_for_in_while_2():
assert res_y == 5
@pytest.mark.level0
@pytest.mark.level1
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@ -109,33 +109,3 @@ def test_for_after_for_in_while_3():
res = func3313()
assert res == 12
@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
def test_for_after_for_in_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3314():
x = Tensor([1])
y = Tensor([2])
z = []
while max(x, y) == Tensor([2]):
y = y + min(x, y)
for _ in range(3):
z.append(Tensor([2]))
for i in z:
x = x * i
return x
res = func3314()
assert res == 8

View File

@ -15,39 +15,11 @@
""" test graph fallback control flow."""
import pytest
import numpy as np
import mindspore
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_after_for_in_for_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3321():
x = Tensor([0])
y = np.array([1])
for _ in range(2):
for _ in range(2):
x = x + 1
for i in range(3):
y = y + i
return x + Tensor(y, dtype=mindspore.int64)
res = func3321()
assert res == 8
@pytest.mark.level0
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@ -104,33 +76,3 @@ def test_for_after_for_in_for_3():
res = func3323()
assert res == 9
@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
def test_for_after_for_in_for_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3324():
x = Tensor([0])
for i in range(3):
x = x - Tensor([i])
for j in range(2):
if j == 0 or j == 1: # pylint: disable=consider-using-in
break
z = [np.array([0]), np.array([1]), np.array([2])]
for i in z:
x = x + Tensor(i)
return x
res = func3324()
assert res == 0

View File

@ -16,6 +16,8 @@
import numpy as np
from mindspore import context
from mindspore.nn import Cell
from mindspore import Tensor, ms_function
from mindspore import dtype as mstype
context.set_context(mode=context.GRAPH_MODE)
@ -63,3 +65,175 @@ def test_single_if_no_else_type_2():
test_net = TrueNet()
res = test_net()
assert str(res) == "(<class 'int'>, <class 'object'>)"
def test_single_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(1)
if x > Tensor(7):
return x
return x * 2
res = control_flow_if()
assert res == 2
def test_single_if_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1, 2, 3, 4, 5])
y = x % 2
z = Tensor(y)
if (x < y).any():
z = Tensor(x)
return z
res = control_flow_if()
assert np.all(res.asnumpy() == np.array([1, 0, 1, 0, 1]))
def test_single_if_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1])
if x <= 1:
x += 1
return Tensor(x)
res = control_flow_if()
assert res == 2
def test_single_if_else_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_else():
x = Tensor(1)
if x > Tensor(7):
return x
x += Tensor(3)
return x * 2
res = control_flow_if_else()
assert res == 8
def test_single_if_else_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_else():
x = np.array([1, 2, 3, 4, 5])
y = x % 2
if (x < y).any():
z = Tensor(x)
else:
z = Tensor(y)
return z
res = control_flow_if_else()
assert np.all(res.asnumpy() == np.array([1, 0, 1, 0, 1]))
def test_single_if_builtin_function_abs():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(-11, mstype.float32)
if abs(x) > Tensor(np.array(2)):
return x - Tensor(np.array(2))
return x * 2
res = control_flow_if()
assert res == -13
def test_single_if_builtin_function_abs_min():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(-11, mstype.float32)
y = Tensor(12, mstype.float32)
if abs(x) > Tensor(np.array(2)) and min(x, y) == x + y:
return x - Tensor(np.array(2))
return x * 2
res = control_flow_if()
assert res == -22
def test_single_if_builtin_function_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = Tensor(-11, mstype.float32)
y = Tensor(12, mstype.float32)
if x + y > 0:
return sum([x, y, 2 * x])
return x * 2
res = control_flow_if()
assert res == -21
def test_single_if_change_variable_value():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1, 2, 3, 4])
y = np.array([4, 5, 6])
if max(x) <= min(y):
x += 3
return Tensor(x)
return Tensor(0)
res = control_flow_if()
assert np.all(res.asnumpy() == np.array([4, 5, 6, 7]))
def test_single_if_np_all():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if():
x = np.array([1, 2, 3, 4])
y = np.array([4, 5, 6])
if np.all(x == np.array([1, 2, 3, 4])) and np.any(y == np.array([4, 4, 4])):
x += 3
return Tensor(x)
return Tensor(0)
res = control_flow_if()
assert np.all(res.asnumpy() == np.array([4, 5, 6, 7]))

View File

@ -0,0 +1,149 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
from mindspore import dtype as mstype
context.set_context(mode=context.GRAPH_MODE)
def test_single_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
z = np.array(0)
while z <= 3:
z += 1
return Tensor(z)
res = control_flow_while()
assert res == 4
def test_single_while_two_cond_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = np.array([1, 2, 3, 4, 5])
y = Tensor(1)
while sum(x) > 0 and y >= 0:
x -= 3
return Tensor(sum(x))
res = control_flow_while()
assert res == 0
def test_single_while_builtin_function_abs_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = Tensor(-11, mstype.float32)
y = Tensor(0)
while abs(x) > Tensor(2):
x += Tensor(4)
y += Tensor(1)
return x, y
res_x, res_y = control_flow_while()
assert res_x == 1
assert res_y == 3
def test_single_while_builtin_function_abs_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = np.array(-11)
y = np.array(0)
while abs(x) > 2:
x += np.array(4)
y += np.array(1)
return Tensor(x), Tensor(y)
res_x, res_y = control_flow_while()
assert res_x == 1
assert res_y == 3
def test_single_while_builtin_function_abs():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = -11
y = 0
while abs(x) > 2:
x += 4
y += 1
return Tensor(x), Tensor(y)
res_x, res_y = control_flow_while()
assert res_x == 1
assert res_y == 3
def test_single_while_builtin_function_max_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = Tensor(3)
y = Tensor(5)
while max(x, y) > 3:
x -= Tensor(4)
y -= Tensor(1)
return x, y
res_x, res_y = control_flow_while()
assert res_x == -5
assert res_y == 3
def test_single_while_builtin_function_max_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while():
x = np.array(3)
y = np.array(5)
while max(x, y) > 3:
x -= np.array(4)
y -= np.array(1)
return Tensor(x), Tensor(y)
res_x, res_y = control_flow_while()
assert res_x == -5
assert res_y == 3

View File

@ -0,0 +1,107 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_single_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 3, 5])
y = np.array([0, 2, 4])
for _ in range(3):
x = x + y
return Tensor(x)
res = control_flow_for()
assert (res.asnumpy() == [1, 9, 17]).all()
def test_single_for_builtin_function_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 3, 5, 7, 9])
result = x
for _ in range(3):
result = sum(x)
return Tensor(result)
res = control_flow_for()
assert res == 25
def test_single_for_builtin_function_numpy_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 3, 5, 7, 9])
y = np.array([0, 2, 4, 6, 8])
result = x
for _ in range(3):
x = x + y
result = sum(x, 1)
return Tensor(result)
res = control_flow_for()
assert res == 86
def test_single_for_builtin_function_tensor_sum():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = Tensor(np.array([1, 3, 5, 7, 9]))
y = Tensor(np.array([0, 2, 4, 6, 8]))
result = x
for _ in range(3):
x = x + y
result = sum(x, 1)
return result
res = control_flow_for()
assert res == 86
def test_single_for_builtin_function_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1.1, 2.2])
for _ in range(3):
x = x + list(x)
return Tensor(x)
res = control_flow_for()
assert (res.asnumpy() == [8.8, 17.6]).all()

View File

@ -0,0 +1,142 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow if in if scenario"""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_in_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(1)
y = Tensor(2)
if x > Tensor(0):
if y > Tensor(1):
return y + 1
return x + 1
return x + y
res = control_flow_if_in_if()
assert res == 3
def test_if_in_if_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(1)
y = Tensor(0)
if x > Tensor(0):
if y > Tensor(1):
return y + 1
return x + 1
return x + y
res = control_flow_if_in_if()
assert res == 2
def test_if_in_if_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(-2)
y = Tensor(-3)
if x > Tensor(0):
if y > Tensor(1):
return y + 1
return x + 1
return x + y
res = control_flow_if_in_if()
assert res == -5
def test_if_in_if_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = np.array([1, 2, 3, 4, 5])
y = x % 2
z = Tensor(y)
if (x >= y).all():
if sum(z) > Tensor(2):
z = Tensor(x) + 1
return z
res = control_flow_if_in_if()
assert np.all(res.asnumpy() == np.array([2, 3, 4, 5, 6]))
def test_if_else_in_if_else_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = Tensor(10)
y = Tensor(7)
if x - y > Tensor(np.array([0])):
x = x - Tensor(3)
if x - y > Tensor(0):
x = x - Tensor(4)
else:
x = x + Tensor(4)
x = x * 2
return x - 1
res = control_flow_if_in_if()
assert res == 21
def test_if_in_if_multi_conds():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_if():
x = np.array([1, 2, 3, 4])
y = np.array([4, 5, 6])
if max(x) <= min(y) and sum(x) == 10:
x += 3
if max(x) <= max(y):
m = Tensor(10)
elif min(x) != max(y) or x.size > y.size:
m = Tensor(20)
else:
m = Tensor(0)
else:
m = Tensor(1)
return m
res = control_flow_if_in_if()
assert res == 20

View File

@ -0,0 +1,60 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow if in while scenario"""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_in_while_built_in_func():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_while():
x = np.array([1, 2, 3, 4])
y = 0
while sum(x) <= 40 and y % 2 == 0:
if min(x) % 2 == 0:
x += 1
else:
x += 3
return Tensor(sum(x))
res = control_flow_if_in_while()
assert res == 42
def test_if_in_while_built_in_func_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_in_while():
x = np.array([1, 2, 3, 4])
while sum(x) <= 40:
if min(x) % 2 == 0:
x += 1
else:
x += 3
if max(x) == 8:
break
return Tensor(sum(x))
res = control_flow_if_in_while()
assert res == 26

View File

@ -0,0 +1,198 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_in_for_tensor_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = Tensor(7)
y = Tensor(0.0)
for _ in range(3):
x = x + y/2
if y < Tensor(10) and x < Tensor(20):
y += x
y += Tensor(1)
return x + y
res = control_flow_for()
assert res == 42
def test_if_in_for_tensor_5():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = Tensor(7)
y = Tensor(0.0)
for _ in range(3):
x = x + y/2
if y < Tensor(10):
y += x
if x < Tensor(15):
x += y/2
y += Tensor(1)
return x + y
res = control_flow_for()
assert res == 62
def test_if_in_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
for _ in range(3):
if sum(x) <= 15:
x += 1
return Tensor(sum(x))
res = control_flow_for()
assert res == 18
def test_if_in_for_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
for _ in range(3):
if sum(x) <= 15:
x += 1
else:
x -= 3
return Tensor(sum(x))
res = control_flow_for()
assert res == 6
def test_if_in_for_numpy_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
for _ in range(3):
if sum(x) <= 15:
x += 2
x -= 1
return Tensor(sum(x))
res = control_flow_for()
assert res == 14
def test_if_in_for_numpy_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = np.array([1])
for _ in range(3):
if sum(x) <= 15:
y += 1
x += y
return Tensor(sum(x) + y)
res = control_flow_for()
assert res == 36
def test_if_in_for_with_break():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = (Tensor(1), Tensor(3), Tensor(5))
a = Tensor(0)
for e in y:
if a > 15:
break
a += Tensor(sum(x)) + e
return a
res = control_flow_for()
assert res == 24
def test_if_in_for_with_continue():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = (Tensor(1), Tensor(3), Tensor(5))
a = Tensor(0)
for e in y:
if a > 15:
continue
a += Tensor(sum(x)) + e
return a
res = control_flow_for()
assert res == 24
def test_if_in_for_with_break_continue():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for():
x = np.array([1, 2, 3, 4])
y = (Tensor(1), Tensor(2), Tensor(4), Tensor(5))
a = Tensor(0)
for e in y:
a += Tensor(sum(x)) + e
if e == Tensor(2):
continue
if a > 15:
a -= Tensor(1)
break
a += Tensor(1)
return a
res = control_flow_for()
assert res == 37

View File

@ -0,0 +1,90 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = np.array([1, 2, 3, 4, 5])
y = np.array([1, 2, 3, 4, 5])
if (x == y).all():
for _ in range(2):
y += x
return Tensor(y)
res = control_flow_for_in_if()
assert np.all(res.asnumpy() == np.array([3, 6, 9, 12, 15]))
def test_for_in_if_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = list((1, 2, 3, 4, 5))
if len(x) == 5:
for _ in range(2):
x.append(10)
return Tensor(x)
res = control_flow_for_in_if()
assert np.all(res.asnumpy() == np.array([1, 2, 3, 4, 5, 10, 10]))
def test_for_in_if_tuple_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = tuple([1, 2, 3, 4, 5])
y = list((0, 1))
if x[4] == 5 and len(y) < 3:
for _ in range(2):
y.append(x[1])
return Tensor(y)
res = control_flow_for_in_if()
assert np.all(res.asnumpy() == np.array([0, 1, 2, 2]))
def test_for_in_if_numpy_list_len_max():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_in_if():
x = np.array([1, 2, 3, 1, 1])
y = list((4, 6, -2))
if len(y) <= max(x):
for i in range(2, 4):
y += x[i]
return Tensor(y)
out = control_flow_for_in_if()
np.all(out.asnumpy() == np.array([9, 11, 3]))

View File

@ -13,18 +13,12 @@
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_in_for_tensor():
"""
Feature: JIT Fallback
@ -45,11 +39,6 @@ def test_for_in_for_tensor():
assert res == 216
@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
def test_for_in_for_tensor_2():
"""
Feature: JIT Fallback
@ -71,11 +60,6 @@ def test_for_in_for_tensor_2():
assert res == 24
@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
def test_for_in_for_numpy():
"""
Feature: JIT Fallback
@ -96,11 +80,6 @@ def test_for_in_for_numpy():
assert out == 27
@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
def test_for_in_for_numpy_2():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,42 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow if after if scenario"""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if():
x = np.array([1, 2, 3, 4])
a = sum(x)
if a > 15:
y = np.array([1, 2, 3, 4])
else:
y = np.array([4, 5, 6])
if np.all(y == np.array([1, 2, 3, 4])):
ret = Tensor(1)
else:
ret = Tensor(2)
return ret
res = control_flow_if_after_if()
assert res == 2

View File

@ -0,0 +1,103 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow if after while scenario"""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = np.array([5, 6])
while sum(x) < 20:
x += 1
y += 1
if max(y) == 9:
return Tensor(sum(y))
y = y - 2
return Tensor(sum(y))
res = control_flow_if_after_while()
assert res == 17
def test_if_after_while_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = np.array([5, 6])
while sum(x) < 20:
x += 1
y += 1
if max(y) == 8:
return Tensor(sum(y))
y = y - 2
return Tensor(sum(y))
res = control_flow_if_after_while()
assert res == 13
def test_if_after_while_tensor_and_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = Tensor(5)
while sum(x) < 20:
x += 1
y += 1
if max(x) == 7:
return y
y = y - 2
return y
res = control_flow_if_after_while()
assert res == 8
def test_if_after_while_tensor_and_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while():
x = np.array([1, 2, 3, 4])
y = Tensor(5)
while sum(x) < 20:
x += 1
y += 1
if max(x) == 6:
return y
y = y - 2
return y
res = control_flow_if_after_while()
assert res == 6

View File

@ -20,11 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_if_after_for_tensor():
"""
Feature: JIT Fallback
@ -45,11 +40,6 @@ def test_if_after_for_tensor():
assert res == 19
@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
def test_if_after_for_tensor_2():
"""
Feature: JIT Fallback
@ -70,11 +60,6 @@ def test_if_after_for_tensor_2():
assert res == 1
@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
def test_if_after_for_tensor_3():
"""
Feature: JIT Fallback
@ -95,11 +80,6 @@ def test_if_after_for_tensor_3():
@pytest.mark.skip(reason="Currently, a can not be parsed in if statement.")
@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
def test_if_after_for_tensor_zip():
"""
Feature: JIT Fallback
@ -121,11 +101,6 @@ def test_if_after_for_tensor_zip():
assert res == 14
@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
def test_single_for_numpy():
"""
Feature: JIT Fallback
@ -145,11 +120,6 @@ def test_single_for_numpy():
assert (res.asnumpy() == [1, 9, 17]).all()
@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
def test_single_for_numpy_2():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,94 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_if_in_if_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_if():
x = Tensor(1)
y = Tensor(10)
z = x + y
if x > Tensor(3):
if y > x:
y += x
else:
z = x * 2
if x + y >= z:
y = y * 2 - x
else:
y = z * 2 - x
return y
res = control_flow_if_after_if_in_if()
assert res == 19
def test_if_after_if_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_if():
x = np.array([1, 3, 5])
y = np.array([1, 3, 5])
z = x + y
if sum(x, 1) > Tensor(3):
x += 1
if (y > x).all():
y += x
else:
z = x * 2
if (x + y >= z).all():
y = y * 2 - x
return Tensor(y)
res = control_flow_if_after_if_in_if()
assert (res.asnumpy() == [0, 2, 4]).all()
def test_if_after_if_in_if_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_if():
x = np.array([1, 3, 5])
y = np.array([1, 3, 5])
if sum(x, 1) > 2:
z = x + y
x += 1
if (y > x - z).all():
y += x
else:
y -= x
else:
z = x * 2
if (x + y >= z).all():
y = y * 2 - x
return Tensor(y)
res = control_flow_if_after_if_in_if()
assert (res.asnumpy() == [4, 10, 16]).all()

View File

@ -0,0 +1,41 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_if_in_while_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_while():
x = Tensor(5)
y = Tensor(2)
z = x - y
while x >= Tensor(3):
if y > x:
y += x
z = x * 2 + y
x -= 2
if x + y >= z:
return y * x - z
return y
res = control_flow_if_after_if_in_while()
assert res == 2

View File

@ -0,0 +1,109 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_if_in_for_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = Tensor(1)
y = Tensor(2)
z = Tensor(0)
for _ in range(3):
if y > x:
y += x
else:
z = x * 2 - y
z = z + Tensor(1)
if x + y >= z:
y = y * x - z
return y
res = control_flow_if_after_if_in_for()
assert res == 4
def test_if_after_if_in_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = Tensor(1)
y = np.array(1)
z = Tensor(0)
tensor_y = Tensor(y)
for _ in range(3):
if tensor_y > x:
z = x * 2 - tensor_y
z = z + Tensor(1)
tensor_y += 2
if x + Tensor(y) >= z:
return tensor_y * x - z
return tensor_y * x + z
res = control_flow_if_after_if_in_for()
assert res == 9
def test_if_after_if_in_for_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = np.array([1, 3, 5, 7])
y = np.array([9, 8, 7, 6])
z = Tensor(1)
for i in range(4):
if x[i] > y[i]:
z = x * 2 - y
y += 2
if (x > y).all():
return Tensor(y * x) - z
return Tensor(y)
res = control_flow_if_after_if_in_for()
assert (res.asnumpy() == [17, 16, 15, 14]).all()
def test_if_after_if_in_for_list():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_if_in_for():
x = [1, 3, 5, 7]
y = [9, 8, 7, 6]
for i in range(4):
if x[i] > y[i]:
y = x * 2
if len(x) < len(y):
return Tensor(x + y)
return Tensor(y)
res = control_flow_if_after_if_in_for()
assert (res.asnumpy() == [1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7]).all()

View File

@ -0,0 +1,66 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_while_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while_in_if():
x = np.array([1])
y = np.array([5])
z = np.array([9])
if z < 6:
while y > x:
y -= x
z = z + np.array([1])
if x + y <= z:
y = y * x - z
return Tensor(y)
res = control_flow_if_after_while_in_if()
assert (res.asnumpy() == [-5]).all()
def test_if_after_while_in_if_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while_in_if():
x = np.array([1])
y = np.array([5])
z = np.array([9])
if z > 6 and x < y:
while y > x:
y -= x
z = z + np.array([1])
x = x + y
if x + y <= z:
y = y * x - z
else:
y = z
return Tensor(y)
res = control_flow_if_after_while_in_if()
assert (res.asnumpy() == [-8]).all()

View File

@ -0,0 +1,39 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_while_in_for_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_while_in_for():
x = np.array([1, 2, 3, 4])
y = np.array([4])
for _ in range(4):
while y > x[0]:
y -= x[1]
if y != 0:
y = y + sum(x)
return Tensor(y)
res = control_flow_if_after_while_in_for()
assert res == 0

View File

@ -0,0 +1,66 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_for_in_if_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_if():
x = Tensor([1])
y = Tensor([2])
z = Tensor([7])
if y > x:
z = Tensor([1])
for _ in range(3):
y -= z
z = x + y
if x + y >= z:
y = y * x - z
else:
y = y * x + z
return y
res = control_flow_if_after_for_in_if()
assert (res.asnumpy() == [-1]).all()
def test_if_after_for_in_if_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_for():
x = np.array([3, 2])
y = Tensor(np.array([0, 2, 4, 6, 8]))
z = Tensor([0])
if 5 in x:
for j in range(5):
y[j] -= j
z = Tensor(x[1] + y[j])
if sum(y) >= z:
z = Tensor(sum(y)) - Tensor([9])
return z
res = control_flow_if_after_for_in_for()
assert res == 11

View File

@ -0,0 +1,62 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_if_after_for_in_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_while():
x = np.array([5, 4, 3, 2, 1])
y = np.zeros(5)
z = np.ones(5)
while sum(x) > y[0]:
for _ in range(3):
y -= 1
x = y + 2
if (x != z).all():
y = y - z[2]
return Tensor(y + z[0])
res = control_flow_if_after_for_in_while()
assert (res.asnumpy() == [-3, -3, -3, -3, -3]).all()
def test_if_after_for_in_while_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_if_after_for_in_while():
x = np.array([5, 4, 3, 2, 1])
y = (Tensor(1), Tensor(3), Tensor(5))
while sum(x) >= 15:
for _ in range(3):
x -= 4
x = x + 2
if sum(y) == 9:
return Tensor(x)
return y[2]
res = control_flow_if_after_for_in_while()
assert (res.asnumpy() == [-5, -6, -7, -8, -9]).all()

View File

@ -20,11 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_if_after_for_in_for_tensor():
"""
Feature: JIT Fallback
@ -49,11 +44,6 @@ def test_if_after_for_in_for_tensor():
assert res == -59
@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
def test_if_after_for_in_for_tensor_2():
"""
Feature: JIT Fallback
@ -75,11 +65,6 @@ def test_if_after_for_in_for_tensor_2():
assert res == -28
@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
def test_if_after_for_in_for_numpy():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,40 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while():
x = [1, 2, 3, 4]
y = Tensor([8])
z = 2
while Tensor([sum(x)]) > y:
x.append(z)
y = Tensor([18])
while y >= 0:
y -= Tensor([x[0]])
return Tensor(x), y
res_x, res_y = control_flow_while_after_while()
assert (res_x.asnumpy() == [1, 2, 3, 4, 2]).all()
assert res_y == -1

View File

@ -0,0 +1,59 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_for_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_for():
x = Tensor([1])
y = Tensor([2])
for _ in range(5):
y = y * x - Tensor([3])
z = y + x
while y > x and x < z:
y -= x
z = z + y
return z
res = control_flow_while_after_for()
assert res == -12
def test_while_after_for_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_for():
x = [1, 2, 3, 4, 5]
y = Tensor([3])
for i in range(4):
x[i] += i
while y >= 0:
y -= Tensor(x[0])
return Tensor(x), y
res_x, res_y = control_flow_while_after_for()
assert (res_x.asnumpy() == [1, 3, 5, 7, 5]).all()
assert res_y == -1

View File

@ -0,0 +1,46 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_if_in_while_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_if_in_while():
x = Tensor([1])
y = Tensor([2])
z = x + y
while x >= y:
if x * y < z:
x = y + z
elif x < y:
x = y - 1
else:
x = y - z
while y > x:
y -= x
z = z + y
return x, y, z
res_x, res_y, res_z = control_flow_while_after_if_in_while()
assert res_x == 1
assert res_y == 1
assert res_z == 4

View File

@ -0,0 +1,41 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_while_in_if_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while_in_if():
x = Tensor([1])
y = Tensor([2])
z = np.array([1]) + np.array([2])
if Tensor(z) >= x + y:
y = y * x + Tensor([3])
while np.array([5]) > z:
z += 1
while y > x:
y -= x
return x, y, Tensor(z)
res = control_flow_while_after_while_in_if()
assert res == (1, 1, 5)

View File

@ -20,11 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_while_after_while_in_while_tensor():
"""
Feature: JIT Fallback
@ -49,11 +44,6 @@ def test_while_after_while_in_while_tensor():
assert res == (2, -3, 1)
@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
def test_while_after_while_in_while_tensor_2():
"""
Feature: JIT Fallback
@ -105,11 +95,6 @@ def test_while_after_while_in_while_numpy():
assert res == (11, 20)
@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
def test_while_after_while_in_while_numpy_2():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,63 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_while_in_for_tensor():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while_in_for():
x = Tensor([1])
y = Tensor([-2])
z = [Tensor([2]), Tensor([4]), Tensor([6])]
for index in z:
while (x * y) > (x + y - index):
x = x + 1
while y >= -x:
y -= x
z = z + y
return x, y, z
res_x, res_y, res_z = control_flow_while_after_while_in_for()
assert res_x == 3
assert res_y == -5
assert (res_z.asnumpy() == [[-3], [-1], [1]]).all()
def test_while_after_while_in_for_tensor_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_while_after_while_in_for():
x = Tensor([1])
y = Tensor([2])
z = [Tensor([2]), Tensor([4]), Tensor([6])]
for index in range(2):
while (x * y) > z[index]:
x = y * x
while y >= x:
y -= x
return x, y
res = control_flow_while_after_while_in_for()
assert res == (1, 0)

View File

@ -0,0 +1,71 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_for_in_while_3():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2313():
x = [1, 2, 3, 4]
y = Tensor([8])
z = 2
while Tensor([sum(x)]) > y:
for _ in range(1):
x.append(z)
y = Tensor([18])
while y >= 0:
y -= Tensor(np.array([x[0]]))
return Tensor(np.array(x)), y
res_x, res_y = func2313()
assert (res_x.asnumpy() == [1, 2, 3, 4, 2]).all()
assert res_y == -1
def test_while_after_for_in_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2314():
x = Tensor([1])
y = Tensor([2])
z = []
while max(x, y) == Tensor([2]):
y = y + min(x, y)
for _ in range(3):
z.append(Tensor([2]))
i = 0
while i < len(z):
x = x * z[i]
i = i + 1
return x
res = func2314()
assert res == 8

View File

@ -0,0 +1,71 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
import mindspore
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_while_after_for_in_for_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2321():
x = Tensor([0])
y = np.array([1])
for _ in range(2):
for _ in range(2):
x = x + 1
i = np.array([1])
while i < 3:
y = y + i
i += 1
return x + Tensor(y, dtype=mindspore.int64)
res = func2321()
assert res == 8
def test_while_after_for_in_for_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func2324():
x = Tensor([0])
for i in range(2):
for j in range(2):
x = x - Tensor([i + j])
z = [np.array([0]), np.array([2]), np.array([2])]
i = 0
while i < len(z):
x = x + Tensor(z[i])
i += 1
return x
res = func2324()
assert res == 0

View File

@ -0,0 +1,62 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_if_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([0])
y = Tensor([0])
if x == y:
x = x + 3
for _ in range(3):
y = y + 1
return x + y
res = func()
assert res == 6
def test_for_after_if_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([1])
y = Tensor([2])
if max(x, y) == Tensor([2]):
x = x + min(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x
res = func()
assert res == 12

View File

@ -0,0 +1,41 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([1])
y = Tensor([2])
while max(x, y) == Tensor([1]):
x = x + min(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x
res = func()
assert res == 6

View File

@ -0,0 +1,63 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
import mindspore
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_for_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([0])
y = np.array([1])
for _ in range(2):
x = x + 1
for i in range(3):
y = y + i
return x + Tensor(y, dtype=mindspore.int64)
res = func()
assert res == 6
def test_for_after_for_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func():
x = Tensor([0])
for i in range(3):
x = x - Tensor([i])
z = (Tensor(0), Tensor(1), Tensor(2))
for i in zip(z):
x = x + i
return x
res = func()
assert res == 0

View File

@ -20,11 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_after_if_in_if_tensor():
"""
Feature: JIT Fallback
@ -50,12 +45,6 @@ def test_for_after_if_in_if_tensor():
assert res == 16
@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
def test_for_after_if_in_if_tensor_2():
"""
Feature: JIT Fallback
@ -82,11 +71,6 @@ def test_for_after_if_in_if_tensor_2():
@pytest.mark.skip(reason='Failed to find parent context.')
@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
def test_for_after_if_in_if_numpy():
"""
Feature: JIT Fallback
@ -112,11 +96,6 @@ def test_for_after_if_in_if_numpy():
@pytest.mark.skip(reason='Not support to get attribute for InterpretObject.')
@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
def test_for_after_if_in_if_numpy_2():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,65 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow for after if in while scenario"""
import pytest
import numpy as np
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_if_in_while_numpy():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_after_if_in_while():
x = np.array([1, 2, 3, 4])
y = np.array([9, 10, 11, 12])
while sum(x) < 20:
x += 2
if max(y) % 2 == 0:
y -= 3
a = Tensor(0)
for i in range(4):
a += Tensor(x[i] - y[i])
return a
res = control_flow_for_after_if_in_while()
assert res == -4
@pytest.mark.skip(reason='Not support to get attribute for InterpretObject.')
def test_for_after_if_in_while_numpy_2():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def control_flow_for_after_if_in_while():
x = np.array([1, 2, 3, 4])
y = np.array([1, 2, 3, 4])
while sum(x) < 20:
x += 1
if max(x) == 7:
break
x += 1
for i in x:
y += i - 20
return sum(y)
res = control_flow_for_after_if_in_while()
assert res == 18

View File

@ -20,11 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_after_if_in_for_tensor():
"""
Feature: JIT Fallback
@ -48,11 +43,6 @@ def test_for_after_if_in_for_tensor():
assert res == 10
@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
def test_for_after_if_in_for_tensor_2():
"""
Feature: JIT Fallback
@ -77,11 +67,6 @@ def test_for_after_if_in_for_tensor_2():
@pytest.mark.skip(reason='Not support to get attribute for InterpretObject.')
@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
def test_for_after_if_in_for_numpy():
"""
Feature: JIT Fallback
@ -105,11 +90,6 @@ def test_for_after_if_in_for_numpy():
@pytest.mark.skip(reason='Not support to get attribute for InterpretObject.')
@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
def test_for_after_if_in_for_numpy_2():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,42 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_while_in_if_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3204():
x = Tensor([1])
y = Tensor([2])
if y - x == Tensor([1]):
while min(x, y) == Tensor([1]):
x = x + min(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x
res = func3204()
assert res == 12

View File

@ -0,0 +1,43 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_while_in_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3214():
x = Tensor([1])
y = Tensor([2])
while max(x, y) == Tensor([2]):
while min(x, y) == Tensor([1]):
x = x - min(x, y)
y = y + max(x, y)
z = (Tensor(1), Tensor(2), Tensor(3))
for i in zip(z):
x = x * i
return x + y
res = func3214()
assert res == 4

View File

@ -20,11 +20,6 @@ from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
@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
def test_for_after_for_in_if_1():
"""
Feature: JIT Fallback
@ -104,11 +99,6 @@ def test_for_after_for_in_if_3():
assert res == 64
@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
def test_for_after_for_in_if_4():
"""
Feature: JIT Fallback

View File

@ -0,0 +1,43 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_for_in_while_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3314():
x = Tensor([1])
y = Tensor([2])
z = []
while max(x, y) == Tensor([2]):
y = y + min(x, y)
for _ in range(3):
z.append(Tensor([2]))
for i in z:
x = x * i
return x
res = func3314()
assert res == 8

View File

@ -0,0 +1,67 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test graph fallback control flow."""
import numpy as np
import mindspore
from mindspore import Tensor, ms_function, context
context.set_context(mode=context.GRAPH_MODE)
def test_for_after_for_in_for_1():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3321():
x = Tensor([0])
y = np.array([1])
for _ in range(2):
for _ in range(2):
x = x + 1
for i in range(3):
y = y + i
return x + Tensor(y, dtype=mindspore.int64)
res = func3321()
assert res == 8
def test_for_after_for_in_for_4():
"""
Feature: JIT Fallback
Description: Test fallback with control flow.
Expectation: No exception.
"""
@ms_function
def func3324():
x = Tensor([0])
for i in range(3):
x = x - Tensor([i])
for j in range(2):
if j == 0 or j == 1: # pylint: disable=consider-using-in
break
z = [np.array([0]), np.array([1]), np.array([2])]
for i in z:
x = x + Tensor(i)
return x
res = func3324()
assert res == 0