Skip to content

Commit

Permalink
make __fake_vars and _double_grads to lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
0x45f committed Mar 11, 2022
1 parent f67c798 commit 3ec7dda
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down

1 comment on commit 3ec7dda

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 3ec7dda Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ CI failures summary

🔍 PR: #40355 Commit ID: 3ec7dda contains failed CI.

🔹 Failed: PR-CI-APPROVAL

Unknown Failed
2022-03-11 10:57:50 警告: 证书通用名 “.bcebos.com” 与所要求的主机名 “sys-p0.bj.bcebos.com” 不符。
2022-03-11 10:57:50 已发出 HTTP 请求,正在等待回应... 200 OK
2022-03-11 10:57:50 长度:87 [application/octet-stream]
2022-03-11 10:57:50 正在保存至: “block.txt”
2022-03-11 10:57:50 0K 100% 47.6M=0s
2022-03-11 10:57:50 2022-03-11 10:57:50 (47.6 MB/s) - 已保存 “block.txt” [87/87])
2022-03-11 10:57:50 --2022-03-11 10:57:50-- https://sys-p0.bj.bcebos.com/bk-ci/bk.txt
2022-03-11 10:57:50 正在解析主机 sys-p0.bj.bcebos.com... 182.61.200.195, 182.61.200.229, 2409:8c04:1001:1002:0:ff:b001:368a
2022-03-11 10:57:50 正在连接 sys-p0.bj.bcebos.com|182.61.200.195|:443... 已连接。
2022-03-11 10:57:50 警告: 证书通用名 “
.bcebos.com” 与所要求的主机名 “sys-p0.bj.bcebos.com” 不符。
2022-03-11 10:57:50 已发出 HTTP 请求,正在等待回应... 200 OK
2022-03-11 10:57:50 长度:5 [application/octet-stream]
2022-03-11 10:57:50 正在保存至: “bk.txt”
2022-03-11 10:57:50 0K 100% 4.48M=0s
2022-03-11 10:57:50 2022-03-11 10:57:50 (4.48 MB/s) - 已保存 “bk.txt” [5/5])
2022-03-11 10:57:57 ****************
2022-03-11 10:57:57 0. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1,qili93) approval for the usage of const_cast.
2022-03-11 10:57:57 There are 1 approved errors.
2022-03-11 10:57:57 ****************

Please sign in to comment.