python - 无法在 Google Colab 中安装 dgl-cu<任何版本>

标签 python pytorch google-colaboratory dgl

我尝试在 Google Colab 中使用 dgl 运行图形模型,但在训练模型时继续出现错误。我相信我的主要问题是我无法使用加载 dgl-cuda 库

!pip install dgl-cu111

我收到以下错误:

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
ERROR: Could not find a version that satisfies the requirement dgl-cu111 (from versions: none)
ERROR: No matching distribution found for dgl-cu111

训练模型时,出现以下错误:

load_done
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/rnn.py:71: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.2 and num_layers=1
  warnings.warn("dropout option adds dropout after all but last "
init done
Epoch 1:   0%|          | 0/49 [00:00<?, ?it/s]
---------------------------------------------------------------------------
DGLError                                  Traceback (most recent call last)
<ipython-input-7-783797e86ab0> in <cell line: 209>()
    207 
    208 
--> 209 train(model)
    210 test_func(model, y_test, X_test)

3 frames
<ipython-input-7-783797e86ab0> in train(net)
    179                         gc.collect()
    180                         continue
--> 181                     acc, loss, _ = fwd_pass(batch_X, batch_y, train=True)
    182 
    183                     losses.append(loss.item())

<ipython-input-7-783797e86ab0> in fwd_pass(X, y, train)
    108     for item in X:
    109         x = [0, 0]
--> 110         x[0] = item[0].to(device)
    111         x[1] = item[1].to(device)
    112         out.append(model(x))

/usr/local/lib/python3.10/dist-packages/dgl/heterograph.py in to(self, device, **kwargs)
   5707 
   5708         # 1. Copy graph structure
-> 5709         ret._graph = self._graph.copy_to(utils.to_dgl_context(device))
   5710 
   5711         # 2. Copy features

/usr/local/lib/python3.10/dist-packages/dgl/heterograph_index.py in copy_to(self, ctx)
    253             The graph index on the given device context.
    254         """
--> 255         return _CAPI_DGLHeteroCopyTo(self, ctx.device_type, ctx.device_id)
    256 
    257     def pin_memory(self):

dgl/_ffi/_cython/./function.pxi in dgl._ffi._cy3.core.FunctionBase.__call__()

dgl/_ffi/_cython/./function.pxi in dgl._ffi._cy3.core.FuncCall()

dgl/_ffi/_cython/./function.pxi in dgl._ffi._cy3.core.FuncCall3()

DGLError: [01:00:58] /opt/dgl/src/runtime/c_runtime_api.cc:82: Check failed: allow_missing: Device API cuda is not enabled. Please install the cuda version of dgl.
Stack trace:
  [bt] (0) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x75) [0x7fae2b978e55]
  [bt] (1) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::runtime::DeviceAPIManager::GetAPI(std::string, bool)+0x1f2) [0x7fae2bcf85f2]
  [bt] (2) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::runtime::DeviceAPI::Get(DGLContext, bool)+0x1e1) [0x7fae2bcf2ba1]
  [bt] (3) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::runtime::NDArray::Empty(std::vector<long, std::allocator<long> >, DGLDataType, DGLContext)+0x13b) [0x7fae2bd15acb]
  [bt] (4) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::runtime::NDArray::CopyTo(DGLContext const&) const+0xc3) [0x7fae2bd4fe23]
  [bt] (5) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::UnitGraph::CopyTo(std::shared_ptr<dgl::BaseHeteroGraph>, DGLContext const&)+0x3ef) [0x7fae2be5d79f]
  [bt] (6) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::HeteroGraph::CopyTo(std::shared_ptr<dgl::BaseHeteroGraph>, DGLContext const&)+0xf6) [0x7fae2bd61286]
  [bt] (7) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(+0x52cbb6) [0x7fae2bd70bb6]
  [bt] (8) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(DGLFuncCall+0x48) [0x7fae2bcf7bb8]

关于如何在 Google Colab 上安装 dgl-gpu 库有什么想法吗?我正在使用 Colab 的 A100 GPU:

(nvcc:NVIDIA (R) Cuda 编译器驱动程序 版权所有 (c) 2005-2022 NVIDIA 公司 建于 Wed_Sep_21_10:33:58_PDT_2022 Cuda 编译工具,版本 11.8,V11.8.89 构建cuda_11.8.r11.8/compiler.31833905_0)

最佳答案

我在使用 V100 GPU 时遇到了这个问题。我的解决方法是指定来源:

pip install dgl==1.0.1+cu117 -f https://data.dgl.ai/wheels/cu117/repo.html

确保为您的设置选择正确的 CUDA 版本。

关于python - 无法在 Google Colab 中安装 dgl-cu<任何版本>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76519346/

相关文章:

python - Scrapy 合并来自多个进程的项目

python - 计算 torch 张量数组的平均值和标准差

linux - 如何在 google colab 中启用拼写检查器(colab 在 linux 操作系统上运行)?

python - 绝对导入导致 ModuleNotFoundError

python - SQLAlchemy/ Pandas : Can not insert default time in MySQL

解决文本规范化任务的 Pythonic 方法

python - pytorch/torchtext 中的单热编码

java - "ValueError: Incompatible Language version 13. Must not be between 9 and 12"与 Google Colab

tensorflow - 如何在 Google Colab 中使用 TensorFlow 2.0 将 tf.Keras 模型转换为 TPU?

pip - 无法修复导入错误 : cannot import name 'ToTensorV2' from 'albumentations.pytorch' on Colab