[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is None
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Lee python/tvm/relax/op/set.py en torno a numpy_unique y compara su salida inversa con el tipo inferido y el contrato en src/relax/op/tensor/set.cc. Empieza ejecutando la reproducción del issue y luego comprueba los casos de ONNX test_unique en tests/python/relax/test_frontend_onnx.py. El objetivo se cumple cuando la inversa para axis=None es unidimensional y tiene longitud x.size, y pasan las pruebas afectadas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Expected behavior
relax.op.unique(x, return_inverse=True) with the default axis=None should return a 1-D int64 inverse of length x.size. For the (2, 2) input below, the inverse should be [2 0 0 1], consistent with the inferred type.
Actual behavior
The VM returns [[2 0] [0 1]] with shape (2, 2). On the default sorted=True path, numpy_unique passes NumPy's inverse through without reshaping it ("numpy.unique already returns 1D inverse_indices, so no reshaping needed"), but since NumPy 2.0 np.unique returns an inverse with the input's shape when axis=None (NumPy 2.4.6 here).
The same mismatch affects the ONNX importer. Running test_unique with --runxfail gives 28 passes and four failures for axis=None with three or four outputs:
RuntimeError: Check failed: input_shape.size() == size (2 vs. 1) : ErrorContext(match_cast, ty=R.Tensor((inverse_numbers,), dtype="int64")) match_cast shape size mismatch.
Found while reading relax.op.unique's runtime (numpy_unique) and comparing it with the inferred type and the set.cc contract; reproduced with the script in this issue through the public API on main at 84657c0 (run on 2026-12-03).
Environment
- Apache TVM
0.28.dev287, built from source at84657c01e5d3(tvm-tirx 0.1.0, tvm-ffi 0.1.16, LLVM 17.0.6) - Debian 12, x86_64, Python 3.11.2, NumPy 2.4.6
- CPU only,
target="llvm"
Steps to reproduce
import numpy as np
import tvm
import tvm_tirx
from tvm import relax
from tvm.relax import script as R
print("tvm", tvm.__version__, "numpy", np.__version__)
x = np.array([[3, 1], [1, 2]], dtype="int64")
bb = relax.BlockBuilder()
v = relax.Var("x", R.Tensor((2, 2), "int64"))
with bb.function("main", [v]):
out = bb.emit(relax.op.unique(v, return_inverse=True))
bb.emit_func_output(out)
mod = bb.get()
print("inferred type:", mod["main"].ret_ty)
vm = relax.VirtualMachine(tvm.compile(mod, target="llvm"), tvm_tirx.cpu())
expected = np.unique(x.ravel(), return_inverse=True)[1]
print("expected inverse (1-D, per the inferred type and ONNX Unique):", expected)
try:
res = vm["main"](tvm_tirx.runtime.tensor(x))
actual = res[1].numpy()
except Exception as e: # noqa: BLE001
raise SystemExit(f"relax.op.unique(return_inverse=True) on a 2-D input failed: {type(e).__name__}: {str(e).strip().splitlines()[-1]}")
print("actual inverse:", actual, "shape", actual.shape)
if actual.shape != expected.shape or not np.array_equal(actual, expected):
raise SystemExit("inverse indices do not match the 1-D result")
print("OK")
Exit code 1. Output combines stdout and stderr, with one LLVM -mcpu fallback diagnostic omitted.
tvm 0.28.dev287 numpy 2.4.6
inferred type: T.Tuple(R.Tensor(dtype="int64", ndim=1), R.Tensor(dtype="int64", ndim=1))
expected inverse (1-D, per the inferred type and ONNX Unique): [2 0 0 1]
actual inverse: [[2 0]
[0 1]] shape (2, 2)
inverse indices do not match the 1-D result
Triage
- needs-triage
- type: bug
- 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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/tvm
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsAbiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 3 días
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsPosiblemente ocupada @pierceluu10 la tomó hace 4 días. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsPosiblemente ocupada @tandede la tomó hace 8 días. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 3 días
-
needs-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/tvm#21043 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
[Bug][Relax][TOPI] RoiAlign mode=max returns the average of the sample pointsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoneeds-triage type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 3 días
Todos los issues de apache/tvm
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
web-push-libs/pywebpush#216 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AgriciDaniel/claude-seo#572 ·
Los mantenedores suelen responder en 5 días
-
area:print-dispatch
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
area: docs domain: technical-writing good first issue type: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Deepak3699/Ai_Mentor#919 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día