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.

Usage

set_random_seed(seed)

Arguments

seed

Integer, the random seed to use.

Value

No return value, called for side effects.