复现RGCL遇到的错误:
Device API gpu is not enabled. Please install the cuda version of dgl. 当前安装的 DGL 是 CPU 版本,不支持 GPU ,代码试图把异构图 .to('cuda:0') 迁移到 GPU,DGL 库无 CUDA 后端直接崩溃。
解决方案:
重装支持 CUDA 的 DGL,先说一下,如果已经安装了错的dgl,要先卸载,比如我装了两个错误的(一个是GPU的,一个是版本不对)
先卸载:
pip uninstall dgl dgl-cu113 -y
正确安装代码 是:根据自己的环境选择版本,我的是0.9.1我的环境 PyTorch 1.11.0 Python 3.8(ubuntu20.04) CUDA 11.3,不知道可以问下AI
pip install dgl-cu113==0.9.1 -f https://data.dgl.ai/wheels/repo.html --trusted-host data.dgl.ai
注意一定要加后面一场串 ,不然报错:
(base) root@autodl-container-6d25459816-01b42b10:~/Work/ReviewGraph-main/RGCL# pip install dgl-cu113==0.7.2
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
ERROR: Could not find a version that satisfies the requirement dgl-cu113==0.7.2 (from versions: none)
ERROR: No matching distribution found for dgl-cu113==0.7.2
避坑1:一开始装错就是用了错误代码安装的是CPU版本:
使用的是:pip install dgl==0.9.1 -f https://data.dgl.ai/wheels/cu113/repo.html
避坑2:安装了不匹配自己环境的GPU版本也不可以
比如我的环境 PyTorch 1.11.0 Python 3.8(ubuntu20.04) CUDA 11.3下dgl-cu113==0.7.2不可以
,所以不能用:
pip install dgl-cu113==0.7.2 -f https://data.dgl.ai/wheels/repo.html --trusted-host data.dgl.ai
完整报错:
(base) root@autodl-container-6d25459816-01b42b10:~/Work/ReviewGraph-main/RGCL# python rgc_nd_ed.py
Namespace(dataset_name='Beauty_and_Personal_Care_5', dataset_path='/root/data/Beauty_and_Personal_Care_5/Beauty_and_Personal_Care_dedup_renamed1_renamed2.json', device=device(type='cuda', index=0), distributed=False, ed_alpha=1.0, gcn_agg_units=64, gcn_dropout=0.7, gcn_out_units=64, model_save_path='log/RGC-ND-ED_Beauty_and_Personal_Care_5_P5.pkl', model_short_name='RGC-ND-ED', nd_alpha=0.3, rating_alpha=1.0, review_feat_size=64, share_param=False, train_classification=True, train_decay_patience=20, train_early_stopping_patience=50, train_grad_clip=1.0, train_log_interval=1, train_lr=0.01, train_lr_decay_factor=0.5, train_max_iter=400, train_min_lr=0.001, train_optimizer='Adam', train_valid_interval=1)
Feature dim:
user: (660178, 660178)
movie: (165067, 165067)
Train enc graph: #user:660178 #movie:165067 #pairs:901181
Train dec graph: #user:660178 #movie:165067 #pairs:901181
Valid enc graph: #user:660178 #movie:165067 #pairs:901181
Valid dec graph: #user:660178 #movie:165067 #pairs:36210
Test enc graph: #user:660178 #movie:165067 #pairs:901181
Test dec graph: #user:660178 #movie:165067 #pairs:36372
Loading data finished ...
Loading network finished ...
Traceback (most recent call last):
File "rgc_nd_ed.py", line 535, in <module>
train(config_args)
File "rgc_nd_ed.py", line 455, in train
dataset.train_enc_graph = dataset.train_enc_graph.int().to(params.device)
File "/root/miniconda3/lib/python3.8/site-packages/dgl/heterograph.py", line 5448, in to
ret._graph = self._graph.copy_to(utils.to_dgl_context(device))
File "/root/miniconda3/lib/python3.8/site-packages/dgl/heterograph_index.py", line 237, in copy_to
return _CAPI_DGLHeteroCopyTo(self, ctx.device_type, ctx.device_id)
File "dgl/_ffi/_cython/./function.pxi", line 293, in dgl._ffi._cy3.core.FunctionBase.__call__
File "dgl/_ffi/_cython/./function.pxi", line 225, in dgl._ffi._cy3.core.FuncCall
File "dgl/_ffi/_cython/./function.pxi", line 215, in dgl._ffi._cy3.core.FuncCall3
dgl._ffi.base.DGLError: [21:30:03] /opt/dgl/src/runtime/c_runtime_api.cc:88: Check failed: allow_missing: Device API gpu is not enabled. Please install the cuda version of dgl.
Stack trace:
[bt] (0) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x4f) [0x7fdf0fb526ef]
[bt] (1) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::runtime::DeviceAPIManager::GetAPI(std::string, bool)+0x37c) [0x7fdf0fe207dc]
[bt] (2) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::runtime::DeviceAPI::Get(DLContext, bool)+0x1f4) [0x7fdf0fe1ab44]
[bt] (3) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::runtime::NDArray::Empty(std::vector<long, std::allocator<long> >, DLDataType, DLContext)+0x15b) [0x7fdf0fe3c24b]
[bt] (4) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::runtime::NDArray::CopyTo(DLContext const&) const+0xc0) [0x7fdf0fe79000]
[bt] (5) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::UnitGraph::CSR::CopyTo(DLContext const&) const+0x259) [0x7fdf0ff992b9]
[bt] (6) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::UnitGraph::CopyTo(std::shared_ptr<dgl::BaseHeteroGraph>, DLContext const&)+0x9f) [0x7fdf0ff8a44f]
[bt] (7) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::HeteroGraph::CopyTo(std::shared_ptr<dgl::BaseHeteroGraph>, DLContext const&)+0xf5) [0x7fdf0fe8ad65]
[bt] (8) /root/miniconda3/lib/python3.8/site-packages/dgl/libdgl.so(+0x4e748b) [0x7fdf0fe9848b]
(base) root@autodl-container-6d25459816-01b42b10:~/Work/ReviewGraph-main/RGCL#