【问题标题】:Pytorch errors: "received an invalid combination of arguments" in Jupyter NotebookPytorch 错误:Jupyter Notebook 中的“收到无效的参数组合”
【发布时间】:2019-06-12 22:30:52
【问题描述】:

我正在尝试学习 Pytorch,但每当我尝试任何在线教程 (https://pytorch.org/tutorials/beginner/blitz/tensor_tutorial.html#sphx-glr-beginner-blitz-tensor-tutorial-py) 时,我都会在尝试运行某些功能时遇到错误,但仅在 Jupyter Notebook 中

运行时

x = torch.empty(5, 3)

我收到一个错误:

module 'torch' has no attribute 'empty'

另外,在运行时

x = torch.zeros(5, 3, dtype=torch.long)

我得到错误:

module 'torch' has no attribute 'long'

其他一些功能也可以正常工作,例如:

x = torch.rand(5, 3)

但一般来说,我尝试运行的大多数代码似乎很快就会遇到错误。我在网上找不到任何解决方案。

当我进入我的 docker 容器并简单地在 shell 中运行 python 时,我可以很好地运行这些行而没有错误。

我在一个从 fastai 镜像扩展而来的 Docker 镜像中运行 pytorch,因为它已经包含了 jupyter notebook 和 pytorch 之类的东西。我使用 anaconda 更新所有内容,并将其提交给自己的新图像。

我完全不知道问题可能是什么。我尝试通过我的 docker 容器中的 anaconda、pip、aptitude 更新软件包,并确保提交我的更改,但似乎没有任何效果。我还尝试使用 python 3.7 创建一个新内核,因为我注意到我的 Jupyter Notebook 仅在 3.6.4 中运行,而当我在 shell 中运行 python 时,它是 3.7。

我也尝试过获取不同的 docker 图像并根据我的需要扩展它们,但是我尝试过的所有图像都在 anaconda 中出现错误,卡在“解决环境”步骤中。

【问题讨论】:

  • 嗨,欢迎来到 SO。尝试安装不同版本的torchtext,错误可能是因为forums.fast.ai/t/…
  • @harshit_k 我试过这个,但不幸的是我仍然有同样的问题。
  • 没问题,你现在可以接受你的答案了。

标签: docker jupyter-notebook pytorch attributeerror


【解决方案1】:

好的,所以我的解决方法是使用以下命令通过 conda 更新 pytorch

conda update pytorch

如果它还没有安装,我已经通过 conda 简单地安装它让它在其他环境中工作

conda install pytorch

有点愚蠢,我之前没有尝试过,但我对 conda 和 pip 之间的区别感到困惑。

【讨论】:

    猜你喜欢
    • 2019-07-26
    • 2020-08-27
    • 1970-01-01
    • 2018-06-27
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    相关资源
    最近更新 更多