[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"

未关闭
#20,906 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, pytorch
领域
compilers

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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())
主要语言
Python
星标
13.9k
派生
4.1k
平均合并
4 天 22 小时
30 天内合并 PR
22

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/tvm 的其他 Issue

查看 apache/tvm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。