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

[fix bug]fix bug for program_converter #60629

Merged
merged 5 commits into from
Jan 17, 2024

Conversation

zyt1024
Copy link
Contributor

@zyt1024 zyt1024 commented Jan 8, 2024

PR types

Bug fixes

PR changes

Others

Description

fix bug for program_converter, #60470

Copy link

paddle-bot bot commented Jan 8, 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 Jan 8, 2024
Copy link

paddle-bot bot commented Jan 8, 2024

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

paddle/fluid/framework/program_converter.cc Outdated Show resolved Hide resolved
@@ -57,6 +60,18 @@ std::pair<bool, std::unordered_map<std::string, uint32_t>> DetectLegacyOps(
program_op_versions.insert(pair);
}

for (const std::string& op_name : convertedOperators) {
if (!current_op_versions.count(op_name)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

这个好像是个废话,这个应该是必然有的吧

// if op_name in current_op_versions and op_name is not in
// program_op_versions, this op_name need to be converted into a new
// program from the old program.
if (!program_op_versions.count(op_name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个更奇怪了,如果load的program_op_versions没有找到这个op,就认为是旧program?如果这个program就是没有这个op呢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果这个program中没有这个op,在here会遍历一下加载的program中的算子,当算子在legacy_op_versions中, 才会执行相应的转换逻辑 ,在前面的处理中,program_op_versions没有找到这个op,相当于先认定这个program是个旧的program了。

if (!legacy_op_versions.count(op_type)) {
        continue;
}

Copy link
Contributor Author

@zyt1024 zyt1024 Jan 9, 2024

Choose a reason for hiding this comment

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

这个更奇怪了,如果load的program_op_versions没有找到这个op,就认为是旧program?如果这个program就是没有这个op呢

另外一个解决是可以在 program_converter.cc#L33 中,也遍历一下加载的program中的算子有哪些( 类似于 program_converter.cc#L307)
当加载的program中有某个算子,但是program中的op_map不存在某个算子,此时一定是legacy_program。

Copy link
Contributor

Choose a reason for hiding this comment

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

program都没有需要转换的op,为什么还要转换呢,可以再梳理一下逻辑
正确的想法应该是这样的

  1. program是旧program,是转2,不是转e2(根据这个 paddle::framework::kLegacyProgramVersion 判断)
  2. program里面有需要转换的op吗,有转3,无转e2
  3. program 有保存这个op的version吗,有的话转4,没有的话转5
  4. 比较这个op的version是否小于等于保存的legacy_op_version, 是转e1, 不是的话continue,所有需要转的都不小于等于转s2
  5. program 有这个op,但是没有这个op的op_version,表示这个是未被修改过的op,默认版本为0,所以可给program op version插入一个0的version记录,转e1
    e1. 是旧program走转换逻辑
    e2. 与转换无关, 不走转换逻辑

is_legacy_program = true;
legacy_op_versions.insert(
std::make_pair(pair.first, program_op_version));
if (program->Version() <= paddle::framework::kLegacyProgramVersion) {
Copy link
Contributor

@GGBond8488 GGBond8488 Jan 11, 2024

Choose a reason for hiding this comment

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

这里需要先判断下,program->version 有没有值,没有的话肯定是旧program,小于的话也是要转换
那么这时候只需要从program里面拿出这些op就行

但是不小于的情况才要去判断op version的版本是不是小于等于我们保存的 legacy_op_version

// is less than current_op_version, the operator also needs to be
// converted.
if (!program_op_versions.count(op_type) ||
program_op_versions[op_type] < current_op_versions[op_type]) {
Copy link
Contributor

@GGBond8488 GGBond8488 Jan 11, 2024

Choose a reason for hiding this comment

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

这个是判断小于current_op_versions 也有点问题,
比如没加复数的assign_value 的op_version 是 0,
加了复数的assign_value 的op_version 是 1,(program 保存的版本)
后续又修改了assign_value, op_version 变成2 ,(当前的版本)
也是 program_op_versions[op_type] < current_op_versions[op_type] 的,
所以这里应该是要小于 保存的 GetLegacyOpVersions 才对

Copy link
Contributor

@GGBond8488 GGBond8488 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants