[PHI] Fix paddle.linalg.det for big tensor #73996
Merged
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.linalg.det反向报错问题:在输入有奇异矩阵时发生:

问题定位:
paddle.linalg.det的梯度计算采用以下公式:直接通过矩阵逆运算实现,但奇异矩阵不可逆($\text{det}(A)=0$ , $A^{-\text{T}}$ 不存在)导致计算失败。理论上,奇异矩阵的梯度应采用伴随矩阵 $\text{adj}(A)$ 直接计算。
此外,
FoundZeroFunctor直接进行零值判定,未考虑浮点数计算的误差,导致大量奇异矩阵被误判断为非奇异矩阵。解决方案:
epsilon阈值,if避免写入竞争:phi::Multiply运算提升为MPType,并通过分块{}减少内存占用后续修复:
本修复仅解决反向报错问题。如果输入均为非奇异矩阵,测试全部通过:
paddle.linalg.detinput from random to non-singular PFCCLab/PaddleAPITest#357如果需要完美计算奇异矩阵,算法需进行非常大调整,该工作将在
paddle.linalg.lu支持复数功能后进行:paddle.linalg.lu#73885