# Why can't I reproduce my results in keras using random seed?

I was doing a task using RNN to predict a time series movement.

I want to make my results reproducible. So I strictly followed this post: https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras

My code are as follows:

# Seed value
# Apparently you may use different seed values at each stage
seed_value= 0

# 1. Set the PYTHONHASHSEED environment variable at a fixed value
import os
os.environ['PYTHONHASHSEED']=str(seed_value)

# 2. Set the python built-in pseudo-random generator at a fixed value
import random
random.seed(seed_value)

# 3. Set the numpy pseudo-random generator at a fixed value
import numpy as np
np.random.seed(seed_value)

tf.compat.v1.set_random_seed(seed_value)

tf.random.set_seed(seed_value)

# 5. Configure a new global tensorflow session

# for later versions:
sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
tf.compat.v1.keras.backend.set_session(sess)


However, every time I ran my codes, I still got a different result, what could the reasons be?

Are you using a CPU or a GPU?

If you are using a GPU, there is an additional source of randomness.

To confirm this point, you can try to use TensorFlow with CPU only, or disable Cuda DNN but the model will be twice longer:

THEANO_FLAGS="optimizer_excluding=conv_dnn" python your_file.py

THEANO_FLAGS="dnn.conv.algo_bwd_filter=deterministic,dnn.conv.algo_bwd_data=deterministic" python your_file.py

• I have set it to only use CPU according to this post stackoverflow.com/questions/40690598/…, and the print result of from tensorflow.python.client import device_lib device_lib.list_local_devices() shows that only CPU is used. But no matter how I try following the post in my question, I still cannot get reproducible results. Jun 27 at 20:53
• Could you try running the code in this link in order to see if it is a hardware issue? stackoverflow.com/questions/60058588/… Jun 28 at 6:55
• Hello, would you please take a look at my new question datascience.stackexchange.com/questions/112252/…? I described the details there. Jun 29 at 19:47