pytorch 固定随机数种子 发表于 2020-02-26 | 分类于 ML/DL 1234567891011121314151617181920import torchimport numpy as npimport randomseed=0random.seed(seed)np.random.seed(seed)if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed)torch.manual_seed(seed)torch.cuda.manual_seed(seed)torch.cuda.manual_seed_all(seed)# Remove randomness (may be slower on Tesla GPUs)# https://pytorch.org/docs/stable/notes/randomness.htmlif seed == 0: torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False