torch随机数 manual_seed
1 import torch 2 seed = 2018 3 torch.manual_seed(seed) 4 torch.cuda.manual_seed(seed) 5 a=torch.rand([1,5]) 6 # torch.manual_seed(seed) 7 # torch.cuda.manual_seed(seed) 8 b=torch.rand([1,5]) 9 print(a,b)
按上面来得到的随机数不同,加上注释就会得到相同的随机数。