mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-25 01:41:17 +08:00
add nn module for sigmoid activation (#111)
* add nn module for sigmoid activation * update .gitignore with .cache folder generated by jetbrains fleet ide * remove .cache folder
This commit is contained in:
parent
600db7d754
commit
68bf1d7867
3
.gitignore
vendored
3
.gitignore
vendored
@ -74,3 +74,6 @@ build/
|
|||||||
# VSCode
|
# VSCode
|
||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# Jetbrains
|
||||||
|
.cache
|
||||||
|
@ -15,6 +15,16 @@ def _make_activation_module(f):
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
def sigmoid(x):
|
||||||
|
r"""Applies the element-wise function:
|
||||||
|
|
||||||
|
.. math::
|
||||||
|
\text{Sigmoid}(x) = \sigma(x) = \frac{1}{1 + \exp(-x)}
|
||||||
|
"""
|
||||||
|
return mx.sigmoid(x)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def relu(x):
|
def relu(x):
|
||||||
"""Applies the Rectified Linear Unit.
|
"""Applies the Rectified Linear Unit.
|
||||||
|
|
||||||
@ -79,6 +89,9 @@ def gelu_fast_approx(x):
|
|||||||
"""
|
"""
|
||||||
return x * mx.sigmoid(1.773 * x)
|
return x * mx.sigmoid(1.773 * x)
|
||||||
|
|
||||||
|
@_make_activation_module
|
||||||
|
class Sigmoid(Module):
|
||||||
|
pass
|
||||||
|
|
||||||
@_make_activation_module(relu)
|
@_make_activation_module(relu)
|
||||||
class ReLU(Module):
|
class ReLU(Module):
|
||||||
|
Loading…
Reference in New Issue
Block a user