Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dropout seeds the global RNG #656

Open
yurivish opened this issue Jan 20, 2021 · 0 comments
Open

dropout seeds the global RNG #656

yurivish opened this issue Jan 20, 2021 · 0 comments

Comments

@yurivish
Copy link

yurivish commented Jan 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant