【PyTorch】DGL 报错FileNotFoundError: Cannot find DGL C++ graphbolt library

报错

使用PyTorch 和DGL时报错:

xxx@xxx-gpu-3080ti-1:~/workspace/inference$ python inference.py 
开始推理
100%|███████████████████████████████████████████████████████████████████████████████████| 99/99 [00:00<00:00, 877.31it/s]
Traceback (most recent call last):
  File "/home2/ykli/workspace/inference/inference.py", line 93, in <module>
    from dgl.data import DGLDataset
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/__init__.py", line 16, in <module>
    from . import (
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/dataloading/__init__.py", line 13, in <module>
    from .dataloader import *
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/dataloading/dataloader.py", line 27, in <module>
    from ..distributed import DistGraph
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/distributed/__init__.py", line 5, in <module>
    from .dist_graph import DistGraph, DistGraphServer, edge_split, node_split
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/distributed/dist_graph.py", line 11, in <module>
    from .. import backend as F, graphbolt as gb, heterograph_index
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/graphbolt/__init__.py", line 55, in <module>
    load_graphbolt()
  File "/home2/ykli/.local/lib/python3.10/site-packages/dgl/graphbolt/__init__.py", line 45, in load_graphbolt
    raise FileNotFoundError(
FileNotFoundError: Cannot find DGL C++ graphbolt library at /home2/ykli/.local/lib/python3.10/site-packages/dgl/graphbolt/libgraphbolt_pytorch_2.3.1.so

核心原因是DGL 与 PyTorch 的兼容性问题。

解决方法:

确定兼容性信息:
https://www.dgl.ai/pages/start.html

先查看自己的CUDA版本
nvidia-smi

xxx@xxx-gpu-3080ti-1:~/workspace/inference$ nvidia-smi
Thu Sep 18 15:15:58 2025       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.153.02             Driver Version: 570.153.02     CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3080 Ti     Off |   00000000:21:00.0 Off |                  N/A |
| 40%   61C    P0            116W /  350W |       0MiB /  12288MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

所以

先安装torch

pip3 install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu121

再安装dgl
(参考https://www.dgl.ai/pages/start.html)

pip3 install  dgl -f https://data.dgl.ai/wheels/torch-2.4/cu124/repo.html

然后就成功了

xxx@xxx-gpu-3080ti-1:~/workspace/inference$ python inference.py 
开始推理
100%|█████████████████████████████████████| 99/99 [00:00<00:00, 884.90it/s]
ok
/home2/ykli/workspace/inference/inference.py:228: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  model.load_state_dict(torch.load("GCN_Multi.pth")["model"])
99it [00:01, 84.29it/s]
推理结束
测试app为恶意app的概率依次为
6.448549e-05
0.017811496
0.002427295
0.0017984548
0.002004614
0.99742377
0.004718356
0.9982717
3.615891e-17
0.9982717
0.99682534
0.004988429
0.010242186
0.98479813
0.98893905
0.9993826
0.004939628
7.899102e-05
0.022339027
0.0033634796
0.98893917
0.99742377
0.99967027
0.9982717
5.6295053e-06
0.030222524
0.99346876
0.99971515
0.9987703
0.09378741
5.4269745e-05
0.0010533822
0.9982717
0.99965036
0.9529677
0.9529677
0.98333883
5.459704e-09
0.0003061844
0.027305502
0.98893905
0.7514718
0.0049884245
0.0049884245
0.0005003361
0.001292823
1.0
0.9505768
0.6262198
0.024419907
0.0049884245
0.9982717
0.98893917
0.9982717
0.0005057038
0.98893917
0.98893917
0.0017296192
0.99965036
0.0014586173
0.917256
0.9986375
0.0006834932
0.95257545
8.688583e-06
0.0043205405
0.9505768
0.0018375306
0.98893917
0.9992711
0.98893905
0.99965036
0.99942386
0.00074927614
0.0015520339
0.99965036
0.041937307
0.9982717
0.98893917
0.0026961763
0.012011028
0.9982717
0.9982717
0.004988434
0.99998665
0.0007492758
0.99967027
0.9982717
1.3757738e-05
0.08972405
0.00043226476
0.99997044
0.4352821
0.99742377
0.013959418
0.9505768
0.0026908643
8.9060154e-07
0.021170292
检测准确率为0.9797979797979798
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值