python-3.x - 无法在 Colab 中使用 PyTorch 重现结果
问题描述
我正在 P100 GPU 上的 Colab 中运行用 PyTorch 编写的模型,并且我使用以下代码设置了所有种子
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed)
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
除了上述之外,我还在代码中需要的任何地方设置了种子值。
只有在同一会话中运行代码时,我才能获得可重现的结果。当我关闭会话然后在新会话中重新运行代码时,结果会有所不同。在 Colab 中使用 PyTorch 是否无法获得可重现的结果?
解决方案
推荐阅读
- python - 通过 Pandas DataFame 在循环中切片字符串
- java - 做什么
> 什么意思? - unity3d - Unity UI Button不断双击,我该如何解决这个问题?
- java - charAt 不能被取消引用
- swiftui - What is the equivalent of textarea in swiftui?
- python - 找到图像的轮廓和凸包之间的共同点
- react-native - 单击通知如何在 React 本机 Firebase 中打开特定页面
- python - Python 3 项目结构的最佳实践
- mysql - 避免三个表之间的重复行
- react-native - 如何在反应导航中实现此视图?