ALinrunrun opened a new issue, #19500:
URL: https://github.com/apache/tvm/issues/19500

   ### Expected behavior
   
   TVM Relay should import and execute ONNX `Resize` consistently with ONNX 
Runtime for:
   
   ```
   mode="nearest"
   coordinate_transformation_mode="half_pixel"
   nearest_mode="round_prefer_floor"
   ```
   
   For a 3x3 input upsampled by scales `[1.0, 1.0, 1.5, 1.5`], ONNX Runtime 
produces:
   
   ```
   [[0. 0. 1. 2.]
    [0. 0. 1. 2.]
    [3. 3. 4. 5.]
    [6. 6. 7. 8.]]
   ```
   
   ### Actual behavior
   
   TVM Relay produces a different output from ONNX Runtime:
   
   ```
   TVM output [0,0]:
   [[0. 1. 1. 2.]
    [3. 4. 4. 5.]
    [3. 4. 4. 5.]
    [6. 7. 7. 8.]]
   
   max_abs=4.000000e+00
   ```
   
   The discrepancy appears when importing ONNX Resize with half_pixel and 
round_prefer_floor.
   
   ### Environment
   
   - TVM: 0.14.dev273 / Relay ONNX frontend
   - ONNX Runtime: 1.23
   - ONNX: 1.15.0
   - NumPy: 1.26.4
   - 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, 3, 3])
       y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, None)
   
       scales = helper.make_tensor(
           "scales", TensorProto.FLOAT, [4], [1.0, 1.0, 1.5, 1.5]
       )
   
       resize = helper.make_node(
           "Resize",
           ["X", "", "scales"],
           ["Y"],
           mode="nearest",
           coordinate_transformation_mode="half_pixel",
           nearest_mode="round_prefer_floor",
       )
   
       graph = helper.make_graph([resize], "g", [x], [y], initializer=[scales])
       return helper.make_model(graph, opset_imports=[helper.make_opsetid("", 
13)])
   
   
   x = np.arange(9, dtype=np.float32).reshape(1, 1, 3, 3)
   model = build_model()
   
   ort_sess = ort.InferenceSession(
       model.SerializeToString(), providers=["CPUExecutionProvider"]
   )
   ort_out = ort_sess.run(None, {"X": x})[0]
   
   mod, params = relay.frontend.from_onnx(model, shape={"X": list(x.shape)})
   with tvm.transform.PassContext(opt_level=3):
       lib = relay.build(mod, target="llvm", params=params)
   
   gm = graph_executor.GraphModule(lib["default"](tvm.cpu()))
   gm.set_input("X", x)
   gm.run()
   tvm_out = gm.get_output(0).numpy()
   
   print("ORT output:")
   print(ort_out[0, 0])
   print("TVM output:")
   print(tvm_out[0, 0])
   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]

Reply via email to