diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py b/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py index ab2adc2c4936d..ac5b235430887 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py @@ -148,15 +148,7 @@ def __init__(self, main_program, inputs, outputs, parameters=None, self._origin_main_program = self._verify_program(main_program) self._tmp_scope_vec = self._create_scope_vec() - # 量化单测里调用jit.save时,save接口会整体切换到静态图模式,在save下构建partial_program时,_create_fake_var调用core.eager.Tensor会段错误 - # 1. 询问jiabin看构造eager.Tensor是否可以在静态图下进行 - # 2. _create_fake_var内new Tnesor时主动切换回动态图 - # 3. save接口内,构建partial_progarm时切回动态图 - # 4. 将__init__中new eager.Tensor的相关调用移动到__call__中 - # A fake_var to handle empty input or output - self.__fake_vars = _create_fake_var() # Set default mode to train - self._double_grads = self._get_double_grads(self._origin_main_program) self.training = True custom_white_list, custom_black_list = None, None @@ -168,6 +160,14 @@ def __init__(self, main_program, inputs, outputs, parameters=None, custom_white_list=custom_white_list, custom_black_list=custom_black_list) + @LazyInitialized + def __fake_vars(self): + return _create_fake_var() + + @LazyInitialized + def _double_grads(self): + return self._get_double_grads(self._origin_main_program) + @LazyInitialized def _infer_program(self): """