-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Precision Depth Alignment] Add support for CUDNN to paddle.nn.functional.grid_sample to align with torch accuracy. #75355
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
[Precision Depth Alignment] Add support for CUDNN to paddle.nn.functional.grid_sample to align with torch accuracy. #75355
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
wanghuancoder
left a comment
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
zrr1999
left a comment
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
A-nnonymous
left a comment
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.
possible type related issues
| cudnn_dtype, | ||
| static_cast<int>(N), | ||
| static_cast<int>(C), | ||
| static_cast<int>(H_in), |
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.
这里的NCHW,是否涉及到类型收窄?前面声明时采用的可是int64_t,超过2147483647时怎么办?
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.
要求加一个溢出判断,或者将声明时的数据类型直接限制为int32_t
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.
前面 if 判断中使用了 canUse32bitIndexMath 进行了 int32 的限制,超过int32 将不会进入该分支中,所以不会出现溢出的情况。
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
| cudnn_dtype, | ||
| static_cast<int>(N), | ||
| static_cast<int>(C), | ||
| static_cast<int>(H_in), |
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
…onal.grid_sample to align with torch accuracy. (PaddlePaddle#75355) * accuracy_stable_grid_sample * fix
…onal.grid_sample to align with torch accuracy. (PaddlePaddle#75355) * accuracy_stable_grid_sample * fix
* CallScalarFunction uses the dtype of 'self' as the type of 'other' when opotype is 'div'(#75237) * LinspaceKernel uses the dtype of 'self' as the type of 'step' when tensor is floating (#75238) * align LinspaceKernel * update meta * update gpu kernel * fix LinspaceKernelInner * improve kernel * fix CudaSigmoidGradFunctor and CudaSiluGradFunctor (#75341) * Softplus accuracy and torch alignment 1 (#75363) * [Precision Depth Alignment] paddle.tan reverse calculation: dx = dout *(1 + tan(x)^2) (#75335) * Tan reverse calculation: dx = dout *(1 + tan(x)^2) * [Precision Depth Alignment] Add support for CUDNN to paddle.nn.functional.grid_sample to align with torch accuracy. (#75355) * accuracy_stable_grid_sample * fix * correlation supports big tensor (#75383) * fix * fix test * fix * paddle.tanh Grad and torch alignment (float16) (#75454) * [Precision Depth Alignment] paddle.sin and paddle.cos aligns with torch precision. (#75503) * accuracy_stable_sin * accuracy_stable_cos * [深度对齐]Divide (#75379) * fix * fix * fix * fix * fix * [Precision Depth Alignment] fix precision for float16 of paddle.tan backward (#75525) * fix precision for float16 of paddle.tan backward * fix else branch of CudaTanGradFunctor * [Precision Depth Alignment] fix precision for paddle.expm1 (#75549) * accuracy_stable_expm1 * fix * Bigtensor排查修复[Paddle/paddle/phi/kernels/funcs] (#75523) * fix * fix * [Precision Depth Alignment] fix beta and threshold of paddle.nn.functional.softplus to double (#75426) * fix beta and threshold of Softplus to double * fix test_softplus_activation_fuse_pass v1 * fix test_activation_zero * fix flaot of SoftplusDoubleGradKernel to double * add op_patches for softplus * add yaml for ops/yaml/legacy * fix infershape/operator for FLOAT64 * fix * add SoftPlusOpTranscriber * fix * fix * fix1 * fix2 * fix coverage * fix coverage2 * fix (#75605) * [深度对齐] dot (#75717) * fix * fix * fix dcu * [Precision Depth Alignment] paddle.log aligns with torch precision (#75799) * accuracy_stable_log * accuracy_stable_log * fix * fix * fix * fix * fix5 * [Precision Depth Alignment] fix eps of paddle.logit from float to double (#75816) * accuracy_stable_logit * add LogitOpTranscriber * fix coverage * fix 0yaml * [Precision Depth Alignment] paddle.log_sigmoid (#75898) * accuracy_stable_log_sigmoid * fix test_activation_stride_op.py * [Precision Depth Alignment] Modify the negative_slope parameter of the paddle.nn.functional.leaky_relu API to double (#75547) * [big tensor] Paddle/paddle/phi/kernels/funcs gpuBigtensor (#75856) * fix funcs * gpu * fix * fix * 修改PADDLE_ENFORCE信息 * fix cpu error * fix dcu * fix dcu * fix * [Fix] log sigmoid complex (#75953) * feature: Add specialized LogSigmoidFunctor and CudaLogSigmoidFunctor for complex numbers This commit introduces specialized implementations of LogSigmoidFunctor and CudaLogSigmoidFunctor to handle complex number inputs. The new implementations utilize direct formulas for improved accuracy and stability in calculations involving complex types. * refactor: Optimize LogSigmoidFunctor and CudaLogSigmoidFunctor for complex types by caching exp(-x) to reduce redundant computations. This change enhances performance while maintaining accuracy in calculations. * refactor: modified the formula in LogSigmoidFunctor to make it numerical stable --------- Co-authored-by: Zhan Rongrui <46243324+zrr1999@users.noreply.github.com> Co-authored-by: 正在学习 <62892980+cszdrg@users.noreply.github.com> Co-authored-by: Bvicii <98971614+scyyh11@users.noreply.github.com>
PR Category
Operator Mechanism
PR Types
New features
Description
背景说明
在
padding_mode == zeros且mode == bilinear且align_corners == true的配置下,Paddle 的原始实现与 PyTorch 存在一定数值差异。通过调用 cuDNN 提供的Spatial TransformerAPI,可以在该配置下与 PyTorch 实现精度对齐。该逻辑通过
condCudnnGridSampler<T>进行适配判断,确保仅在支持的设备和数据类型(如 float / double)下调用 cuDNN。本 PR 对
grid_sample在 GPU 上的实现进行了优化与精度对齐处理。当满足以下特定条件时:padding_mode == zerosmode == bilinearalign_corners == truecondCudnnGridSampler<T>(x, grid) == true(即当前环境支持调用 cuDNN 的 grid sampler)将启用 cuDNN 的
cudnnSpatialTfSamplerForward和cudnnSpatialTfSamplerBackward接口来计算前向和反向传播,以提高性能并与 PyTorch 在该配置下的行为保持数值一致性。主要改动
✅ 前向部分
在
phi::grid_sample前向实现中增加判断逻辑,当满足上述条件时:x_desc与y_descst_desccudnnSpatialTfSamplerForward实现 bilinear 采样x_desc/y_desc/st_desc)✅ 反向部分
在反向传播中增加相应逻辑:
x_desc/dx_desc/y_desc描述符st_desccudnnSpatialTfSamplerBackward计算dx和dgrid测试
【前向】:与torch完全对齐。(195个case)
【反向】:存在atomicAdd,在并行计算时,原子操作先后顺序不同导致了结果的随机性。(torch运行两次,都无法对齐)
pcard-67164