Pytorch——torch.manual_seed(), torch.cuda.manual_seed()

torch.manual_seed(args.seed)

为CPU设置种子用于生成随机数,以使得结果是确定的

if args.cuda: 
torch.cuda.manual_seed(args.seed)

为当前GPU设置随机种子;
如果使用多个GPU,应该使用以下代码为所有的GPU设置种子。

torch.cuda.manual_seed_all()

使用同样的随机初始化种子可以保证每次初始化都相同

你可能感兴趣的:(Pytorch)