[Bug] [Relax][ONNX] OneHot does not convert floating-point depth to int64

Aperta Adatta ai principianti
#20,895 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@tandede ci sta già lavorando.

Dal 4/11/2026.

  • #20908 di @tandede — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia in python/tvm/relax/frontend/onnx/onnx_frontend.py, dal convertitore OneHot collegato nell’issue, e confronta come gestisce le profondità intere e in virgola mobile. Esegui la riproduzione fornita con un’installazione di TVM abilitata per LLVM; il lavoro è terminato quando entrambi i tipi di profondità vengono convertiti e producono l’output previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-triage type: bug
Expected behavior

OneHot-11 permits floating-point depth and requires converting it to int64 before use. Depth 3.0 should behave like int64 3.

Actual behavior

The int64-depth control executes correctly. Changing only depth to float32 fails during conversion:

TypeError: Cannot convert from type `float` to `int`

The converter passes the result of depth.value.numpy().tolist() directly as num_classes. The final Cast keeps the output dtype explicit.

Environment

TVM 0.28.dev0, LLVM 18.1.3, Linux x86_64; Python 3.12.3, NumPy 2.5.4, ONNX 1.22.0, ORT 1.29.0. The installed binary build revision is unknown; current main was inspected statically, not rebuilt.

Steps to reproduce

Run with an LLVM-enabled TVM installation:

import numpy as np
import onnx
import tvm
from onnx import TensorProto as T, helper as h, numpy_helper as nh
from onnx.reference import ReferenceEvaluator
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx

x = np.array([0, 2], dtype="int64")
expected = np.array([[1, 0, 0], [0, 0, 1]], dtype="float32")
for depth_dtype in ("int64", "float32"):
    model = h.make_model(h.make_graph([
        h.make_node("OneHot", ["x", "depth", "values"], ["raw"]),
        h.make_node("Cast", ["raw"], ["y"], to=T.FLOAT)], "onehot",
        [h.make_tensor_value_info("x", T.INT64, [2])],
        [h.make_tensor_value_info("y", T.FLOAT, [2, 3])],
        [nh.from_array(np.array(3, dtype=depth_dtype), "depth"),
         nh.from_array(np.array([0, 1], dtype="float32"), "values")]),
        opset_imports=[h.make_opsetid("", 11)], ir_version=10)
    onnx.checker.check_model(model, full_check=True)
    np.testing.assert_array_equal(ReferenceEvaluator(model).run(None, {"x": x})[0], expected)
    try:
        mod = from_onnx(model, keep_params_in_input=False)
        vm = relax.VirtualMachine(relax.build(mod, target="llvm"), tvm.cpu())
        np.testing.assert_array_equal(vm["main"](tvm.runtime.tensor(x)).numpy(), expected)
        print(depth_dtype, "control passed")
    except Exception as error:
        if depth_dtype == "int64":
            raise
        print(depth_dtype, type(error).__name__, str(error).splitlines()[-1])
Triage
  • needs-triage
Lingua principale
Python
Stelle
13.9k
Fork
4k
Merge medio
8h 2m
PR unite (30g)
180

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/tvm

Tutte le issue di apache/tvm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.