【NPU】Add TensorCopy to NPU kernel for reduce_sum op #31666
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
OPs
Describe
PR #31620 为
reduce_sum
op 添加了 NPU Kernel。问题
NPU Kernel 实现中,求反向,创建临时Tensor时,未对该临时Tensor赋值。会导致reduce_sum op的反向计算错误,观察到错误的梯度全部为0。
修复
这个PR修复了这个问题,使用TensorCopy,将grad_out的值赋值给创建的临时变量。
反向计算错误时单测通过的原因
![图片](https://user-images.githubusercontent.com/26408901/111298639-eecd3700-8689-11eb-9111-01998a6e3158.png)
因为组网时,reduce_sum前面的网络中没有任何参数,即使reduce_sum导致梯度计算错误,也不会影响参数更新。