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

add IndexPutGradInfermeta to fix backward error in static-mode #55602

Merged

Conversation

zoooo0820
Copy link
Contributor

@zoooo0820 zoooo0820 commented Jul 21, 2023

PR types

Bug fixes

PR changes

OPs

Description

Card-73285
Since the auto-generated code is different between dynamic and static mode, Grad OP index_put_grad works fine in dynamic mode but raises error in static mode.

I0720 12:47:08.784021  8805 op_call_stack.cc:62] InvalidArgumentError: shape of value can't not be broadcast to shape of x[indices] (at /paddle/Paddle/paddle/phi/kernels/funcs/index_put_utils.h:286)
Traceback (most recent call last):
  File "test_index_put_grad.py", line 50, in <module>
    res = exe.run(fetch_list=[z, x.grad_name, value.grad_name])
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/executor.py", line 1444, in run
    use_prune=use_prune,
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/executor.py", line 1669, in _run_impl
    ret = new_exe.run(list(feed.keys()), return_numpy)
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/executor.py", line 684, in run
    tensors = self._new_exe.run(feed_names)._move_to_list()
ValueError: In user code:

    File "test_index_put_grad.py", line 44, in <module>
      z  = paddle.index_put(y, (index1,), value)
    File "/usr/local/lib/python3.7/dist-packages/paddle/tensor/manipulation.py", line 4918, in index_put
      attrs={'accumulate': accumulate},
    File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/layer_helper.py", line 45, in append_op
      return self.main_program.current_block().append_op(*args, **kwargs)
    File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py", line 4033, in append_op
      attrs=kwargs.get("attrs", None),
    File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py", line 2795, in __init__
      for frame in traceback.extract_stack():

    InvalidArgumentError: shape of value can't not be broadcast to shape of x[indices] (at /paddle/Paddle/paddle/phi/kernels/funcs/index_put_utils.h:286)
      [operator < index_put_grad > error]

The essence of the problem is in GeneralBinaryGradInferMeta , the second input (indices[0]) is used incorrectly in the static graph mode, resulting in error size of value_grad. This PR fixes this by adding IndexPutGradInferMeta.

@paddle-bot
Copy link

paddle-bot bot commented Jul 21, 2023

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

@Courtesy-Xs Courtesy-Xs 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

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

LGTM

@jeff41404 jeff41404 merged commit 76530a2 into PaddlePaddle:develop Jul 24, 2023
27 checks passed
@zoooo0820 zoooo0820 deleted the fix_index_put_all_false_case branch July 24, 2023 10:31
wz1qqx pushed a commit to wz1qqx/Paddle that referenced this pull request Jul 31, 2023
…ePaddle#55602)

* add IndexPutGradInfermeta to fix backward error in static-mode

* codestyle
jinjidejinmuyan pushed a commit to jinjidejinmuyan/Paddle that referenced this pull request Aug 30, 2023
…ePaddle#55602)

* add IndexPutGradInfermeta to fix backward error in static-mode

* codestyle
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.

None yet

4 participants