Skip to content

upgrade the TraceLayer.save_inference_model method with add file suffix automatically#31989

Merged
zhhsplendid merged 2 commits intoPaddlePaddle:developfrom
CtfGo:fix-TraceLayer-save
Apr 7, 2021
Merged

upgrade the TraceLayer.save_inference_model method with add file suffix automatically#31989
zhhsplendid merged 2 commits intoPaddlePaddle:developfrom
CtfGo:fix-TraceLayer-save

Conversation

@CtfGo
Copy link
Contributor

@CtfGo CtfGo commented Mar 31, 2021

PR types

Bug fixes

PR changes

APIs

Describe

update the TraceLayer.save_inference_model method:
(1) change the param "dirname" to "path" to indicate it is a path prefix of the saved model, and update docs
(2) save the program and params on the path with ".pdmodel" and ".pdiparams" suffix seperately

@CLAassistant
Copy link

CLAassistant commented Mar 31, 2021

CLA assistant check
All committers have signed the CLA.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@CtfGo CtfGo force-pushed the fix-TraceLayer-save branch from a7e7783 to 6e350c1 Compare March 31, 2021 11:42
@CtfGo CtfGo force-pushed the fix-TraceLayer-save branch from 6e350c1 to 92ccb86 Compare March 31, 2021 11:56
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

这个更改了一个参数名,dirname -> path,可能会造成2.1和2.0在使用了这个API的部分场景中不兼容,但我个人支持做不兼容修改,有几方面原因:

  1. 目前paddle存储多个结果的save load接口全局都统一成存储后缀的形式了,这个接口属于漏网之鱼,有必要统一
  2. dirname这个名字表意明确,与前缀的含义不兼容,更改为path更加通用,长远看比较好
  3. 2.1和2.0属于大版本不同,少量不兼容问题也合理
  4. 这个接口是低频接口,使用场景不多,而且参数位置也没有改变,只要用户没有明确使用参数名,就可以继续使用

仅代表个人看法,具体还需要 @lanxianghit @jzhang533 @XiaoguangHu01 看一下

Copy link

@saxon-zh saxon-zh left a comment

Choose a reason for hiding this comment

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

LGTM


def setUp(self):
self.save_path = "./nonexist_dir/fc"
import shutil
Copy link
Member

Choose a reason for hiding this comment

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

NIT (Not Important): However, since it is not so important and this PR needs many approves. I will approve it and you can change in next PR.

Python officially suggests to put imports at top of file, I think you should follow it in your case.
https://www.python.org/dev/peps/pep-0008/#imports

image

Let me explain my understanding of the pros and cons of importing at top of a file or in a function.

Importing at top of a file:

  1. More consistent with other programming language.
  2. We group imports all together and easy to organize

There are several cases I think we can import in a function:

  1. Conditional import, e.g.
if something:
    import xxx
  1. You would like your function code to work correctly after copy the function code to other file (other file may not contain that import)

But I don't think here we meet the cases for importing in a function :-) so I would suggest to import at the top.

fc_layer = SimpleFCLayer(3, 4, 2)
input_var = paddle.to_tensor(np.random.random([4, 3]).astype('float32'))
with fluid.dygraph.guard():
dygraph_out, traced_layer = fluid.dygraph.TracedLayer.trace(
Copy link
Member

Choose a reason for hiding this comment

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

We should write new test cases for Paddle 2.0 path. So fluid.dygraph.TracedLayer should be changed to paddle.jit.TracedLayer. However, since it is not so important and this PR needs many approves. I will approve it and you can change in next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestion,I will change these two in next pr.

@CtfGo CtfGo changed the title update the TraceLayer.save_inference_model method with add file suffix automatically, test=develop update the TraceLayer.save_inference_model method with add file suffix automatically Apr 7, 2021
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhhsplendid zhhsplendid merged commit 10af966 into PaddlePaddle:develop Apr 7, 2021
@CtfGo CtfGo deleted the fix-TraceLayer-save branch April 7, 2021 08:40
@CtfGo CtfGo changed the title update the TraceLayer.save_inference_model method with add file suffix automatically upgrade the TraceLayer.save_inference_model method with add file suffix automatically Dec 13, 2021
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.

7 participants