-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Accuracy diff No.43-44] Accuracy grid sample #74555
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
[Accuracy diff No.43-44] Accuracy grid sample #74555
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #74555 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 3
Lines ? 105
Branches ? 0
===========================================
Hits ? 105
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/re-run all-failed |
PR Category
Execute Infrastructure
PR Types
Improvements
Description
精度问题描述:
问题定位与分析:
【4D精度测试】

【5D精度测试】

【float32精度问题 & 实验分析 -> 合理】
上面精度修复已经对grid sample的计算流程进行修复,但是在测试过程发现,当使用 paddle.nn.functional.grid_sample(Tensor([100, 1, 176, 176],"float32"), Tensor([100, 1, 37632, 2],"float32"), align_corners=False, ) shape,并且 grid tensor元素为 -0.2670455 时,cpu 与 torch 反向精度会出现不对齐。最后发现时float32浮点数计算精度舍入导致的,符合理论预期。下面是实验分析过程:
计算误差代码:
当 grid_slice_t = -0.2670455 ,max_val = 175时,上面代码的使用理论计算应该为63.999996,但是上面数据类型是float32时,计算结果为64.000000,代码后面使用floor()进行位置计算,torch在当前数据下ix = 63,而paddle cpu的ix = 64,从而出现了精度误差。这个时候大家都会想到提升精度到double计算,然后再调用floor()计算位置,这个方法有尝试过,实验结果显示,使用double后,上面 grid_slice_t = -0.2670455 时是对齐了。但是 grid_slice_t = -0.41477278时,double的计算结果为50.9999954,floor()后为50,而torch的计算结果为51.000000,floor()后为51,还是不能对齐。怀疑是float32浮点数运算精度舍入导致。
为了进一步验证计算流程的正确性,将上面出现精度误差的实验数据的类型全部转换成float64,paddle与torch结果完全对齐。
使用float64后的反向计算结果:
pcard-67164