在Colab中为torch_sparse构建轮子需要很长时间

18

我正在尝试在Google Colab上运行以下命令:

!pip install torch_sparse

一开始看起来似乎工作正常:


Collecting torch_sparse
  Downloading https://files.pythonhosted.org/packages/9a/86/699eb78ea7ce259da7f9953858ec2a064e4e5f5e6bf7de53aa6c8bb8b9a8/torch_sparse-0.6.9.tar.gz
Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from torch_sparse) (1.4.1)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.7/dist-packages (from scipy->torch_sparse) (1.19.5)
Building wheels for collected packages: torch-sparse

但是从这里开始,它会一直运行而不输出任何错误消息,并且轮子永远也不会被构建。

我的Colab环境是托管的并使用GPU加速器。我也可以事先安装torch并初始化cuda,但这并没有改变任何东西。

6个回答

17

综合之前的所有答案,以下是能够在colabs的任何运行时都能工作的代码片段:

import torch

!pip uninstall torch-scatter torch-sparse torch-geometric torch-cluster  --y
!pip install torch-scatter -f https://data.pyg.org/whl/torch-{torch.__version__}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{torch.__version__}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{torch.__version__}.html
!pip install git+https://github.com/pyg-team/pytorch_geometric.git

1
它对我起作用了!而且只花了一分钟。 - Peyman

13

安装实际上完成需要30分钟至1小时时间(我没有准确的时间)。但是,当我尝试导入torch_sparse时,遇到了这里描述的问题:Google Colab上PyTorch Geometric CUDA安装问题

我尝试应用最受欢迎的答案,但由于它似乎已经过时,所以我将其更新为以下内容:

!pip install torch-geometric \
  torch-sparse \
  torch-scatter \
  torch-cluster \
  -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
这个安装很顺利,只用了几秒钟。目前看起来,它使我能够从torch_geometric/torch_sparse中导入我需要的所有内容。如果以后遇到任何问题,我会告诉你的!

这个安装很顺利,只用了几秒钟。目前看起来,它使我能够从 torch_geometric/torch_sparse 中导入我需要的所有内容。如果以后遇到任何问题,我会告诉你的!


1
安装对我来说也太慢了。上面的答案对我没用。这种方法有没有更新? - Prince Bhatti

3
为了提高可移植性,可以自动提供适当 PyTorch 版本的路径。
import torch
print(torch.__version__)
!pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-{torch.__version__}.html

2

以上的答案都对我没用。构建轮子一直在转,转啊转。以下是发布日期有效的解决方法:

  1. 首先找到您的torch版本:

    import torch print(torch.__version__)

1.10.0+cu111

  1. 如果您和我一样,colab的cuda没有列在pytorch-geometric的安装说明中,则可以参考他们的教程笔记本的安装方法,使用以下命令:
!pip uninstall torch-scatter torch-sparse torch-geometric torch-cluster  
!pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu111.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cu111.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-1.10.0+cu111.html
!pip install git+https://github.com/pyg-team/pytorch_geometric.git

注意:您可以使用https://data.pyg.org/whl/torch-{torch.__version__}.html替换上面的内容。
import torch

!echo https://data.pyg.org/whl/torch-{torch.__version__}.html 

https://data.pyg.org/whl/torch-{1.10.0+cu111}.html


1

在之前的回答中,Matthias Fey建议使用以下方法在colab中下载依赖项:

!pip install -q torch-scatter -f https://data.pyg.org/whl/torch-1.9.0+cu111.html
!pip install -q torch-sparse -f https://data.pyg.org/whl/torch-1.9.0+cu111.html
!pip install -q git+https://github.com/pyg-team/pytorch_geometric.git

这个Colab链接Github链接可能会有所帮助。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接