Skip to content
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

grid_sample 输出结果与torch的不一致 #58907

Closed
zhiminzhang0830 opened this issue Nov 10, 2023 · 3 comments
Closed

grid_sample 输出结果与torch的不一致 #58907

zhiminzhang0830 opened this issue Nov 10, 2023 · 3 comments
Assignees

Comments

@zhiminzhang0830
Copy link
Contributor

zhiminzhang0830 commented Nov 10, 2023

相同的输入数据条件下,paddle和torch的grid_sample输出结果不一致,diff 为13。

gpu diff: 13.0
cpu diff: 13.0

import paddle
import numpy as np
import torch

input = np.load('input.npy')
grid = np.load('vgrid.npy')

# paddle cpu
cpu_place = paddle.CPUPlace()
input_paddle = paddle.to_tensor(input, place=cpu_place)
grid_paddle = paddle.to_tensor(grid, place=cpu_place)
output_paddle = paddle.nn.functional.grid_sample(
        x=input_paddle, grid=grid_paddle, padding_mode='border', mode='nearest', align_corners=True
    )
# paddle gpu
input_paddle = paddle.to_tensor(input)
grid_paddle = paddle.to_tensor(grid)
output_paddle_gpu = paddle.nn.functional.grid_sample(
        x=input_paddle, grid=grid_paddle, padding_mode='border', mode='nearest', align_corners=True
    )



# torch cpu
input_torch = torch.from_numpy(input)
grid_torch = torch.from_numpy(grid)
output_torch = torch.nn.functional.grid_sample(input_torch, grid_torch,  padding_mode='border', mode='nearest', align_corners=True)

# torch gpu
device = torch.device('cuda:0')
input_torch = torch.from_numpy(input).to(device)
grid_torch = torch.from_numpy(grid).to(device)
output_torch_gpu = torch.nn.functional.grid_sample(input_torch, grid_torch,  padding_mode='border', mode='nearest', align_corners=True)

diff = abs(output_torch_gpu.cpu().numpy() - output_paddle_gpu.cpu().numpy()).max()
print(' gpu diff:', diff)

diff = abs(output_torch.numpy() - output_paddle.cpu().numpy()).max()
print(' cpu diff:', diff)

其他补充信息 Additional Supplementary Information

torch版本:1.12.1
paddle版本:2.5.2
input.npy 和 vgrid.npy 可以从此处下载

@wangna11BD
Copy link
Contributor

升级torch版本至2.1.0,可以对齐~

@AndSonder
Copy link
Contributor

AndSonder commented Dec 5, 2023

@zhiminzhang0830 @wangna11BD 可以请问一下为什么无法和torch 2.1.0 之前的结果对齐吗,我在给 openvino 支持 paddle2.5.1 的时候也遇到了这个问题 当 padding_mode='border' 的时候,有时候 grid_sample 的值无法和 openvino 端输出的值对齐,在 openvino 中 paddle 和 torch 对于 grid_sample 这个算子的写法是一样的,torch 就可以通过相关单侧

Copy link

paddle-bot bot commented Dec 17, 2024

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants