Iirc the bug Karpathy mentioned in his tweet was actually due to the seed being the same across multigpu data parallel workers! You need to account for this too. So the author hasnt solved it. I know this bc I fixed the bug. And probably caused it. Hehe. Also you dont just want to set ur numpy seed but also the native python one and the torch one.
A common mistake when NumPy’s RNG with PyTorch
51–54 of 54 posts
Re: A common mistake when NumPy’s RNG with PyTorch
#52.NET has a similar pitfall, but not due to forking but rather that the Random() default seed is based on the system clock. So starting several threads constructing new Random objects with the hope that they are unique might in fact give you same RNG sequences.
Re: A common mistake when NumPy’s RNG with PyTorch
#53Forgetting to seed your RNG is a really classic bug. IMHO RNGs should auto seed unless explicitly set not to, but since the opposite behaviour was baked into C so many years ago it's kind of the default. The worst part is how easy a bug this is to miss unless you're explicitly printing out the first set of random numbers for some strange reason.
I’m of the opposite opinion and would get away from all auto RNG seeding: 1) this will help reproducibility a great deal, which is a pain so often. 2) forcing users to actually understand the seeding of RNGs from the point that they are novice programmers could help allay bugs of the sort seen in this post, which I believe stems from having too much faith that RNGs will simply work out of the box as substitutions for…
But you really need to change selected known bad seeds, which destroy the PRNG statistical properties. Most PRNG's have a couple of known bad seeds, but nobody does anything against it. Same for hash functions.
Re: A common mistake when NumPy’s RNG with PyTorch
#54Is there something specific about numpy here, or would it be any RNG? I'm looking at some code that uses random.random() to randomly apply augmentations, I suspect that will have the same issue right?
For splitting up sequential ranges, a good rng typically has an advance function to advance the seed for each range. So you can get reproducibility.