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

   ### Expected behavior
   
   TVM Relax should execute ONNX `Atan` consistently with ONNX Runtime for 
large finite float32 inputs.
   
   For very large positive inputs, `atan(x)` should approach `pi/2`. For very 
large negative inputs, it should approach `-pi/2`.
   
   ### Actual behavior
   
   TVM Relax returns `0.0` / `-0.0`, while ONNX Runtime returns values close to 
`±pi/2`:
   
   ```
   input: [ 3.e+22  7.e+21 -2.e+25]
   ORT  : [ 1.5707964  1.5707964 -1.5707964]
   TVM  : [ 0.  0. -0.]
   ```
   
   The discrepancy appears when importing an ONNX Atan model through the Relax 
ONNX frontend and compiling it for the llvm target.
   
   ### Environment
   
   TVM: 0.14 environment / Relax ONNX frontend
   ONNX Runtime: 1.23
   Python: 3.11
   Target: llvm
   OS: Linux
   
   ### Steps to reproduce
   
   ```
   import warnings
   
   warnings.filterwarnings("ignore")
   
   import numpy as np
   import onnxruntime as ort
   import tvm
   from onnx import TensorProto, helper
   from tvm import relax
   from tvm.relax.frontend.onnx import from_onnx
   
   
   node = helper.make_node("Atan", ["x"], ["y"])
   
   graph = helper.make_graph(
       [node],
       "g",
       [helper.make_tensor_value_info("x", TensorProto.FLOAT, [3])],
       [helper.make_tensor_value_info("y", TensorProto.FLOAT, [3])],
   )
   
   model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 20)])
   model.ir_version = 9
   
   x = np.array([3e22, 7e21, -2e25], dtype=np.float32)
   
   ort_out = ort.InferenceSession(
       model.SerializeToString(),
       providers=["CPUExecutionProvider"],
   ).run(None, {"x": x})[0]
   
   mod = from_onnx(model)
   
   with tvm.transform.PassContext(opt_level=3):
       ex = tvm.compile(mod, target=tvm.target.Target("llvm"))
   
   vm = relax.VirtualMachine(ex, tvm.cpu())
   
   out = vm["main"](tvm.runtime.tensor(x, tvm.cpu()))
   tvm_out = (out[0] if isinstance(out, (list, tuple)) else out).numpy()
   
   print("input:", x)
   print("ORT  :", ort_out)
   print("TVM  :", 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