问题描述
我的网络包括“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? 我想知道该代码是否能保证我的训练过程的确定性计算。
解决方法
function getAnnotationsFromDocument(docId,callback){
initDB();
var async = require('async');
async.waterfall([
function authorize(callback){
//checkAuthorization
(...)
},function getRfpdocAnnotations(auth,metadata,callback){
//call to DB
(...)
},function processRfpdocAnnotations(rfpDocAnnotations,callback){
(...)
callback(null,annotationsList);
}
],function (err,result) {
if(err) {
callback(err);
} else {
callback(null,result);
}
});
}
仅适用于 CUDA 卷积运算,仅此而已。因此,不,它不能保证您的训练过程是确定性的,因为您还使用了 torch.backends.cudnn.deterministic=True
,其后向函数对于 CUDA 是不确定的。
torch.nn.MaxPool3d
会影响此处列出的所有正常非确定性操作(请注意,torch.set_deterministic()
在 1.8 中已重命名为 set_deterministic
):https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html?highlight=use_deterministic#torch.use_deterministic_algorithms
正如文档所述,某些列出的操作没有确定性的实现。因此,如果设置了 use_deterministic_algorithms
,它们将抛出错误。
如果您需要使用诸如 torch.use_deterministic_algorithms(True)
之类的非确定性操作,那么目前,您的训练过程无法确定性——除非您自己编写自定义确定性实现。或者您可以打开一个 GitHub 问题请求确定性实现:https://github.com/pytorch/pytorch/issues
此外,您可能想查看此页面:https://pytorch.org/docs/stable/notes/randomness.html