Skip to content

Conversation

@pesionzhao
Copy link
Contributor

@pesionzhao pesionzhao commented Jul 1, 2025

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, )

输入数据的某一列如下

image

在排序后0.5的分位数为0.09138859

input[0]input[2]数据相同,都为0.5的分位数,稳定排序后分位数应该是input[0]对应的数据,所以对应的梯度回传的位置应该是input[0], 查看paddle计算的梯度(p) 和torch计算的梯度(t)如下

image

可见paddle回传梯度到了input[0]的位置,而torch回传梯度到了input[2]的位置,所以torch的内置排序是不稳定的,paddle结果是对的

@paddle-bot
Copy link

paddle-bot bot commented Jul 1, 2025

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

@paddle-bot paddle-bot bot added the contributor External developers label Jul 1, 2025
@pesionzhao pesionzhao changed the title Fix argsort bug to solve Big Tensor Problem in paddle.quanile Fix argsort bug to solve Big Tensor Problem: paddle.nanquantile Jul 1, 2025
Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

LGTM 这个API没有大Tensor问题吗?再找书豪把把关

@lshpku lshpku merged commit 8b5f720 into PaddlePaddle:develop Jul 2, 2025
54 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

3 participants