-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Dynamically bind dtype #62508
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
… fix the dtype check in `monkey_patch_math_tensor.py` to also consider `core.DataType` in addition to `core.VarDesc.VarType`.
…move unnecessary code
Fixes an issue where the comparison of variable dtypes was incorrect in the `monkey_patch_tensor` function. The comparison now correctly checks the dtype of the variable.
…de, dtype should always be DataType
…type conversion cause a cache miss error
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下面这个分支里的逻辑,后续可以考虑抽离成一个函数,避免if-for的多层嵌套
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类型。
通过将动态图切分成 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