【问题标题】:PyTorch Geometric CUDA installation issues on Google ColabGoogle Colab 上的 PyTorch Geometric CUDA 安装问题
【发布时间】:2020-05-30 19:58:11
【问题描述】:

我正在使用 Google Colab 开发一个 PyTorch Geometric 项目以支持 CUDA。由于默认情况下它的库不存在,我运行:

!pip install --upgrade torch-scatter
!pip install --upgrade torch-sparse
!pip install --upgrade torch-cluster
!pip install --upgrade torch-spline-conv 
!pip install torch-geometric

最近在导入torch_geometric时,由于版本升级,出现CUDA版本不匹配的提示:

RuntimeError: 检测到 PyTorch 和 torch_sparse 是用不同的 CUDA 版本编译的。 PyTorch 的 CUDA 版本为 10.1,torch_sparse 的 CUDA 版本为 10.0。请重新安装与您的 PyTorch 安装相匹配的 torch_sparse。

为了解决这个问题,我尝试将 conda 用于特定的 CUDA 版本:

!conda install pytorch==1.4.0 cudatoolkit=10.0 -c pytorch

然而,在运行 print(torch.version.cuda) 时,我得到 10.1 作为输出,而不是我想要的 10.0。

这是一个最近的错误,因为它在过去一周没有抛出这个问题。有解决此问题的最佳实践吗?

【问题讨论】:

    标签: pytorch google-colaboratory pytorch-geometric


    【解决方案1】:

    你可以在pytorch几何官网找到示例colab notebooks https://pytorch-geometric.readthedocs.io/en/latest/notes/colabs.html

    这是我在同一个网站上使用的。它正在发布日期。

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

    【讨论】:

    • 这似乎与现有的答案大体上重复,你能解释一下有什么不同和重要吗?
    • 这里给出的解决方案目前都不起作用。 Pytorch Geometric 官方网站上给出的那个对我有用。
    【解决方案2】:

    根据我的分析,torch 几何对 cuda 11 和 pytorch 1.7.0 给出错误

    请安装pytorch 1.6和amd cuda 10.2并在下面执行

    pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
    pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
    pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
    pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
    pip install torch-geometric
    

    【讨论】:

      【解决方案3】:

      这是我在 co-lab 中用于安装 PyTorch 几何相关依赖项的最新代码命令。

      import torch
      
      def format_pytorch_version(version):
        return version.split('+')[0]
      
      TORCH_version = torch.__version__
      TORCH = format_pytorch_version(TORCH_version)
      
      def format_cuda_version(version):
        return 'cu' + version.replace('.', '')
      
      CUDA_version = torch.version.cuda
      CUDA = format_cuda_version(CUDA_version)
      
      !pip install torch-scatter     -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
      !pip install torch-sparse      -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
      !pip install torch-cluster     -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
      !pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
      !pip install torch-geometric 
      

      【讨论】:

        【解决方案4】:

        来自their website

        试试这个

        !pip install torch-geometric \
          torch-sparse==latest+cu101 \
          torch-scatter==latest+cu101 \
          torch-cluster==latest+cu101 \
          -f https://pytorch-geometric.com/whl/torch-1.4.0.html
        

        【讨论】:

        • 更新:我们甚至必须在上述命令中包含 torch-spline-conv 才能与最新版本兼容。
        • @MdWahiduzzamanKhan,显然,甚至 torch-cluster 也已更新。使用: !pip install torch-cluster==latest+cu101 -f pytorch-geometric.com/whl/torch-1.4.0.html 这行甚至可以使torch-cluster兼容
        【解决方案5】:

        您可能想尝试以下方法,看看这是否解决了“pytorch-geometric”中的 CUDA 版本控制错误问题:

        1. apt-get --purge remove "cublas" "cuda*"
        2. 重启
        3. sudo curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
        4. sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
        5. sudo apt-get install cuda-10-1
        6. python -c“导入火炬;打印(火炬.version.cuda)”

          10.1

        7. nvcc --version

          Cuda 编译工具,版本 10.1,V10.1.243

        【讨论】:

          【解决方案6】:

          问题可以通过评论解决:

          !pip install torch-scatter==latest+cu101 torch-sparse==latest+cu101 -f https://s3.eu-central-1.amazonaws.com/pytorch-geometric.com/whl/torch-1.4.0.html
          

          我们还有其他解决方案吗?

          【讨论】:

          • 您能否评论一下您是如何解决这一行的问题的?应该在 !pip install torch-geometric \ torch-sparse==latest+cu101 \ torch-scatter==latest+cu101 \ torch-cluster==latest+cu101 \ -f pytorch-geometric.com/whl/torch-1.4.0.html 之后添加还是改用?跨度>
          猜你喜欢
          • 2019-05-15
          • 2021-11-18
          • 2021-09-29
          • 2018-11-06
          • 2018-11-06
          • 1970-01-01
          • 1970-01-01
          • 2020-03-21
          • 2019-02-17
          相关资源
          最近更新 更多