The dropout! function will seed the global RNG when called with a seed argument, leading to unexpected deterministic behavior further on in program execution once the function has returned. For example, the following code will always return the same result even though the second call to dropout does not set the seed argument:
julia> using Knet
julia> let
a = Float64[n for n in 1:10]
dropout(a, .2, drop=true, seed=1)
dropout(a, .2, drop=true)
end
10-element Array{Float64,1}:
1.25
2.5
3.75
5.0
6.25
7.5
8.75
0.0
11.25
12.5
julia> let
a = Float64[n for n in 1:10]
dropout(a, .2, drop=true, seed=1)
dropout(a, .2, drop=true)
end
10-element Array{Float64,1}:
1.25
2.5
3.75
5.0
6.25
7.5
8.75
0.0
11.25
12.5
This also means that other uses of randomness become implicitly re-seeded at the point of the call to dropout, leading (for example) to the following two independent calls to rand to return the same results:
julia> using Knet
julia> let
a = Float64[n for n in 1:10]
dropout(a, .2, drop=true, seed=1)
rand_1 = rand(10)
dropout(a, .2, drop=true, seed=1)
rand_2 = rand(10)
rand_1 == rand_2
end
true
As a separate issue, if zero is passed as the seed then no seed will be set at all:
|
function dropout!(p,x,y;seed=0) |
|
if seed != 0; Random.seed!(seed); end |
The
dropout!function will seed the global RNG when called with aseedargument, leading to unexpected deterministic behavior further on in program execution once the function has returned. For example, the following code will always return the same result even though the second call todropoutdoes not set theseedargument:This also means that other uses of randomness become implicitly re-seeded at the point of the call to
dropout, leading (for example) to the following two independent calls torandto return the same results:As a separate issue, if zero is passed as the seed then no seed will be set at all:
Knet.jl/src/ops20/dropout.jl
Lines 45 to 46 in f1de18b