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

   ### Expected behavior
   
   TVM Relax should execute ONNX `ScatterElements` consistently with ONNX 
Runtime when `reduction="add"` is used.
   
   For duplicated target indices, the updates should be accumulated with the 
original input value.
   
   ### Actual behavior
   
   TVM appears to overwrite with the last update value instead of applying add 
reduction:
   
   ```
   onnxruntime:
   [[16.  2.  2.]
    [ 2.  2.  2.]
    [ 2. 20.  2.]
    [ 2.  2. 26.]]
   
   tvm:
   [[11.  2.  2.]
    [ 2.  2.  2.]
    [ 2. 13.  2.]
    [ 2.  2. 17.]]
   
   max_abs_diff: 9.0
   ```
   
   ### Environment
   
   TVM: 0.14 environment / Relax ONNX frontend
   ONNX Runtime: 1.23
   Python: 3.11
   Target: llvm
   OS: Linux
   
   ### Steps to reproduce
   
   ```
   import numpy as np
   import onnx
   import onnxruntime as ort
   import tvm
   from onnx import TensorProto, helper
   from tvm import relax
   from tvm.relax.frontend.onnx import from_onnx
   
   
   data = np.full((4, 3), 2.0, dtype=np.float32)
   indices = np.array([[0, 2, 3], [0, 2, 3]], dtype=np.int64)
   updates = np.array([[3.0, 5.0, 7.0], [11.0, 13.0, 17.0]], dtype=np.float32)
   
   x = helper.make_tensor_value_info("X", TensorProto.FLOAT, [4, 3])
   i = helper.make_tensor_value_info("I", TensorProto.INT64, [2, 3])
   u = helper.make_tensor_value_info("U", TensorProto.FLOAT, [2, 3])
   y = helper.make_tensor_value_info("Y", TensorProto.FLOAT, [4, 3])
   
   node = helper.make_node(
       "ScatterElements",
       ["X", "I", "U"],
       ["Y"],
       axis=0,
       reduction="add",
   )
   
   graph = helper.make_graph([node], "g", [x, i, u], [y])
   model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 18)])
   model.ir_version = 8
   model = onnx.shape_inference.infer_shapes(model)
   
   ort_out = ort.InferenceSession(
       model.SerializeToString(),
       providers=["CPUExecutionProvider"],
   ).run(None, {"X": data, "I": indices, "U": updates})[0]
   
   mod = from_onnx(model)
   mod = relax.transform.LegalizeOps()(mod)
   
   exe = tvm.relax.build(mod, target="llvm")
   vm = tvm.relax.VirtualMachine(exe, device=tvm.cpu())
   
   tvm_out = vm["main"](
       tvm.runtime.tensor(data, device=tvm.cpu()),
       tvm.runtime.tensor(indices, device=tvm.cpu()),
       tvm.runtime.tensor(updates, device=tvm.cpu()),
   ).numpy()
   
   print("onnxruntime:")
   print(ort_out)
   print("tvm:")
   print(tvm_out)
   print("max_abs_diff:", float(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