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

Abierto
#20,906 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
66/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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())
Lenguaje dominante
Python
Estrellas
13.9k
Forks
4.1k
Merge medio
4 d 22 h
PR fusionados (30 d)
22

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/tvm

Todos los issues de apache/tvm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.