注:以下截图分别来自torchdata、dgl、torch的官网
先看torchdata与torch的版本适配,这边选择0.6.0版本的torchdata,那么需要对应的torch为2.0.0 pip install torchdata==0.6.0
再看dgl的版本适配
那这边需要选择的是cuda11.8,dgl cu118,然后去选取torch的cu118
# CUDA 11.8 conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.8 -c pytorch -c nvidia
dgl下载,去轮子仓库,这边看到1.1.2+cu118和2.2.1+cu118等可用,2.2.1+cu118用不来,那就1.1.2+cu118可用。
data.dgl.ai/wheels/cu118/repo.html
pip install dgl==1.1.2+cu118 -f https://data.dgl.ai/wheels/cu118/repo.html
测试
import torch import dgl print("PyTorch version:", torch.__version__) print("CUDA available:", torch.cuda.is_available()) print("CUDA version used by PyTorch:", torch.version.cuda) print("GPU:", torch.cuda.get_device_name(0) if torch.cuda.is_available() else "No CUDA") print("DGL version:", dgl.__version__)
Using device: cuda PyTorch version: 2.0.0 CUDA available: True CUDA version used by PyTorch: 11.8 GPU: NVIDIA GeForce RTX 4070 Laptop GPU DGL version: 1.1.2+cu118
可以,看样子是成功了。