[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputs
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 70/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- compilers, machine-learning
Línea de trabajo
Empieza en python/tvm/relax/frontend/onnx/onnx_frontend.py, en el conversor NonZero, donde se construye la forma de salida y rank 0 se asigna a una dimensión inicial de 1. Luego revisa el caso escalar existente en tests/python/relax/test_frontend_onnx.py, que actualmente espera esa forma. Ejecuta el script de reproducción del issue. Terminado cuando una entrada escalar dé una salida (0, N) que coincida con ONNX, y la prueba escalar se actualice para esperarla.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Thanks for participating in the TVM community! We use https://discuss.tvm.apache.org/ for any general usage questions and discussions. The issue tracker is used for actionable items such as feature proposals discussion, roadmaps, and bug tracking. You are always welcomed to post on the forum first 😸
Issues that are inactive for a period of time may get closed. We adopt this policy so that we won't lose track of actionable issues that may fall at the bottom of the pile. Feel free to reopen a new one if you feel there is an additional problem that needs attention when an old one gets closed.
Expected behavior
For a scalar input, ONNX opset 13 defines the output shape of NonZero as (0, N), where N is the number of nonzero elements. For example, a float32 scalar with value 2 should produce an int64 tensor of shape (0, 1). ONNX NonZero-13 specification
Actual behavior
TVM imports and executes the model, but the output has a leading dimension of 1 for both scalar inputs. A downstream ONNX Shape node also returns [1, 1] for scalar 2.
| Input | Expected shape | TVM output shape |
|---|---|---|
| Scalar 0 | (0, 0) | (1, 0) |
| Scalar 2 | (0, 1) | (1, 1) |
| Vector [0] | (1, 0) | (1, 0) |
| Vector [2] | (1, 1) | (1, 1) |
All four models pass ONNX validation. ONNX Runtime and the ONNX Python reference implementation also return the shapes in the TVM column. ONNX Runtime emits an output shape warning for both scalar inputs.
The ONNX converter explicitly maps input rank 0 to 1 when constructing the output shape. The existing scalar frontend test expects this leading dimension of 1. Converter at the tested commit · Scalar test
Environment
- TVM commit
3d89c4991c5a37492f470800231a5ea8f57a95c6, LLVM 21, CPU - Linux x86-64 (WSL2), Python 3.10.22
- ONNX 1.21.0, ONNX Runtime 1.23.2
Steps to reproduce
import numpy as np
import onnx
import tvm_tirx
from onnx import TensorProto, helper
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx
x = np.asarray(2, dtype=np.float32)
graph = helper.make_graph(
[helper.make_node("NonZero", ["X"], ["Y"])],
"scalar_nonzero",
[helper.make_tensor_value_info("X", TensorProto.FLOAT, [])],
[helper.make_tensor_value_info("Y", TensorProto.INT64, ["rank", "count"])],
)
model = helper.make_model(
graph, opset_imports=[helper.make_opsetid("", 13)], ir_version=8
)
onnx.checker.check_model(model, full_check=True)
mod = from_onnx(model, keep_params_in_input=False)
vm = relax.VirtualMachine(relax.build(mod, target="llvm"), tvm_tirx.cpu())
result = vm["main"](tvm_tirx.runtime.tensor(x))
print(result.numpy().shape) # Actual: (1, 1). Expected: (0, 1).
Triage
- needs-triage
- 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] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NonePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
[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
-
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