diff --git a/mindspore/ccsrc/pipeline/jit/action.cc b/mindspore/ccsrc/pipeline/jit/action.cc index 230d4ca7ae..7902f643e8 100644 --- a/mindspore/ccsrc/pipeline/jit/action.cc +++ b/mindspore/ccsrc/pipeline/jit/action.cc @@ -1242,6 +1242,12 @@ std::vector BackendPipeline() { return actions; } std::vector MindIRPipeline() { + auto context_ptr = MsContext::GetInstance(); + if (context_ptr->get_param(MS_CTX_EXECUTION_MODE) == kPynativeMode) { + MS_LOG(EXCEPTION) + << "The graph generated form MindIR is not support to execute in the PynativeMode, please convert " + "to the GraphMode."; + } std::vector actions; // Set funcGraph loaded from MindIR to resource. (void)actions.emplace_back(std::make_pair("load_mindir", SetMindIRGraphAction)); diff --git a/mindspore/python/mindspore/train/serialization.py b/mindspore/python/mindspore/train/serialization.py index f5cdfba206..24d8b126be 100644 --- a/mindspore/python/mindspore/train/serialization.py +++ b/mindspore/python/mindspore/train/serialization.py @@ -972,6 +972,8 @@ def _spilt_save(net_dict, model, file_name, is_encrypt, **kwargs): def _save_mindir(net, file_name, *inputs, **kwargs): """Save MindIR format file.""" + if context._get_mode() == context.PYNATIVE_MODE: + raise RuntimeError("MindIR export is not support in the Pynative mode, please convert to the Graph Mode.") model = mindir_model() phase_name = "predict" if net._auto_parallel_mode else "export.mindir" diff --git a/tests/st/control/test_while_mindir.py b/tests/st/control/test_while_mindir.py index efaca20c8a..941ea5346b 100644 --- a/tests/st/control/test_while_mindir.py +++ b/tests/st/control/test_while_mindir.py @@ -52,12 +52,13 @@ def test_single_while(): outputs_after_load = loaded_net(x, y) assert origin_out == outputs_after_load + @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training @pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard def test_ms_function_while(): - context.set_context(mode=context.PYNATIVE_MODE) + context.set_context(mode=context.GRAPH_MODE) network = SingleWhileNet() x = Tensor(np.array([1]).astype(np.float32)) @@ -71,10 +72,13 @@ def test_ms_function_while(): graph = load(mindir_name) loaded_net = nn.GraphCell(graph) + context.set_context(mode=context.PYNATIVE_MODE) + @ms_function def run_graph(x, y): outputs = loaded_net(x, y) return outputs + outputs_after_load = run_graph(x, y) assert origin_out == outputs_after_load @@ -122,6 +126,7 @@ def test_single_while_inline_load(): assert os.path.exists(mindir_name) load(mindir_name) + @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training @pytest.mark.platform_arm_ascend_training diff --git a/tests/st/export_and_load/test_bgcf.py b/tests/st/export_and_load/test_bgcf.py index 8f9785d0d7..6947b1c3da 100644 --- a/tests/st/export_and_load/test_bgcf.py +++ b/tests/st/export_and_load/test_bgcf.py @@ -196,6 +196,7 @@ class ForwardBGCF(nn.Cell): @pytest.mark.platform_arm_ascend_training @pytest.mark.env_onecard def test_export_bgcf(): + context.set_context(mode=context.GRAPH_MODE) num_user, num_item = 7068, 3570 network = BGCF([64, num_user, num_item], 64, "tanh", [0.0, 0.0, 0.0], num_user, num_item, 64) diff --git a/tests/st/export_and_load/test_get_and_init_graph_cell_parameters.py b/tests/st/export_and_load/test_get_and_init_graph_cell_parameters.py index 351f4013b7..f6b952b0cc 100644 --- a/tests/st/export_and_load/test_get_and_init_graph_cell_parameters.py +++ b/tests/st/export_and_load/test_get_and_init_graph_cell_parameters.py @@ -94,18 +94,3 @@ def test_get_and_init_graph_cell_parameters_in_graph_mode(): """ context.set_context(mode=context.GRAPH_MODE) get_and_init_graph_cell_parameters() - - -@pytest.mark.level0 -@pytest.mark.platform_x86_cpu -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.platform_x86_gpu_training -@pytest.mark.env_onecard -def test_get_and_init_graph_cell_parameters_in_pynative_mode(): - """ - Description: load mind ir and update parameters in pynative mode. - Expectation: generate a graph with updated parameters. - """ - context.set_context(mode=context.PYNATIVE_MODE) - get_and_init_graph_cell_parameters() diff --git a/tests/ut/python/mindir/test_init_graph_cell_parameters_with_illegal_data.py b/tests/ut/python/mindir/test_init_graph_cell_parameters_with_illegal_data.py index c6cc8863ae..20aaecd675 100644 --- a/tests/ut/python/mindir/test_init_graph_cell_parameters_with_illegal_data.py +++ b/tests/ut/python/mindir/test_init_graph_cell_parameters_with_illegal_data.py @@ -99,7 +99,7 @@ def test_init_graph_cell_parameters_with_wrong_value_shape(): Description: load mind ir and update parameters with wrong tensor shape. Expectation: raise a ValueError indicating the update value shape error. """ - context.set_context(mode=context.PYNATIVE_MODE) + context.set_context(mode=context.GRAPH_MODE) net = Net() mindir_name = "net_2.mindir" export(net, input_a, input_b, file_name=mindir_name[:-7], file_format='MINDIR')