diff --git a/python/oneflow/test/modules/test_consistent_0_dim_tensor.py b/python/oneflow/test/modules/test_consistent_0_dim_tensor.py index 5d7923c1ce4..18f4fc9fedc 100644 --- a/python/oneflow/test/modules/test_consistent_0_dim_tensor.py +++ b/python/oneflow/test/modules/test_consistent_0_dim_tensor.py @@ -20,7 +20,7 @@ from oneflow.test_utils.automated_test_util import * -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def _test_0_dim_tensor(test_case, placement, sbp): x1 = random_tensor(0).to_global(placement=placement, sbp=sbp) x2 = random_tensor(0).to_global(placement=placement, sbp=sbp) @@ -29,7 +29,7 @@ def _test_0_dim_tensor(test_case, placement, sbp): return y1 + y2 -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def _test_1dim_slice(test_case, placement, sbp): x = random_tensor(1, random(1, 4) * 8).to_global(placement=placement, sbp=sbp) return x[5] diff --git a/python/oneflow/test/modules/test_consistent_abs.py b/python/oneflow/test/modules/test_consistent_abs.py index 3ec8c2348da..be11cd0a3e6 100644 --- a/python/oneflow/test/modules/test_consistent_abs.py +++ b/python/oneflow/test/modules/test_consistent_abs.py @@ -21,7 +21,7 @@ import oneflow.unittest -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def _test_abs_with_ndim_data(test_case, ndim, placement, sbp): dims = [random(1, 3) * 8 for i in range(ndim)] x = random_tensor(ndim, *dims).to_global(placement=placement, sbp=sbp) diff --git a/python/oneflow/test/modules/test_consistent_adaptive_pool.py b/python/oneflow/test/modules/test_consistent_adaptive_pool.py index 89f90a2d675..54d3b36cbae 100644 --- a/python/oneflow/test/modules/test_consistent_adaptive_pool.py +++ b/python/oneflow/test/modules/test_consistent_adaptive_pool.py @@ -31,7 +31,7 @@ ] -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def _test_adaptive_avgpoolnd(test_case, ndim, pool_size, placement, sbp): dims = [random(1, 3) * 8 for i in range(ndim)] x = random_tensor(ndim, *dims).to_global(placement=placement, sbp=sbp) @@ -48,7 +48,7 @@ def _test_adaptive_avgpoolnd(test_case, ndim, pool_size, placement, sbp): return y -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def _test_adaptive_avgpoolnd_functional(test_case, ndim, pool_size, placement, sbp): dims = [random(1, 3) * 8 for i in range(ndim)] x = random_tensor(ndim, *dims).to_global(placement=placement, sbp=sbp) diff --git a/python/oneflow/test/modules/test_consistent_chunk.py b/python/oneflow/test/modules/test_consistent_chunk.py index a17a8d14e9f..992c9b346a2 100644 --- a/python/oneflow/test/modules/test_consistent_chunk.py +++ b/python/oneflow/test/modules/test_consistent_chunk.py @@ -21,7 +21,7 @@ from oneflow.test_utils.automated_test_util import * -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def _test_chunk(test_case, ndim, placement, sbp): dims = [random(1, 3).to(int) * 8 for _ in range(ndim)] x = random_tensor(ndim, *dims).to_global(placement=placement, sbp=sbp) diff --git a/python/oneflow/test/modules/test_consistent_diag.py b/python/oneflow/test/modules/test_consistent_diag.py index d7b0e47433c..a46da1065de 100644 --- a/python/oneflow/test/modules/test_consistent_diag.py +++ b/python/oneflow/test/modules/test_consistent_diag.py @@ -22,7 +22,7 @@ from oneflow.test_utils.automated_test_util import * -@autotest(n=1, check_graph=False) +@autotest(n=1, check_graph=True) def do_test_diag_impl(test_case, ndim, placement, sbp): dims = [random(1, 4) * 8 for i in range(ndim)] x = random_tensor(ndim, *dims) diff --git a/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py b/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py index 159ad0a8d47..ac305c994b3 100644 --- a/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py +++ b/python/oneflow/test_utils/automated_test_util/torch_flow_dual_object.py @@ -292,6 +292,15 @@ def get_fake_program_more_detail(oneflow, mode, func, args=None, kwargs=None): print("\n\n") +# NOTE(lixiang): When the graph global test is executed, the func is used to get the device type. +# There is no oneflow_kwargs["device"] case for graph global test. +def get_global_test_device(oneflow_args): + if isinstance(oneflow_args[0], flow.Tensor): + return oneflow_args[0].placement.type + else: + return oneflow_args[0][0].placement.type + + # NOTE(lixiang): When oneflow is of type nn.Module, build the following Graph for testing. # graph_train_oneflow: is a deepcopy of oneflow. def get_module_graph_test(graph_train_oneflow, oneflow, verbose, oneflow_args, *args): @@ -382,6 +391,9 @@ def build(self): elif oneflow.__name__ == "Parameter": # nn.Graph donot deal with Parameter creation. test_g_res = oneflow_res + # When doing the global op test, get_global_test_device() will be executed, and temporarily skipping the graph autotest on cpu device. + elif is_global() and (get_global_test_device(oneflow_args) == "cpu"): + test_g_res = oneflow_res else: test_g = TestGraphOfFunctional() test_g_res = test_g() @@ -422,8 +434,12 @@ def build(self): return graph_tensor_oneflow(*tensor_graph_args, **tensor_graph_kwargs) try: - test_g = TestGraphOfTensorMethod() - test_g_res = test_g() + # Set test_g_res = None, check_eager_graph_tensor will return True, the purpose is to temporarily skip the Graph global test on cpu. + if is_global() and (get_global_test_device((oneflow,)) == "cpu"): + test_g_res = None + else: + test_g = TestGraphOfTensorMethod() + test_g_res = test_g() except Exception as e: if not verbose: get_fake_program_more_detail( @@ -479,8 +495,12 @@ def oneflow_eager_run_with_graph_check( test_g = get_module_graph_test( graph_train_oneflow, oneflow, verbose, oneflow_args, *args ) - # When testing module methods, kwargs are not considered. - test_g_res = test_g(*graph_args) + # When doing the global op test, get_global_test_device() will be executed, and temporarily skipping the graph autotest on cpu device. + if is_global() and (get_global_test_device(oneflow_args) == "cpu"): + test_g_res = oneflow_res + else: + # When testing module methods, kwargs are not considered. + test_g_res = test_g(*graph_args) elif oneflow.__name__ in ignore_apis_list: find_check_module_func = False # 1. "oneflow.nn.modules" not in oneflow.__module__: For avoid run nn.Module branch graph test, like fold op call Fold Module actually.