Skip to content

matrix_exp API 与 torch 存在精度差异 #76042

@BeingGod

Description

@BeingGod

bug描述 Describe the Bug

matrix_exp API 与 torch 在特定数值下存在精度差异

AI4S 实现 e3nn 库时,在单测中发现 paddle 的 matrix_exp API 与 torch 在特定数值下存在精度差异,导致单测失败。期望能够实现 bitwise equal

版本: paddle==3.2.0, torch==2.8.0+cu126
硬件: H200

复现单测:

import paddle
import torch
import numpy as np

a = np.array([[2.74944162]])
b = np.array([[ 0.        ,  0.        ,  0.99999994],
        [ 0.        ,  0.        ,  0.        ],
        [-0.99999994,  0.        ,  0.        ]])

a_pd = paddle.to_tensor(a).astype(paddle.float32)
b_pd = paddle.to_tensor(b).astype(paddle.float32)

res_pd = paddle.linalg.matrix_exp(a_pd*b_pd)

a_pt = torch.from_numpy(a).to(dtype=torch.float32, device='cpu')
b_pt = torch.from_numpy(b).to(dtype=torch.float32, device='cpu')

res_pt = torch.matrix_exp(a_pt*b_pt)

print(res_pd)
print(res_pt)

np.testing.assert_equal(res_pd.numpy(), res_pt.cpu())

运行结果:

Image

其他补充信息 Additional Supplementary Information

No response

Metadata

Metadata

Labels

PFCCPaddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfccstatus/close已关闭type/bug-report报bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions