TensorFlow: Non-repeatable results

You need to set operation level seed in addition to graph-level seed, ie

tf.reset_default_graph()
a = tf.constant([1, 1, 1, 1, 1], dtype=tf.float32)
graph_level_seed = 1
operation_level_seed = 1
tf.set_random_seed(graph_level_seed)
b = tf.nn.dropout(a, 0.5, seed=operation_level_seed)

In TensorFlow 2.0 tf.set_random_seed(42) has changed to tf.random.set_seed(42).

https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/random/set_seed

That should be the only seed necessary if just using TensorFlow.


See this tensorflow github issue. Some operations on the GPU are not fully deterministic (speed vs precision).

I also observed that for the seed to have any effect, tf.set_random_seed(...) must be called before the Session is created. And also you should either completely restart the python interpreter every time you run your code, or call tf.reset_default_graph() at the start.