pytorch中cudnn.benchmark和cudnn.deterministic的作用

##随机数设置模板

def setup_seed(seed):
     torch.manual_seed(seed)  # 为CPU设置随机种子
     torch.cuda.manual_seed(seed)  # 为当前GPU设置随机种子
     torch.cuda.manual_seed_all(seed) # 为所有GPU设置随机种子
     np.random.seed(seed)     #np随机数组种子
     random.seed(seed)      # 随机数种子  
     
     torch.backends.cudnn.benchmark = True  # 是否自动加速,自动选择合适算法,false选择固定算法
     torch.backends.cudnn.deterministic = True  # 为了消除该算法本身的不确定性
     
# 设置随机数种子
setup_seed(20)

参考文献

https://www.pythonf.cn/read/155691

https://zhuanlan.zhihu.com/p/73711222

https://blog.csdn.net/weixin_61445075/article/details/124073298?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-124073298-blog-124863924.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-124073298-blog-124863924.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=1

猜你喜欢

转载自blog.csdn.net/qq_35568823/article/details/126461737