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

add a wrap_decorator decorator to keep the __doc__ attr #45773

Merged

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Sep 5, 2022

PR types

Bug fixes

PR changes

Others

Describe

try to fix the missing docstring of paddle.jit.save, the details describe in PaddlePaddle/docs#5243 (comment)

目前通过 paddle.jit.save.__doc__ 无法获取到 docstring,原因是装饰器没有传递内层函数的 __doc__ 属性

@_run_save_pre_hooks
@switch_to_static_graph
def save(layer, path, input_spec=None, **configs):
"""
Saves input Layer or function as ``paddle.jit.TranslatedLayer``
format model, which can be used for inference or fine-tuning after loading.

其中 switch_to_static_graph 已经使用 wrap_decorator 装饰过,因此不会造成 __doc__ 等属性的丢失,而 _run_save_pre_hooks 没有,因此使用 wrap_decorator 装饰下,尝试下效果

@paddle-bot
Copy link

paddle-bot bot commented Sep 5, 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.

@SigureMo
Copy link
Member Author

SigureMo commented Sep 5, 2022

本地编译 wheels 安装测试,修改前后的效果如下:

before after
Jupyter Notebook image image
REPL help function image image
__doc__ attribute image image

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

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

LGTM

@YuanRisheng YuanRisheng merged commit fd86a93 into PaddlePaddle:develop Sep 6, 2022
@SigureMo SigureMo deleted the try-fix-some-missing-docstring branch September 6, 2022 08:57
Caozhou1995 pushed a commit to Caozhou1995/Paddle that referenced this pull request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants