-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Unable to create a reproduceable code #850
Comments
I am having the exact same problem. I ran the bundled LSTM example 4 times as follows (I installed both
And I get the following test set scores and accuracies for the four runs which as you can see vary widely:
The full log for the command is below. Shouldn't every epoch yield exactly the same result across runs if
|
@nouiz in #439 suggests the following:
|
Nevermind, I tried his suggestion, but I still can't get consistent results. |
Are you using Convolutions on GPU? It may be you need to use a special By default cuDNN uses a non deterministic algorithm to compute gradients Daniele Bonadiman On Thu, Mar 3, 2016 at 12:42 AM, Henry Lin notifications@github.com wrote:
|
I'm not using a CNN. Just a simple, feedforward neural network. |
EDIT: Okay, I actually figured out my problem. I thought that Looks like I could reproduce the results now. Thanks. |
Adding to @dbonadiman : The documentation on http://deeplearning.net/software/theano/library/sandbox/cuda/dnn.html is not up to date with theano 0.8.1
to your .theanorc file (algo_bwd = deterministc is deprecated) |
@hlin117 What did you do to solve the issue? I have the same situation: a very simple feedforward neural network. I set the numpy seed as the very first thing in the script. However, I do get different results for different runs. I'm using the latest theano dev (as suggested by #439) + keras version: ``import numpy as np [...] print("build model") |
Can you double check you're using those packages, using keras.version
|
hi @hlin117
However, the seeding still doesn't work, I get different results with different runs. |
Can you make sure that you're using the same training and testing set for every run? (Truthfully, that was actually my problem.) |
No, that's not the problem, I'm using pre-split separate files. Weird.. |
There is a few source of non-deterministic things in Theano. We are in the https://github.com/Theano/Theano/pull/4212/files#diff-c55c00bc8b5d7f77c3795170a0a519ad On Thu, Apr 28, 2016 at 2:43 AM, Barbara Plank notifications@github.com
|
Hi @nouiz! I tried now, changed the two lines in theano/sandbox/cuda/opt.py, ran setup.py, and added THEANO_FLAGS='optimizer_excluding=conv_dnn' in front of the script. However, it's still not deterministic.. Did I do something wrong? When do you expect the flag to be ready? Btw: here's the simple sample code that I'm running. https://github.com/bplank/example_ff.git |
@bplank, after spending some time trying to find a solution to this problem, I think I nailed down a major source of randomness. Using python 2 I'm able to get consistent results with your code running theano on a GPU without any special However, with python 3 results are not deterministic, even with the proposed flags above. What turned results deterministic in python 3 was setting the flag
before running the code. Details about this flag can be found at the python docs. |
@kepler Thanks, great! I just checked, your suggestion of setting |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, but feel free to re-open it if needed. |
We can close this issue (it works for theano) - it is still an open issue for the tensorflow backend - see: #2280 |
Follow up: This is how it works for me for the theano backend:
|
Again follow up: The two runs I compared to were accidentally very similar, but now I do no longer get the same results back.. Did something change with the Theano backend? |
Update: With Theano (0.9.0 dev version) my sample code actually works IF I set the |
@bplank can you summarize the versions of Theano, Keras, and Python you're using, and what steps you took to get deterministic results? I see setting PYTHONHASHSEED=0 and np.random.seed from the above comments; was there anything else? Were you able to get it to work with Theano 0.9.0 stable version? |
I discussed this issue with @bplank and did reproducibility tests myself, and we both got deterministic results with the setup you described:
I confirmed that this produced deterministic results with Keras 1.2.2 and 2.0.4 on different example scripts, though not when running with CUDA. For this, a patch for Theano is needed, which has also been discussed above already. I use this minimal patch in my virtualenv: https://gist.github.com/mbollmann/fda3b219ef1416649b79ecc725174152 I didn't try Tensorflow backend, and I only tried a subset of the available layers/models in Keras, so this was not strictly an exhaustive test. |
@riley-x I needed to use the PYTHONHASHSEED. And setting the seed before any import, as @mbollmann said above. I did get deterministic results with Python 3.6 Anaconda, theano '0.9.0.dev-c697eeab84e5b8a74908da654b66ec9eca4f1291' and Keras 2.0.2. See the |
I succeeded in getting reproducibility with: See my comments on Jason Brownlee's blog at |
Closing as this is resolved |
Keeps a parallel API between optimizer.apply and optimizer.stateless_apply. We can leave the iterations return type on apply_gradients for compat with tf.keras.
Keeps a parallel API between optimizer.apply and optimizer.stateless_apply. We can leave the iterations return type on apply_gradients for compat with tf.keras.
I've tried adding numpy.random.seed before importing anything from keras (as was suggested in #439). However, each run produces different result.
The text was updated successfully, but these errors were encountered: