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

[Typing][B-52] Add type annotations for python/paddle/onnx/export.py #66862

Merged
merged 3 commits into from
Aug 1, 2024

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Jul 31, 2024

PR Category

User Experience

PR Types

Improvements

Description

Copy link

paddle-bot bot commented Jul 31, 2024

你的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.

Comment on lines 34 to 40
class _ConfigsList(TypedDict):
output_spec: NotRequired[list[Tensor]]
with_hook: NotRequired[bool]
combine_params: NotRequired[bool]
clip_extra: NotRequired[bool]
skip_forward: NotRequired[bool]
input_names_after_prune: NotRequired[list[str]]
Copy link
Contributor

Choose a reason for hiding this comment

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

能不能直接用 python/paddle/jit/api.py_SaveOptions

另外,@SigureMo 这个 _SaveOptionsoutput_spec 是不是 Sequence[Tensor | int] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我看了下,不太一样。那个多了个参数skip_prune_program

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddleonnx/utils.py那边:
supported_configs = { "output_spec", "with_hook", "combine_params", "clip_extra", "skip_forward", "input_names_after_prune", }

Copy link
Contributor

Choose a reason for hiding this comment

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

嗯 感觉应该是 paddle2onnx 对齐 paddle

@Zheng-Bicheng 大佬,帮忙看看?!这个 supported_configs 具体有哪些?🫠

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jiang-Jia-Jun 大佬帮忙看看呢?这部分代码不是我写的,我不太了解。

Copy link
Member

Choose a reason for hiding this comment

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

我看了下,不太一样。那个多了个参数skip_prune_program

那个是新增的参数,只不过是 paddle2onnx 没有跟进而已,比如在那之前加的 input_names_after_prune 就跟进在 paddle2onnx 加了,因为当时 CI 挂了,后面的参数 skip_prune_program 估计是因为 CI 也没挂就没人管了

paddle2onnx 加这个检查(paddle_jit_save_configs)基本没啥意义,反而两个 repo 之间协同会麻烦很多,建议删了

这里直接对齐 jit.save 的 Options

Copy link
Member

Choose a reason for hiding this comment

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

这个 _SaveOptions 的 output_spec 是不是 Sequence[Tensor | int] ?

嗯,我改一下

def export(
layer: Layer,
path: str,
input_spec: list[InputSpec | Tensor] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里也可以参考 python/paddle/jit/api.pysave input_spec: Sequence[InputSpec | paddle.Tensor | object] | None = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我看参数说明里写的只有list,没有tuple,也没有python built-in variables

Copy link
Contributor

Choose a reason for hiding this comment

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

整个调用逻辑,最后走的是 paddle.jit.save ,个人感觉以这个为准?

@SigureMo @Zheng-Bicheng 两位大佬怎么看?

Copy link
Contributor

Choose a reason for hiding this comment

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

整个调用逻辑,最后走的是 paddle.jit.save ,个人感觉以这个为准?

大佬,我觉得理论上也应该是这样的,但是最好还是让佳军(@Jiang-Jia-Jun)再确认下,这部分代码应该比较古老了。

@luotao1 luotao1 added contributor External developers HappyOpenSource 快乐开源活动issue与PR labels Jul 31, 2024
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@Jiang-Jia-Jun
Copy link

@Zheng-Bicheng paddle.onnx.export调用了paddle2onnx.convert.dygraph2onnx接口,而后者的实现其实是在内部又调回了paddle.jit.save接口来先动转静,然后再导出为ONNX模型。因此从这里看,这些参数都保持与paddle.jit.save同步更新即可。

Copy link

@Jiang-Jia-Jun Jiang-Jia-Jun left a comment

Choose a reason for hiding this comment

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

LGTM

@SigureMo SigureMo merged commit 753329a into PaddlePaddle:develop Aug 1, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants