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

Dynamically bind dtype #62508

Merged
merged 26 commits into from
Mar 13, 2024
Merged

Dynamically bind dtype #62508

merged 26 commits into from
Mar 13, 2024

Conversation

zrr1999
Copy link
Member

@zrr1999 zrr1999 commented Mar 7, 2024

PR types

Others

PR changes

Others

Description

目前框架内有两套dtype的表示,一套是老静态图的VarType,一套是PIR下的DataType。动态图在c++端底层的dtype都是DataType,但是之前应该是为了兼容,所以动态图python的dtype也还是VarType类型。

这个pr主要是想修改python端的paddle.dtype,在PIR下paddle.dtype返回的是DataType类型;在老静态图下返回的是VarType类型。

dtype drawio

通过将动态图切分成 PIR 和非 PIR 模式,以确保在任何一种情况下 dtype 都是动静统一的,以免添加众多繁杂的转换、特殊处理逻辑,在不久的将来,左侧的 not use_pir_api 场景就可以完全废弃掉了

Important

本 PR 主要影响是在开启 FLAGS_enable_pir_api=True 场景下动态图的行为(含动转静),当然,CI 上目前没有这种测试(除动转静单测,动转静单测整体还是跑在动态图下,因此会测到部分动态图相关逻辑),因此测试可能是不全面的,这就需要未来去逐渐针对适配升级,不过当前 PR 已经手动在部分 Seg、Detection 模型上测试开启 FLAGS_enable_pir_api=True 通过,更多的场景可能需要在合入后联动「SOT+PIR」模型测试一同测试和修复(就目前经验而言,这类问题修复非常快)

参考 #62146

Copy link

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

@paddle-bot paddle-bot bot added the contributor External developers label Mar 7, 2024
@0x45f 0x45f self-assigned this Mar 7, 2024
… fix the dtype check in `monkey_patch_math_tensor.py` to also consider `core.DataType` in addition to `core.VarDesc.VarType`.
Comment on lines +860 to +863
if (var_tensor->IsType<paddle::framework::Vocab>()) {
return ToPyObject(phi::DataType::UNDEFINED);
} else if (var_tensor->IsType<paddle::framework::Strings>()) {
return ToPyObject(phi::DataType::PSTRING);
Copy link
Contributor

Choose a reason for hiding this comment

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

PR的修改对当前的代码执行应该是没有影响,不过当前pir下的DataType里并没有RAW和STRING类型,需要讨论确认在动态图模式下,此修改对相关模型执行的影响

return ToPyObject(framework::proto::VarType::RAW);
} else if (var_tensor->IsType<paddle::framework::Strings>()) {
return ToPyObject(framework::proto::VarType::STRING);
if (FLAGS_enable_pir_api) {
Copy link
Contributor

Choose a reason for hiding this comment

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

下面这个分支里的逻辑,后续可以考虑抽离成一个函数,避免if-for的多层嵌套

@0x45f 0x45f merged commit 5171897 into PaddlePaddle:develop Mar 13, 2024
30 checks passed
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.

6 participants