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

[BugFix]Fix set_attr modify underly type #47500

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented Oct 31, 2022

PR types

Bug fixes

PR changes

Others

Describe

修复了当保存的模型包含一些反向算子时(如batch_norm_grad),在 _inference_optimize 函数修改 is_test 属性会导致其 attr_type 错误地由 BOOL 变成 INT,会导致预测执行时报错。

Pybind11 在似乎会将 Python端的True以 Int的形式传递给 C++ 后端。但我看了OpDesc::SetAttr 是包含这部分处理逻辑的,但前向算子是生效的,反向算子似乎没有按照预期生效,为了统一解决,这里修改为显式地调用_set_bool_attr:

// OpDesc::SetAttr函数实现

  // In order to set bool attr properly
  if (attr_type == proto::AttrType::INT) {
    if (HasProtoAttr(name) &&
        GetProtoAttr(name).type() == proto::AttrType::BOOLEAN) {
      attrs_ptr->operator[](name) = static_cast<bool>(PADDLE_GET_CONST(int, v));
      need_update_ = true;
      return;
    }

@paddle-bot
Copy link

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

Copy link
Contributor

@zhiqiu zhiqiu 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

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

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

LGTM

@Aurelius84 Aurelius84 merged commit e6a6b0f into PaddlePaddle:develop Nov 1, 2022
Aurelius84 added a commit to Aurelius84/Paddle that referenced this pull request Nov 2, 2022
XiaoguangHu01 pushed a commit that referenced this pull request Nov 7, 2022
* Fix set_attr modify underly type (#47500)

* reformat code

* Revert "reformat code"

This reverts commit f11a5d7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants