diff --git a/python/paddle/fluid/io.py b/python/paddle/fluid/io.py index b9b172dbb8b67012bcbe99018eb4f83dc723687f..fbc84be2a06140b9337413daa931d4e99553d7a4 100644 --- a/python/paddle/fluid/io.py +++ b/python/paddle/fluid/io.py @@ -191,7 +191,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): 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):