Fix argsort bug to solve Big Tensor Problem: paddle.nanquantile #73738
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 Category
Operator Mechanism
PR Types
Bug fixes
Description
修复paddle.nanquantile在处理大Tensor问题时出现全零的问题
根本原因是argsort在分段排序时,输出指针未加offset,导致全零,修改后forward与torch精度对齐
backward未与torch对齐,在排查时发现,在生成大tensor数据时,可能生成相同的数据,torch在排序时会出现不稳定的情况,paddle是稳定排序,分析如下
测试API为
paddle.nanquantile(Tensor([325957340, 7],"float32"), q=0.5, axis=1, )输入数据的某一列如下
在排序后0.5的分位数为0.09138859
input[0]和input[2]数据相同,都为0.5的分位数,稳定排序后分位数应该是input[0]对应的数据,所以对应的梯度回传的位置应该是input[0], 查看paddle计算的梯度(p) 和torch计算的梯度(t)如下可见paddle回传梯度到了
input[0]的位置,而torch回传梯度到了input[2]的位置,所以torch的内置排序是不稳定的,paddle结果是对的