模型训练随机种子及其原理

实习中所跑实验一般都有随机种子

但是不知道原理是什么。

下边用来记录。

来源:https://wenku.baidu.com/view/eed3b921ecf9aef8941ea76e58fafab068dc445a.html

https://blog.csdn.net/ytusdc/article/details/125529881

def seed_everything(seed):
  random.seed(seed)
  os.environ['PYTHONHASHSEED'] = str(seed)
   np.random.seed(seed)
   torch.manual_seed(seed)#为当前的cpu设置随机种子
   torch.cuda.manual_seed(seed)#为gpu
   torch.cuda.manual_seed_all(seed)#当有多块gpu设置随机种子
   torch.backends.cudnn.deterministic = True#设置每次返回的卷积算法一致
  torch.backends.cudnn.benchmark=False#使用的非确定性算法自动寻找最适合当前配置的高效算法 (不理解)
torch.backends.cudnn.enabled=True #pytorch使用CUDANN加速即用GPU加速
  

 

 

 

 

 

 原理:

原理待续

posted on 2022-07-17 09:52  nlp如此迷人  阅读(467)  评论(0)    收藏  举报

导航