seed = 2018
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
a=torch.rand([1,5])
b=torch.rand([1,5])
关闭进程,重新运行上面代码,发现得到的a和b和上一次的a和b是一样的
seed = 2018
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
a=torch.rand([1,5])
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
b=torch.rand([1,5])
每次获取随机数时,设置seed,发现每次获得的都一样(前提是函数调用方式一样),上面的a==b