ALinrunrun opened a new issue, #19562:
URL: https://github.com/apache/tvm/issues/19562
### Expected behavior
TVM Relax should execute ONNX `Erf` consistently with ONNX Runtime for small
non-zero float32 inputs.
For tiny values near zero, `erf(x)` should be approximately proportional to
`x` and should not be rounded to exactly zero unless the result is actually
below the representable range.
### Actual behavior
TVM Relax returns `0.0` for several tiny non-zero inputs, while ONNX Runtime
returns non-zero values:
```
input: [ 3.e-12 5.e-20 -7.e-15 4.e-01]
ORT : [ 3.3851374e-12 5.6418959e-20 -7.8986542e-15 4.2839235e-01]
TVM : [0. 0. 0. 0.42839235]
```
The larger input 0.4 matches, but tiny non-zero inputs are flushed to zero
in TVM.
The discrepancy appears when importing an ONNX Erf 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("Erf", ["x"], ["y"])
graph = helper.make_graph(
[node],
"g",
[helper.make_tensor_value_info("x", TensorProto.FLOAT, [4])],
[helper.make_tensor_value_info("y", TensorProto.FLOAT, [4])],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 20)])
model.ir_version = 9
x = np.array([3e-12, 5e-20, -7e-15, 0.4], 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]