diff --git a/python/paddle/fluid/io.py b/python/paddle/fluid/io.py index 3e32c4ec55ec52f70c129194c3d90110f09db31c..fadd247e0df37877a43f80eb0a7cd74c7d36abca 100644 --- a/python/paddle/fluid/io.py +++ b/python/paddle/fluid/io.py @@ -198,7 +198,8 @@ def _load_program_scope(main=None, startup=None, scope=None): with paddle.fluid.scope_guard(scope): with paddle.fluid.program_guard(prog, startup_prog): with paddle.fluid.unique_name.guard(): - yield + with paddle.fluid.framework._dygraph_guard(None): + yield def _get_valid_program(main_program): @@ -663,7 +664,6 @@ def save_persistables(executor, dirname, main_program=None, filename=None): filename=filename) -@dygraph_not_support def load_vars(executor, dirname, main_program=None, @@ -1830,7 +1830,6 @@ def load(program, model_path, executor=None, var_list=None): set_var(v, load_dict[v.name]) -@dygraph_not_support def load_program_state(model_path, var_list=None): """ :api_attr: Static Graph diff --git a/python/paddle/fluid/tests/unittests/test_static_save_load.py b/python/paddle/fluid/tests/unittests/test_static_save_load.py index ac61ab756f06e5142ffae3e913b722ba6ef93dc2..72c992234335dd712395bd31ec7d07d04b5395f5 100644 --- a/python/paddle/fluid/tests/unittests/test_static_save_load.py +++ b/python/paddle/fluid/tests/unittests/test_static_save_load.py @@ -1153,7 +1153,6 @@ class TestProgramStateOldSave(unittest.TestCase): # make sure all the paramerter or optimizer var have been set to zero self.assertTrue(np.sum(np.abs(new_t)) == 0) - #fluid.load(test_program, "./test_1", None ) program_state = fluid.load_program_state("test_program_1") fluid.set_program_state(main_program, program_state) @@ -1164,6 +1163,11 @@ class TestProgramStateOldSave(unittest.TestCase): base_t = base_map[var.name] self.assertTrue(np.array_equal(new_t, base_t)) + with fluid.dygraph.guard(place): + load_state = fluid.load_program_state("test_program_1") + for k, v in load_state.items(): + self.assertTrue(np.array_equal(base_map[k], v)) + class TestProgramStateOldSaveSingleModel(unittest.TestCase): def test_ptb_rnn_cpu_float32(self):