Skip to contents

You can use this utility to make almost any Keras program fully deterministic. Some limitations apply in cases where network communications are involved (e.g. parameter server distribution), which creates additional sources of randomness, or when certain non-deterministic cuDNN ops are involved.

This sets:

  • the R session seed: set.seed()

  • the Python session seed: import random; random.seed(seed)

  • the Python NumPy seed: import numpy; numpy.random.seed(seed)

  • the TensorFlow seed: tf$random$set_seed(seed) (only if TF is installed)

  • The Torch seed: import("torch")$manual_seed(seed) (only if the backend is torch)

  • and disables Python hash randomization.

Note that the TensorFlow seed is set even if you're not using TensorFlow as your backend framework, since many workflows leverage tf$data pipelines (which feature random shuffling). Likewise many workflows might leverage NumPy APIs.





Integer, the random seed to use.


No return value, called for side effects.