【问题标题】:What does the difference between 'torch.backends.cudnn.deterministic=True' and 'torch.set_deterministic(True)'?'torch.backends.cudnn.deterministic=True' 和 'torch.set_deterministic(True)' 有什么区别?
【发布时间】:2021-05-13 18:23:18
【问题描述】:

我的网络包含“torch.nn.MaxPool3d”,当根据 PyTorch 文档(版本 1.7 - https://pytorch.org/docs/stable/generated/torch.set_deterministic.html#torch.set_deterministic)打开 cudnn 确定性标志时,它会引发 RuntimeError,但是,当我插入代码“torch.backends.cudnn”时.deterministic=True' 在我的代码开头,没有 RuntimeError。为什么该代码不会引发 RuntimeError? 我想知道该代码是否能保证我的训练过程的确定性计算。

【问题讨论】:

    标签: pytorch deterministic reproducible-research


    【解决方案1】:

    torch.backends.cudnn.deterministic=True适用于 CUDA 卷积操作,仅此而已。因此,不,它不能保证你的训练过程是确定性的,因为你也在使用torch.nn.MaxPool3d,它的后向函数对于 CUDA 是不确定的。

    另一方面,torch.set_deterministic() 会影响此处列出的所有正常非确定性操作(请注意,set_deterministic 在 1.8 中已重命名为 use_deterministic_algorithms):https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html?highlight=use_deterministic#torch.use_deterministic_algorithms

    正如文档所述,某些列出的操作没有确定性实现。所以如果设置了torch.use_deterministic_algorithms(True),就会抛出错误。

    如果您需要使用像torch.nn.MaxPool3d 这样的非确定性操作,那么,目前,您的训练过程无法确定性——除非您自己编写自定义确定性实现。或者,您可以打开一个 GitHub 问题,请求确定性实施:https://github.com/pytorch/pytorch/issues

    此外,您可能还想查看此页面:https://pytorch.org/docs/stable/notes/randomness.html

    【讨论】:

    • 这是金子:As the documentation states, some of the listed operations don't have a deterministic implementation. So if torch.use_deterministic_algorithms(True) is set, they will throw an error. 谢谢,我一度对看到的错误感到困惑。
    猜你喜欢
    • 2020-02-08
    • 2011-06-22
    • 2018-12-20
    • 2023-03-14
    • 2014-10-27
    • 2017-11-08
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多