Skip to content
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

[Dy2Stat]Polish @to_static temporary file directory to speed up transformation #47102

Merged
merged 5 commits into from
Oct 19, 2022

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented Oct 18, 2022

PR types

Function optimization

PR changes

Others

Describe

What's New?

  • 独立了@to_static 的temp 目录
  • 指定了 temp文件的前缀为类似 resnet_forward_xxx.py,便于调试

在 windows Python39 环境下发现 PaddleSeg 某个模型转写特别慢,经过分析发现:发现99.9%的时间都耗费在 ast_to_func函数中的 module = SourceFileLoader(module_name, f.name).load_module() 代码行。
image

经定位是因为windows下会默认把 temp文件写到 C:\Users\Administrator.DESKTOP-xxxxx\AppData\Local\Temp目录,在读取这个目录文件时存在一定的额外开销,可能原因:

  • 此目录是公共目录,可能会被多个进程读取,有锁?
  • 发现开发机器上 Temp下非常多文件,读取时可能会影响性能。

修复方案:在 NamedTemporaryFileAPI 里可以指定 dir 参数,换成其他空目录后,导出就非常快了:
image

@paddle-bot
Copy link

paddle-bot bot commented Oct 18, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@Aurelius84 Aurelius84 changed the title [Dy2Stat]Polish @to_static temporary file directory [Dy2Stat]Polish @to_static temporary file directory to speed up transformation Oct 18, 2022
Copy link
Contributor

@0x45f 0x45f left a comment

Choose a reason for hiding this comment

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

LGTM

@0x45f 0x45f merged commit b3afac8 into PaddlePaddle:develop Oct 19, 2022
Aurelius84 added a commit to Aurelius84/Paddle that referenced this pull request Oct 19, 2022
…formation (PaddlePaddle#47102)

* [Dy2Stat]Polish @to_static temporary file directory

* [Dy2Stat]Polish @to_static temporary file directory

* refine temp.name

* fix typo

* fix typo
lanxianghit pushed a commit that referenced this pull request Oct 19, 2022
…formation (#47102) (#47144)

Polish @to_static temporary file directory to speed up transformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants