-
Notifications
You must be signed in to change notification settings - Fork 388
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
I can't get deterministic results... even after setting the seed before each run. #280
Comments
Figured it out: I need to have the random seed stuff in the
|
Would it make sense to add this callback to skorch? |
I think so, deterministic behavior can be nice to have. I don't know if the way I'm doing it is the "right" way (I basically just found all the "seed" parameters I could and set them...), and I think you can run into issues if your Let me know if you want it and I can create a pull request. |
Great that it worked. Usually, when I fix seeds at the start of my script, I never have trouble getting deterministic results, so I can't really tell why this is necessary here (though I'm not sure that determinism can be guaranteed in each case when using parallelism and/or CUDA). |
Also, I could imagine that fixing the seed at the start of the training (as the callback would do) is not always desirable. If you're not careful, it could happen that you want to run an experiment X times and average the results, but really you're having the exact same outcome each time. |
This is more when playing around with things in Jupyter (you don't always run things in order), or conceivably when doing a Gridsearch (if you want to actually compare like vs. like, and not seed vs seed).
There are definitely times when you don't want this, I completely agree. |
I can see that sometimes it can be practical to do as you suggest. But I'm not sure it helps to avoid "seed vs seed" comparison in a grid search. It could well be that a particular seed happens to work better with these hyper parameters than with those hyper parameters, when another seed wouldn't. Regarding the question whether to include this in skorch, here are my reasons why I would avoid it:
On the other hand, I see no problem with using "hacky" solutions like the one proposed above during quick experimentation. Our goal with skorch was to make such things possible. |
I see your point. Indeed, this is perhaps too "hacky" to be promoted to an "official" callback. But as you admitted, it's okay to use this. I just thought that this snippet could be quite helpful and was wondering what we can do to increase its discoverability. |
I see two possibilities here, with decreasing "officiality":
Still, I might have to see a complete example where this is really needed first. |
Okay, I'll keep this thread in mind. If I ever need to use a fixed seed and find this useful, I'll send a PR to add it to FAQ. |
@spott Not sure if this is related to your issue, but there was a bugfix with regards to random seeds in pytorch 0.4.1 which might help you: pytorch/pytorch#7886 |
This discussion seems to be finished to me. Please re-open if there is still a need to discuss. |
I created a callback to reset the seed before each training run, in order to try and nail down data reproduction:
However, even when I add this to my model (and it runs before training starts), I get non-deterministic results.
I assume that the reason for that is the data loader is being seeded before the training loop gets around to calling the
FixRandomSeed
callback. Is there an idiomatic way to fix this? or do I have to fix all the seeds before I runnet.fit
?The text was updated successfully, but these errors were encountered: