TLDR:这是个关于torch.backends.cudnn设置的问题,不同组合的torch.backends.deterministic和torch.backends.cudnn.benchmark会产生不一样的结果,其中最快的组合(deterministic = False ,benchmark = True
)比最慢的组合(deterministic = True ,benchmark = False
)大约快了30倍。
现在先记录下方便以后有想法有能力了再总结回顾。
在跑BEAT的时候,有一处代码很好玩,other_tools.set_random_seed()
只不过很有点意外的是当deterministic = True ,benchmark = True
的时候居然这么慢,我起初以为设置好了benchmark=True
后torch框架会自动选个最快的卷积算法,后续deterministic = True
让这个卷积算法每次返回都是这个固定最快的。
上面是我以为的,下面根据结果(在注释的代码中)来分析
在deterministic = True ,benchmark = True
的情况,的确还是会选下卷积算法,比如把benchmark
在比如设置为False的时候每次运行时间都是固定的,设置为True的时候还是会有点时间上的小波动,可见的确是选了下卷积的算法造成了结果的差异。当然具体怎么选的我暂且就不知道了,当然,选取最快的情况deterministic = False ,benchmark = True
会有什么意向不到的结果我暂且也不清楚,网上很多说选取deterministic = True ,benchmark = False
是为了保持结果的可复现性,我感觉这很扯就是,波动理应当极小极小(当然这是我目前的偏见)。