Parallel kernels can schedule floating-point work in different orders, so identical TensorFlow runs may diverge by small amounts even when their inputs do not change. Operation determinism selects deterministic implementations for supported operations, allowing exact comparisons during debugging and regression testing.
TensorFlow exposes a process-level operation-determinism API. An unseeded tf.random.normal() call succeeds before the switch but raises RuntimeError afterward, which distinguishes an enabled process from TensorFlow's default state.
The switch does not seed random-number generators. Repeatable random values also require a shared seed and the same hardware and software environment; deterministic operations can run more slowly, and an unsupported operation may raise tf.errors.UnimplementedError.
Related: Set a random seed in TensorFlow
Related: Check TensorFlow version
Related: Create a TensorFlow virtual environment
Related: Install TensorFlow with pip
import tensorflow as tf SEED = 2026
def draw_seeded_tensor(): tf.keras.utils.set_random_seed(SEED) return tf.random.normal((4,))
The Keras helper resets Python, NumPy, and TensorFlow random state each time the function runs.
tf.random.normal((4,))
tf.config.experimental.enable_op_determinism()
guard_raised = False try: tf.random.normal((4,)) except RuntimeError: guard_raised = True
first = draw_seeded_tensor() second = draw_seeded_tensor() seeded_match = bool( tf.reduce_all( tf.equal(first, second) ) )
if not guard_raised: raise AssertionError( "Operation determinism did not reject an unseeded random operation" )
tf.debugging.assert_equal( seeded_match, True, message="Resetting the shared seed did not reproduce the random tensor", )
print("Unseeded before enablement: allowed") print("Unseeded after enablement: blocked") print("Seeded repeatability: exact match")
$ python3 determinism-demo.py Unseeded before enablement: allowed Unseeded after enablement: blocked Seeded repeatability: exact match
An AssertionError about the unseeded operation means the determinism call is absent or did not run. An UnimplementedError identifies an operation without a deterministic implementation in the current environment.