Skip to content

solve elementwise_add_grad tenosr copy bug#32095

Closed
thisjiang wants to merge 1 commit intoPaddlePaddle:developfrom
thisjiang:optimize-elementwise_add_grad-checkdims
Closed

solve elementwise_add_grad tenosr copy bug#32095
thisjiang wants to merge 1 commit intoPaddlePaddle:developfrom
thisjiang:optimize-elementwise_add_grad-checkdims

Conversation

@thisjiang
Copy link
Contributor

@thisjiang thisjiang commented Apr 6, 2021

PR types

Bug fixes

PR changes

OPs

Describe

已确认doutdxdy的dimension一定是相同的,问题出在其它地方,已关闭。

前置PR:PR32051

BUG描述:
按之前的逻辑为例:

  1. doutdx的数据地址相同,且doutdy的数据地址不同时,只需拷贝dout中的数据到dy中;
  2. dout的dimension与dy相同时这没有问题,但当两者不同时就出错了:TensorCopy会改变dy的dimension为dout的值,因此会对后续的计算造成影响。

修复方案:
TensorCopy前先检查doutdxdy的dimension是否相同,若相同则进一步根据判断调用TensorCopy,否则直接调用SimpleElemwiseAddGradCUDAKernel

TODO:
使用memory::Copy替代TensorCopy是不是更简单通用?不用在意dimension是否相同,拷贝大小取x->numel() * sizeof(T),这样只需保证dout的大小一定大于等于size即可(后者elementwise的原理可以保证)。

@thisjiang thisjiang closed this Apr 6, 2021
@thisjiang thisjiang deleted the optimize-elementwise_add_grad-checkdims branch April 6, 2021 11:11
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.

1 participant