[Bug][Relax][PyTorch] `grid_sample` returns the wrong shape and values after `from_exported_program`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 62/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- compilers, machine-learning
Hướng nghiên cứu
Start with the PyTorch importer's _grid_sampler_2d converter, which is reached through from_exported_program, and compare its grid argument with what relax.op.image.grid_sample expects. Run the two reproduction cases from the issue: the 1x1x4x4 input with a 1x3x5x2 grid, and the 2x2 grid. Done means the TVM output shape and values match eager PyTorch in both cases.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Expected behavior
For a grid of shape [N, H, W, 2], F.grid_sample returns [N, C, H, W]. The model converted with from_exported_program should give the same shape and values as eager.
Actual behavior
TVM returns the wrong shape, with no error or warning. With a 2 x 2 grid the shape happens to be right, but the values are wrong.
eager: torch.Size([1, 1, 3, 5])
tvm: (1, 1, 5, 2)
eager: [[[[2.5, 4.5], [10.5, 12.5]]]]
tvm: [[[[2.5, 10.5], [12.5, 10.5]]]]
Possibly _grid_sampler_2d passes PyTorch's [N, H, W, 2] grid directly, while relax.op.image.grid_sample works on [N, 2, H, W].
Environment
- TVM: main @
2bf0532(0.28.dev0), built from source, targetllvm - PyTorch: 2.12.0+cu130
- Python: 3.12, Ubuntu x86_64
Steps to reproduce
import torch
import tvm
import tvm_tirx
from tvm import relax
from tvm.relax.frontend.torch import from_exported_program
class M(torch.nn.Module):
def forward(self, x, grid):
return torch.nn.functional.grid_sample(x, grid, align_corners=False)
x = torch.arange(16, dtype=torch.float32).reshape(1, 1, 4, 4)
grid = torch.zeros(1, 3, 5, 2)
print("eager:", M()(x, grid).shape)
ep = torch.export.export(M(), (x, grid))
mod = from_exported_program(ep)
ex = tvm.compile(mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm_tirx.cpu())
out = vm["main"](tvm_tirx.runtime.tensor(x.numpy()), tvm_tirx.runtime.tensor(grid.numpy()))
print("tvm: ", out[0].numpy().shape)
# A 2 x 2 grid has the right shape by accident, but the values are wrong
grid = torch.tensor([[[[-0.5, -0.5], [0.5, -0.5]], [[-0.5, 0.5], [0.5, 0.5]]]])
print("eager:", M()(x, grid).tolist())
ep = torch.export.export(M(), (x, grid))
mod = from_exported_program(ep)
ex = tvm.compile(mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm_tirx.cpu())
out = vm["main"](tvm_tirx.runtime.tensor(x.numpy()), tvm_tirx.runtime.tensor(grid.numpy()))
print("tvm: ", out[0].numpy().tolist())
- Ngôn ngữ chính
- Python
- Star
- 13.9k
- Fork
- 4k
- Merge trung bình
- 8 giờ 5 phút
- Pull request đã merge (30 ngày)
- 170
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/tvm
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] [Relax][ONNX] OneHot does not convert floating-point depth to int64Có thể đã có người làm @tandede đã nhận 2 ngày trước. Đang mởneeds-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug][Relax] ReorderTakeAfterMatmul fails on vector dot productsCó thể đã có người làm @hiyufan đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/tvm#20595 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
aws-samples/sample-per-model-bedrock#782 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Google text documents are base64-encoded twiceCó thể đã có người làm @feiiiiii5 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
coveragepy/coveragepy#2364 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Plugin] astrbot_plugin_sd_drawĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100