[Bug][Relax][ONNX] IsInf ignores detect_negative and detect_positive
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Il bug è nel convertitore del frontend ONNX per IsInf, che mappa direttamente su relax.op.isinf e ignora gli attributi detect_negative e detect_positive. Parti da quel convertitore nel frontend Relax ONNX e leggi gli attributi, poi costruisci il risultato da isinf combinato con controlli di segno. Esegui il repro.py allegato sulle tre combinazioni di attributi; fatto significa che ogni combinazione corrisponde all'output di ONNX Runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Description
ONNX IsInf has detect_negative (default 1) and detect_positive (default 1) attributes selecting which infinities are reported. The converter calls relax.op.isinf and drops both attributes.
Expected Behavior
x = [1, +inf, -inf, 0] must produce [0,1,0,0] for detect_negative=0, [0,0,1,0] for detect_positive=0 and [0,0,0,0] when both are 0, matching onnxruntime.
Actual Behavior
The output is always [0,1,1,0]: every attribute combination behaves like the defaults.
Real-world Impact & Practical Relevance
IsInf with a single detection direction is used to build masks for +inf/-inf separately (e.g. masking only negative infinities before a max/softmax). Both masks becoming the same changes the model semantics.
Environment
- Apache TVM:
0.27.0.post1(PyPI wheel, published 2026-09-29); the buggy code path is unchanged onmainat3d89c4991c5a37492f470800231a5ea8f57a95c6(2026-11-22, static inspection). - OS / Python: Ubuntu 22.04.5 / Python 3.10.12, LLVM CPU target.
- onnx 1.13.1, onnxruntime 1.20.0, NumPy 1.26.4.
Steps to Reproduce
Save the following as repro.py and run python repro.py (exit status 1
means the bug is reproduced):
#!/usr/bin/env python3
"""BUG-0103 -- [Relax ONNX frontend] IsInf ignores detect_negative / detect_positive.
ONNX IsInf has attributes detect_negative (default 1) and detect_positive
(default 1) selecting which infinities are reported. The converter maps
straight to relax.op.isinf and drops both attributes, so the output always
equals "is +inf or -inf".
Exit status: 0 if TVM matches ONNX Runtime for every attribute combination,
1 if the bug is reproduced.
Run: python repro.py [--target llvm]
"""
import argparse
import os
os.environ.update({k: "1" for k in ("OMP_NUM_THREADS", "MKL_NUM_THREADS",
"OPENBLAS_NUM_THREADS", "TVM_NUM_THREADS")})
import numpy as np
import onnx
import onnxruntime as ort
import tvm
from onnx import TensorProto as T
from onnx import helper
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx
def vi(name, dt, shape):
return helper.make_tensor_value_info(name, dt, shape)
def make_model(nodes, inputs, outputs, inits=(), opset=17):
g = helper.make_graph(nodes, "g", inputs, outputs, initializer=list(inits))
m = helper.make_model(g, opset_imports=[helper.make_opsetid("", opset)])
m.ir_version = 8
onnx.checker.check_model(m)
return m
def run_ort(m, feeds):
s = ort.InferenceSession(m.SerializeToString(), providers=["CPUExecutionProvider"])
return s.run(None, feeds)
def run_tvm(m, feeds, target):
mod = from_onnx(m, shape_dict={k: list(v.shape) for k, v in feeds.items()})
mod = relax.transform.LegalizeOps()(mod)
ex = tvm.compile(mod, target=target)
vm = relax.VirtualMachine(ex, tvm.cpu())
out = vm["main"](*feeds.values())
if not isinstance(out, (list, tuple)):
out = [out]
return [o.numpy() if hasattr(o, "numpy") else o for o in out]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--target", default="llvm")
args = ap.parse_args()
x = np.array([[1.0, np.inf, -np.inf, 0.0]], dtype="float32")
bad = False
for dn, dp in ((0, 1), (1, 0), (0, 0)):
node = helper.make_node("IsInf", ["x"], ["y"],
detect_negative=dn, detect_positive=dp)
m = make_model([node], [vi("x", T.FLOAT, [1, 4])],
[vi("y", T.BOOL, [1, 4])])
ref = run_ort(m, {"x": x})[0]
got = np.asarray(run_tvm(m, {"x": x}, args.target)[0])
line_ok = np.array_equal(ref, got)
bad |= not line_ok
print(f"detect_negative={dn} detect_positive={dp}: "
f"ORT {ref.astype(int).tolist()} TVM {got.astype(int).tolist()}"
f" {'ok' if line_ok else 'MISMATCH'}")
print("NOT REPRODUCED (fixed?)" if not bad else "BUG REPRODUCED")
return 0 if not bad else 1
if __name__ == "__main__":
raise SystemExit(main())
Error Log / Traceback
detect_negative=0 detect_positive=1: ORT [[0, 1, 0, 0]] TVM [[0, 1, 1, 0]] MISMATCH
detect_negative=1 detect_positive=0: ORT [[0, 0, 1, 0]] TVM [[0, 1, 1, 0]] MISMATCH
detect_negative=0 detect_positive=0: ORT [[0, 0, 0, 0]] TVM [[0, 1, 1, 0]] MISMATCH
BUG REPRODUCED
Prior Report Search
No matching issue found; #19452 (closed) was a CodeGenVM intrinsic crash for isnan/isinf, unrelated to the attributes. Search: IsInf.
- Lingua principale
- Python
- Stelle
- 13.9k
- Fork
- 4.1k
- Merge medio
- 4g 22h
- PR unite (30g)
- 22
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/tvm
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NoneForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsApertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsForse già presa @pierceluu10 l’ha presa 4 giorni fa. Apertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsForse già presa @tandede l’ha presa 9 giorni fa. Apertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 3 giorni
-
[Bug][Relax][TOPI] RoiAlign mode=max returns the average of the sample pointsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaneeds-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 3 giorni
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
web-push-libs/pywebpush#216 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
AgriciDaniel/claude-seo#572 ·
I maintainer di solito rispondono entro 5 giorni
-
area:print-dispatch
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno
-
area: docs domain: technical-writing good first issue type: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Deepak3699/Ai_Mentor#919 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno