Skip to content

Commit

Permalink
fix bad rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Nov 7, 2021
1 parent d709b5c commit bcb3460
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/activations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ julia> lineplot(logsigmoid, -5, 5, height=7)
```
"""
logσ(x) = -softplus(-x)

const logsigmoid = logσ

"""
Expand Down Expand Up @@ -202,7 +203,7 @@ julia> leakyrelu(-10f0, 1//20)
-0.5f0
```
"""
leakyrelu(x, a=oftf(x, 0.01)) = max(a * x, x)
leakyrelu(x, a=oftf(x, 0.01)) = ifelse(x>0, float(x), oftf(x, a*x)) # max(a*x, x) is 3x slower

"""
relu6(x) = min(max(0, x), 6)
Expand Down Expand Up @@ -289,7 +290,7 @@ julia> elu(-10f0, 2)
"""
elu(x, α=1) = ifelse(x 0, float(x), α * (exp(x) - 1))

deriv_elu(Ω, α=1) = ifelse 0, 1, Ω + α)
deriv_elu(Ω, α=1) = ifelse 0, one(Ω), Ω + α)

"""
gelu(x) = 0.5x * (1 + tanh(√(2/π) * (x + 0.044715x^3)))
Expand Down Expand Up @@ -677,14 +678,17 @@ for (f, df) in UNARY_ACTS
@eval function rrule(::typeof(broadcasted),
::typeof($f), x::Numeric)
Ω = $f.(x)
function $pullback(Δ)
NoTangent(), NoTangent(), @.* $df)
function $pullback(Δ)
x_thunk = InplaceableThunk(
dx -> @.(dx += Δ * $df),
@thunk @.* $df)
)
NoTangent(), NoTangent(), x_thunk
end
return Ω, $pullback
end
end


BINARY_ACTS = [ # f, df1, df2
(:elu, :(deriv_elu(Ω, x2)), :(NoTangent())), # TODO use real deriv instead of DNE
]
Expand Down

0 comments on commit bcb3460

Please sign in to comment.