Skip to content

Commit

Permalink
Exposed the pure python gelu implementation. (tensorflow#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldemarmiesse authored Mar 9, 2020
1 parent eb3f30d commit 7d547cf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tensorflow_addons/activations/gelu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from tensorflow_addons.utils import types
from tensorflow_addons.utils.resource_loader import LazySO
from tensorflow_addons import options

_activation_so = LazySO("custom_ops/activations/_activation_ops.so")

Expand All @@ -42,6 +43,17 @@ def gelu(x: types.TensorLike, approximate: bool = True) -> tf.Tensor:
A `Tensor`. Has the same type as `x`.
"""
x = tf.convert_to_tensor(x)

if not options.TF_ADDONS_PY_OPS:
try:
return _gelu_custom_op(x, approximate)
except tf.errors.NotFoundError:
options.warn_fallback("gelu")

return _gelu_py(x, approximate)


def _gelu_custom_op(x, approximate):
return _activation_so.ops.addons_gelu(x, approximate)


Expand Down

0 comments on commit 7d547cf

Please sign in to comment.