[XPU] Fix precision for paddle.Tensor.__truediv__ complex number operations#78950
Open
YqGe585 wants to merge 1 commit into
Open
[XPU] Fix precision for paddle.Tensor.__truediv__ complex number operations#78950YqGe585 wants to merge 1 commit into
YqGe585 wants to merge 1 commit into
Conversation
…ide/divide_grad and complex128 cast kernels Add XPU kernel support for complex number division operations: 1. DivideKernel<complex64,XPUContext>: implement complex division via real/imag decomposition using float-level XPU APIs, since XPU lacks native complex64 broadcast_div. 2. DivideGradKernel<complex64,XPUContext>: implement complex division gradients (dx = dout/conj(y), dy = -dout*conj(out/y)) using real/imag decomposition with ExpandGradKernel for broadcasting. 3. CastKernel<complex128,XPUContext> and COMPLEX128 case in CastKernel switch: enable float64->complex128 and float32->complex128 casting needed for type promotion when float64 and complex64 are combined. All changes gated by PADDLE_WITH_XPU_FFT compile flag, following the pattern established by existing complex64 specializations in add/multiply kernels. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
你的PR提交成功,感谢你对开源项目的贡献! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fix XPU precision for
paddle.Tensor.__truediv__complex number division operations. Three originally failing cases on XPU are now resolved:bool / complex(0,2)— AccuracyError where XPU output differed from GPUfloat64 / complex64— PaddleError where XPU kernel threw errorcomplex64 / float64— PaddleError where XPU kernel threw errorRoot cause: XPU lacked kernel support for complex number division and casting operations. Three fixes were applied:
DivideKernel<complex64,XPUContext>
Implemented complex division via real/imag decomposition using float-level XPU APIs, since XPU lacks native
broadcast_div<complex64>. Formula: (a+bi)/(c+di) = ((ac+bd)/(c²+d²)) + ((bc-ad)/(c²+d²))i. This fixes thefloat64/complex64andcomplex64/float64PaddleError cases.DivideGradKernel<complex64,XPUContext>
Implemented complex division gradients (dx = dout/conj(y), dy = -dout*conj(out/y)) via real/imag decomposition with ExpandGradKernel for broadcasting. This fixes the
bool/complex(0,2)AccuracyError case.CastKernel<complex128,XPUContext> + COMPLEX128 case
Enabled float64→complex128 and float32→complex128 casting needed for type promotion when float64 and complex64 are combined. Added both the COMPLEX128 case in the CastKernel switch and a CastKernel specialization that extracts real part and delegates to CastKernel.
All changes are gated by
PADDLE_WITH_XPU_FFTcompile flag, following the pattern established by existing complex64 specializations in add/multiply kernels.Modified files:
paddle/phi/kernels/xpu/elementwise_divide_kernel.cc(+57 lines)paddle/phi/kernels/xpu/elementwise_divide_grad_kernel.cc(+158 lines)paddle/phi/kernels/xpu/cast_kernel.cc(+40 lines)Does this PR introduce a precision change?
Yes — XPU precision for complex number division operations now aligns with GPU/CPU behavior.