ITADN

Sign operator returns 0 for NaN inputs instead of NaN

#24502Openwuyii8941 创建于 2026-05-16
bug 🐞
W
wuyii8941commented
### What happened? ## Expected behavior `Sign(NaN)` should return `NaN`, matching ONNX Runtime behavior. ## Actual behavior IREE returns `0` for NaN inputs. ``` Input: [nan, 1.0, nan, -2.0, 0.0] ORT: [nan, 1.0, nan, -1.0, 0.0] IREE: [0.0, 1.0, 0.0, -1.0, 0.0] ``` Full reproducer: `iree_bug_017_sign_nan.py` ## Root cause The Sign lowering uses a comparison chain (`x > 0 → 1, x < 0 → -1, else → 0`) which maps NaN to 0 since IEEE 754 comparisons with NaN return false. ## Note While the ONNX spec is not fully normative on NaN behavior for Sign, ONNX Runtime (the reference implementation) consistently propagates NaN. IREE's behavior can cause silent numerical divergence when switching runtimes. ### Steps to reproduce your issue ## Reproduction ```python import numpy as np import onnx from onnx import helper, TensorProto import onnxruntime as ort x = np.array([np.nan, 1.0, np.nan, -2.0, 0.0], dtype=np.float32) X = helper.make_tensor_value_info("X", TensorProto.FLOAT, [5]) Y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [5]) node = helper.make_node("Sign", ["X"], ["Y"]) graph = helper.make_graph([node], "main", [X], [Y]) model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)]) model = onnx.shape_inference.infer_shapes(model) # Save and run through IREE pipeline: # iree-import-onnx model.onnx -o model.mlir # iree-compile model.mlir --iree-hal-target-backends=llvm-cpu -o model.vmfb # iree-run-module --module=model.vmfb --input=5xf32=[nan,1.0,nan,-2.0,0.0] # # Or via Python API (see full reproducer script). ``` ### What component(s) does this issue relate to? _No response_ ### Version information ## Environment - iree-base-compiler: 3.12.0rc20260515 - iree-base-runtime: 3.12.0rc20260515 - Python: 3.11 - OS: Linux ### Additional context _No response_
0 条评论