今天使用LSTM做时序预测,发现同样的参数运行结果却不一样。
查找资料发现神经网络初始化参数并不一样,需要设置随机数种子使得结果可复现。
seed = 0
torch.manual_seed(seed) # 为CPU设置随机种子
torch.cuda.manual_seed(seed) # 为当前GPU设置随机种子
torch.cuda.manual_seed_all(seed) # 为所有GPU设置随机种子
今天使用LSTM做时序预测,发现同样的参数运行结果却不一样。
查找资料发现神经网络初始化参数并不一样,需要设置随机数种子使得结果可复现。
seed = 0
torch.manual_seed(seed) # 为CPU设置随机种子
torch.cuda.manual_seed(seed) # 为当前GPU设置随机种子
torch.cuda.manual_seed_all(seed) # 为所有GPU设置随机种子