(self, seed)
| 219 | self.model.load_state_dict(params) |
| 220 | |
| 221 | def set_random_seed(self, seed): |
| 222 | torch.manual_seed(seed) # 为CPU设置随机种子 |
| 223 | if self.device.type == 'cuda': |
| 224 | torch.backends.cudnn.benchmark = False |
| 225 | torch.cuda.manual_seed(seed) # 为当前GPU设置随机种子 |
| 226 | torch.cuda.manual_seed_all(seed) # 为所有GPU设置随机种子 |
| 227 | random.seed(seed) |
| 228 | np.random.seed(seed) |
| 229 | |
| 230 | def set_device(self, device): |
| 231 | if device == 'gpu' and torch.cuda.is_available(): |