pytorch - 无法重现使用 hyperopt 从超参数调整中获得的结果
问题描述
我已经建立了一个 Pytorch 模型并使用库 Hyperopt 执行了超参数调整。尽管我已经在每次运行开始时调用了以下种子函数,但获得的结果是不可重现的:
实用程序.py
def seed_everything(seed=42):
random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
培训师.py
def train(self, params):
util.seed_everything()
#wrote my training code here
经过进一步检查,我发现 hyperopt 调优的第一个结果始终是可重现的,但随后的运行则不是。这对我来说是出乎意料的,因为我已经在 train 函数的开头调用了 seed_everthing() 。
另外,如果我按以下方式进行培训:
for i in range(2):
print ("in iteration ", i)
trainer = Trainer(**configs)
trainer.train(params)
迭代 1 和 2 的结果彼此不同,但它们始终相同(即迭代 1 始终给出 1.31714 的 train_loss,而迭代 2 始终给出 4.31235)
我希望迭代 1 和迭代 2 会给出相同的结果,因为它应该是可重现的。
解决方案
推荐阅读
- laravel - 3张表之间的雄辩关系问题
- reactjs - 如何在内部使用异步函数和 setState 测试 useEffect
- arrays - 使用 Vue 将数组数据发送到 laravel 控制器
- python - 在 python 列表中查找浮点数
- c# - 如何从根 GameObject 开始查找 GameObject(层次结构中的较低层)?
- javascript - 带break的这个do while循环发生了什么?
- python - 如果 python 中列的 len() 小于 10,则跳过整行
- javascript - 如何将 Javascript 代码放入 React 的组件中?
- python - 使用 {x,y} 坐标而不是余弦定律求三角形的角度
- asp.net-mvc - ASPNET MVC - 将所有 URL 子文件夹路由到单个控制器