Skip to content

Commit 34d835b

Browse files
committed
Fix scalar indexing and restore GPU testing for AlphaDropout
1 parent dfacc9c commit 34d835b

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

src/layers/normalise.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,12 @@ function (a::AlphaDropout)(x::AbstractArray{T}) where T
107107
iszero(p) && return x
108108
isone(p) && return sign.(x) .* T(0)
109109

110-
λ = T(1.0507009873554804934193349852946)
111-
α = T(1.6732632423543772848170429916717)
112-
α1 = T(-λ * α)
113-
A = inv(sqrt((1 - p) * (1 + p * α1^2)))
114-
B = -A * α1 * p
110+
α′ = T(-1.7580993408473766) # selu(-Inf) == -λα
111+
A = T(inv(sqrt((1 - p) * (1 + p * α′^2))))
112+
B = T(-A * α′ * p)
115113

116114
noise = rand!(similar(x))
117-
return A .* ifelse.(noise .> p, x, α1) .+ B
115+
return A .* ifelse.(noise .> p, x, α′) .+ B
118116
end
119117

120118
testmode!(m::AlphaDropout, mode=true) =

test/cuda/layers.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@
1010
@test gradient(x -> sum(cpu(x)), gpu(rand(3,3))) isa Tuple
1111
end
1212

13-
# TODO: These layers get into scalar indexing
14-
# `AlphaDropout` throws a compilation error on GPUs,
15-
# whereas, the rest are scalar indexing issues.
16-
# The norm layers behave differently on the CPU and
17-
# the GPU too.
18-
const BROKEN_LAYERS = Union{DepthwiseConv,
19-
AlphaDropout}
13+
# TODO: These layers get into scalar indexing issues.
14+
const BROKEN_LAYERS = Union{DepthwiseConv}
2015

2116
const ACTIVATIONS = [identity, relu, tanh,
2217
sigmoid, exp, softplus,

0 commit comments

Comments
 (0)