-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dy2St] optimize print
function convertor to display Tensor at compile time
#48672
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
你的PR提交成功,感谢你对开源项目的贡献! |
SigureMo
changed the title
[Dy2St] refactor convert_print to display Tensor in compile time
[WIP][Dy2St] refactor convert_print to display Tensor in compile time
Dec 2, 2022
SigureMo
force-pushed
the
dy2st/frontend/print
branch
from
December 2, 2022 12:22
461d19f
to
896c6d4
Compare
SigureMo
changed the title
[WIP][Dy2St] refactor convert_print to display Tensor in compile time
[WIP][Dy2St] refactor Dec 2, 2022
convert_print
to display Tensor at compile time
SigureMo
changed the title
[WIP][Dy2St] refactor
[Dy2St] refactor Dec 3, 2022
convert_print
to display Tensor at compile timeconvert_print
to display Tensor at compile time
SigureMo
changed the title
[Dy2St] refactor
[Dy2St] optimize Dec 3, 2022
convert_print
to display Tensor at compile timeprint
function to display Tensor at compile time
SigureMo
changed the title
[Dy2St] optimize
[Dy2St] optimize Dec 4, 2022
print
function to display Tensor at compile timeprint
function convertor to display Tensor at compile time
0x45f
approved these changes
Dec 5, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lxsbupt
pushed a commit
to lxsbupt/Paddle
that referenced
this pull request
Dec 17, 2022
…ile time (PaddlePaddle#48672) * [Dy2St] refactor convert_print to display Tensor in compile time
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Function optimization
PR changes
Others
Describe
完成动转静功能扩展和旧接口退场1中的「
优化 PrintTransformer 功能优化 print 函数动转静效果」kwargs
,应该没啥问题<frozen importlib._bootstrap>:283: DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead
,见 replace deprecatedload_module
withexec_module
#48679convert_print
的原始行为是组网(编译)阶段仅仅打印非 Tensor 参数,而执行阶段仅仅打印 Tensor 参数,本 PR 修改后在组网阶段也打印了 Tensor 参数另外组网阶段原始行为是遍历各个参数分别调用
print
函数,这样不仅无法支持sep
、end
等关键字参数,而且与动态图行为差异很大,每个参数都会换一下行,本 PR 直接调用一次print
函数,以使其与动态图行为基本一致,同时也支持了sep
、end
等关键字参数由于在 Python2
print
是语句而不是函数,而在 Python3 中是函数,因此曾经利用PrintTransformer
来分别对两种 AST node 进行了 transform,最后都转写成_jst.Print(arg1, arg2, ...)
,而现在 Paddle 已经不支持 Python22,可以保证print
一定是函数,故无需专门的PrintTransformer
来进行处理,直接利用CallTransformer
转写成_jst.Call(print)(arg1, arg2, ...)
之后在组网阶段交给convert_call
处理即可(类似convert_enumerate
等 built-in 函数的处理),因此用于转写的PrintTransformer
可以移除,转写后的_jst.Print
也无需再暴露此外对单测
test_print
做了若干修改:declarative
->to_static
PrintTransformer
了,AST 的处理与其余函数是一致的下面是修改前后的效果对比:
代码:
修改前:
修改后:
Footnotes
[Dy2St] Dygraph to Static function extension tracking issue #48334 ↩
[CodeStyle] Legacy python code cleanup tracking issue #46837 ↩