-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed
Description
Describe the issue
There appears to be a divergence between onnxruntime and onnx/onnx. In the implementation of onnx, a floor-based strategy for integer division is used (added in onnx/onnx@49e4798). However when comparing the implementations, onnxruntime uses a truncation based approach leading to an inconsistency between libraries.
To reproduce
import numpy as np
from onnx import helper, TensorProto
model = helper.make_model(
helper.make_graph(
[helper.make_node("Div", ["A", "B"], ["C"])],
"div_test",
[
helper.make_tensor_value_info("A", TensorProto.INT64, [4]),
helper.make_tensor_value_info("B", TensorProto.INT64, [4]),
],
[helper.make_tensor_value_info("C", TensorProto.INT64, [4])],
),
opset_imports=[helper.make_opsetid("", 14)],
)
a = np.array([8, -8, 7, -7], dtype=np.int64)
b = np.array([-3, 3, -2, 2], dtype=np.int64)
print("Inputs:")
print(f" A = {a}")
print(f" B = {b}")
print()
from onnx.reference import ReferenceEvaluator
ref = ReferenceEvaluator(model)
ref_result = ref.run(None, {"A": a, "B": b})[0]
print(f"ONNX: {ref_result}")
import onnxruntime as ort
sess = ort.InferenceSession(model.SerializeToString(), providers=["CPUExecutionProvider"])
ort_result = sess.run(None, {"A": a, "B": b})[0]
print(f"ONNX Runtime: {ort_result}")
print()
print("Expected:")
print(f" {a} // {b} = {a // b}")Yields
Inputs:
A = [ 8 -8 7 -7]
B = [-3 3 -2 2]
ONNX: [-3 -3 -4 -4]
ONNX Runtime: [-2 -2 -3 -3]
Expected:
[ 8 -8 7 -7] // [-3 3 -2 2] = [-3 -3 -4 -4]Urgency
Non-urgent
Platform
Mac
OS Version
14
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.23.2
ONNX Runtime API
Python
Architecture
ARM64
Execution Provider
Default CPU
Execution Provider Library Version
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels