echuraev commented on code in PR #13119:
URL: https://github.com/apache/tvm/pull/13119#discussion_r1001645930
##########
tests/python/frontend/onnx/test_forward.py:
##########
@@ -5638,13 +5638,14 @@ def verify_reverse_sequence(x, sequence_lens,
batch_axis, time_axis):
verify_reverse_sequence(x, sequence_lens, 1, 0)
[email protected]("op_name", ["Gelu", "FastGelu"], scope="session")
@tvm.testing.parametrize_targets
-def test_gelu(target, dev):
+def test_gelu(target, dev, op_name):
Review Comment:
Let's also extend the tests to check accuracy for `fp16` datatype.
##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -926,10 +926,39 @@ def _impl_v1(cls, inputs, attr, params):
return _op.multiply(term1, term2)
+class FastGelu(OnnxOpConverter):
+ """Operator converter for FastGelu from Microsoft onnxruntime contrib
opset.
+
+ fast_gelu(x) = 0.5x(1 + tanh(sqrt(2/pi)(x + 0.044715x^3)))
+ = 0.5x(1 + tanh((sqrt(2/pi)x + 0.044715(sqrt(2/pi)x^3)))
+ """
+
+ @classmethod
+ def _impl_v1(cls, inputs, attr, params):
+ x = inputs[0]
+ if inputs[1]:
+ bias = inputs[1]
+ x += bias
+
+ # Declare consts
+ const_dtype = infer_type(x).checked_type.dtype
+ half = _expr.const(0.5, dtype=const_dtype)
+ one = _expr.const(1.0, dtype=const_dtype)
+ const1 = _expr.const(math.sqrt(2 / math.pi), dtype=const_dtype)
+ const2 = _expr.const(0.044715 * math.sqrt(2 / math.pi),
dtype=const_dtype)
Review Comment:
I took a look at the [ONNX
documentation](https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.FastGelu).
And they use hard-coded constants in their implementation. Let's check that
for `fp16` we will have the same accuracy with the current implementation as
ONNX.
--
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]