-
-
Save afspies/59971c4043ab23aab508adde0b54478b to your computer and use it in GitHub Desktop.
Experiment Seeding for GPUs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import random | |
import tensorflow as tf | |
# from tfdeterminism import patch - only in older versions (<2?) of Tensorflow | |
# import torch | |
def seed(seed=42): | |
# -- Python & Numpy -- | |
random.seed(seed) | |
np.random.seed(seed) | |
# -- Tensorflow -- | |
tf.random.set_seed(seed) | |
tf.experimental.numpy.random.seed(s) | |
os.environ['TF_CUDNN_DETERMINISTIC'] = '1' | |
os.environ['TF_DETERMINISTIC_OPS'] = '1' | |
# tf.set_random_seed(s) - Older Version | |
# -- Pytorch -- | |
# torch.manual_seed(seed) | |
# The following may slightly slow down training: | |
# torch.use_deterministic_algorithms(True) | |
# os.environ['CUBLAS_WORKSPACE_CONFIG']=':4096:8' # see https://docs.nvidia.com/cuda/cublas/index.html#cublasApi_reproducibility | |
# torch may also require specifying seeded worker for dataloader | |
# https://github.com/NVIDIA/framework-determinism |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment