为了保证在本机上的可复现性,需要设置随机种子:
import numpy as npimport torchnp.random.seed(0) torch.manual_seed(0) torch.cuda.manual_seed_all(0) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False