文档中提到:
确定性模式可能会对您的模型产生性能影响,具体取决于您的模型。
我的问题是,这里的性能是什么意思。是处理速度还是模型质量(即最小损失)?换句话说,通过设置手动种子使模型呈确定性方式运行,是否会导致较长的训练时间直到找到最小损失,或者这种最小损失比非确定性模型更差?
为了完整起见,我通过设置所有这些属性来手动使模型呈现确定性:
def set_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed)
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)