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 8, 2021
1 parent 6d5e839 commit 964dc16
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/activations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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 @@ -294,7 +294,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 @@ -763,14 +763,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 964dc16

Please sign in to comment.