torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False manual_seed控制程序的随机性

cuda 是NVIDIA 针对自家的CPU设计的并行计算的框架,

cuDNN是is a GPU-accelerated library of primitives for deep neural networks。是专门针对深度神经网络打造的加速库。

cuDNN Archive | NVIDIA Developericon-default.png?t=M276https://developer.nvidia.com/rdp/cudnn-archivetorch.backends.cudnn.benchmark = False

Reproducibility — PyTorch 1.11.0 documentationicon-default.png?t=M276https://pytorch.org/docs/stable/notes/randomness.html

The cuDNN library, used by CUDA convolution operations, can be a source of nondeterminism across multiple executions of an application. When a cuDNN convolution is called with a new set of size parameters, an optional feature can run multiple convolution algorithms, benchmarking them to find the fastest one. Then, the fastest algorithm will be used consistently during the rest of the process for the corresponding set of size parameters. Due to benchmarking noise and different hardware, the benchmark may select different algorithms on subsequent runs, even on the same machine.

Disabling the benchmarking feature with torch.backends.cudnn.benchmark = False causes cuDNN to deterministically select an algorithm, possibly at the cost of reduced performance.

However, if you do not need reproducibility across multiple executions of your application, then performance might improve if the benchmarking feature is enabled with torch.backends.cudnn.benchmark = True.

大概意思是:torch.backends.cudnn.benchmark = True,在训练的时候,一个好的特征可能会经过好多不同的convolution algorithms的测试,选出来最快的,剩下的过程都会采用这个算法。

如果torch.backends.cudnn.benchmark = False,那么模型的表现可能不是最优的,但reproducibility是比较强的。

当算法固定的时候,但算法本身可能是nondeterministic的。

如果torch.use_deterministic_algorithms(True),但有些算法本身是nondeterminitic的,所以就可能报错。有些算法是有deterministic的implementation的,使用时不会报错。

对比之下,torch.backends.cudnn.deterministic = True 只会针对这一个算法进行控制,而torch.use_deterministic_algorithms(True) 会对其他的操作产生影响(which will make other PyTorch operations behave deterministically, too)

同时,其他提升程序的reproducibility的方法,考虑seed的使用:

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值