[Bug][Relax] `x[i] = v` on a 2-D tensor fails in `from_exported_program`: "IndexPut requires the number of index tensors to match the data tensor dimensions"

Đang mở
#20,906 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 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
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch
Lĩnh vực
compilers

Hướng nghiên cứu

Start in the Relax PyTorch frontend path that converts exported index_put operations; the issue identifies _index_put and relax.op.index_put as likely points to inspect. Compare how the frontend represents missing dimensions for x[i] = v with the operator’s index requirements, then run the reproduction and check that the converted result matches eager PyTorch for the listed indexing cases.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

needs-triage type: bug
Expected behavior

x[i] = v writes the rows i of a 2-D tensor. It is valid in eager and torch.export, so from_exported_program should convert it.

Actual behavior

The conversion fails. The same happens for x[i, :] = v, x[[0, 0]] += ..., index_fill and index_copy, i.e. whenever fewer index tensors than dimensions are given. A 1-D tensor, one index tensor per dimension, or a leading slice (x[:, i] = v) work.

eager: [[1.0, 1.0], [0.0, 0.0], [1.0, 1.0]]
ValueError: IndexPut requires the number of index tensors (1) to match the data tensor dimensions (2)

Possibly _index_put passes the index list from x[i] = v on as is, while relax.op.index_put requires one index tensor per dimension.

Environment
  • TVM: main @ 2bf0532 (0.28.dev0), built from source, target llvm
  • 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, i, v):
        x[i] = v
        return x


x = torch.zeros(3, 2)
i = torch.tensor([0, 2])
v = torch.ones(2, 2)
print("eager:", M()(x.clone(), i, v).tolist())

ep = torch.export.export(M(), (x, i, v))
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(t.numpy()) for t in (x, i, v)])
print("tvm:  ", out[0].numpy().tolist())
Ngôn ngữ chính
Python
Star
13.9k
Fork
4.1k
Merge trung bình
4 ngày 22 giờ
Pull request đã merge (30 ngày)
22

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/tvm

Tất cả issue của apache/tvm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.