ALinrunrun opened a new issue, #19501:
URL: https://github.com/apache/tvm/issues/19501
### Expected behavior
TVM Relay should import and execute ONNX `RoiAlign` consistently with ONNX
Runtime when using:
```
opset=16
coordinate_transformation_mode="half_pixel"
mode="avg"
sampling_ratio=2
```
For the same input tensor and ROIs, TVM should produce values close to ONNX
Runtime within normal floating-point tolerance.
### Actual behavior
TVM Relay produces different results from ONNX Runtime:
```
ORT[0,0,:]: [0.6476003 0.680636 0.2975294 0.6975541 0.5666482
0.30768085
0.49313858 0.44409746]
TVM[0,0,:]: [0.6062307 0.63081366 0.22761177 0.62207025 0.43770045
0.4528265
0.5918484 0.31075302]
max_abs=1.451457e-01 tol=1e-04
```
The discrepancy appears when importing ONNX `RoiAlign` with
`coordinate_transformation_mode="half_pixel"`.
### Environment
- TVM: 0.14 environment / Relay ONNX frontend
- ONNX Runtime: 1.23
- Python: 3.11
- Target: llvm
- OS: Linux
### Steps to reproduce
```
import numpy as np
import onnx
from onnx import TensorProto, helper
import onnxruntime as ort
import tvm
from tvm import relay
from tvm.contrib import graph_executor
def build_model():
x = helper.make_tensor_value_info("X", TensorProto.FLOAT, [1, 1, 10, 10])
rois = helper.make_tensor_value_info("R", TensorProto.FLOAT, [2, 4])
batch = helper.make_tensor_value_info("B", TensorProto.INT64, [2])
y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [2, 1, 3, 3])
node = helper.make_node(
"RoiAlign",
["X", "R", "B"],
["Y"],
output_height=3,
output_width=3,
sampling_ratio=2,
spatial_scale=1.0,
mode="avg",
coordinate_transformation_mode="half_pixel",
)
graph = helper.make_graph([node], "g", [x, rois, batch], [y])
return helper.make_model(graph, opset_imports=[helper.make_opsetid("",
16)])
rng = np.random.RandomState(0)
x = rng.rand(1, 1, 10, 10).astype(np.float32)
rois = np.array(
[[0.5, 0.5, 5.5, 5.5], [1.0, 2.0, 7.0, 8.0]],
dtype=np.float32,
)
batch = np.array([0, 0], dtype=np.int64)
feeds = {"X": x, "R": rois, "B": batch}
model = build_model()
ort_sess = ort.InferenceSession(
model.SerializeToString(), providers=["CPUExecutionProvider"]
)
ort_out = ort_sess.run(None, feeds)[0]
mod, params = relay.frontend.from_onnx(
model,
shape={
"X": list(x.shape),
"R": list(rois.shape),
"B": list(batch.shape),
},
)
with tvm.transform.PassContext(opt_level=3):
lib = relay.build(mod, target="llvm", params=params)
gm = graph_executor.GraphModule(lib["default"](tvm.cpu()))
for name, value in feeds.items():
gm.set_input(name, value)
gm.run()
tvm_out = gm.get_output(0).numpy()
print("ORT[0,0,:]:", ort_out[0, 0].ravel()[:8])
print("TVM[0,0,:]:", tvm_out[0, 0].ravel()[:8])
print("max_abs:", np.max(np.abs(ort_out - tvm_out)))
```
### Triage
needs-triage
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]