GNN环境安装/conda channel/动手深度学习

参考:

  • torch_geometric踩坑实战–安装与运行 亲测有效!! https://blog.csdn.net/m0_55245520/article/details/130424828
  • pytorch 查看gpu cuda版本 https://blog.csdn.net/jacke121/article/details/93592487

x.1 安装

x.1.1 镜像信息补充

参考 https://mp.weixin.qq.com/s?__biz=MzI5MTcwNjA4NQ%3D%3D&idx=1&mid=2247491983&scene=21&sn=2052e7a038f2db52eb282b88495a7dfd#wechat_redirect

请添加图片描述

请添加图片描述
请添加图片描述

请添加图片描述

x.1.2 conda环境安装

使用anaconda的environment.yml安装环境,将conda镜像改为上一步中的conda镜像,即将channels中的文件改变。这一步时间会比较长,主要使用conda install进行安装,要耐心等待

conda env create -f environment.yml
conda activate env_cp39_GCN

yml文件如下,

name: env_cp39_GCN
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - pytorch
  - dglteam
  - conda-forge
  - defaults
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=1_gnu
  - argon2-cffi=21.3.0=pyhd8ed1ab_0
  - argon2-cffi-bindings=21.2.0=py39hb9d737c_2
  - asttokens=2.0.5=pyhd8ed1ab_0
  - attrs=21.4.0=pyhd8ed1ab_0
  - backcall=0.2.0=pyh9f0ad1d_0
  - backports=1.0=py_2
  - backports.functools_lru_cache=1.6.4=pyhd8ed1ab_0
  - beautifulsoup4=4.11.1=pyha770c72_0
  - blas=1.0=mkl
  - bleach=5.0.0=pyhd8ed1ab_0
  - boost=1.74.0=py39h5472131_5
  - boost-cpp=1.74.0=hc6e9bd1_3
  - bottleneck=1.3.4=py39hce1f21e_0
  - brotli=1.0.9=h166bdaf_7
  - brotli-bin=1.0.9=h166bdaf_7
  - brotlipy=0.7.0=py39h27cfd23_1003
  - bzip2=1.0.8=h7b6447c_0
  - ca-certificates=2022.6.15=ha878542_0
  - cairo=1.16.0=h6cf1ce9_1008
  - certifi=2022.6.15=py39hf3d152e_0
  - cffi=1.15.0=py39hd667e15_1
  - charset-normalizer=2.0.4=pyhd3eb1b0_0
  - click=8.0.4=py39h06a4308_0
  - colorama=0.4.4=pyhd3eb1b0_0
  - cryptography=36.0.0=py39h9ce1e76_0
  - cudatoolkit=10.2.89=hfd86e86_1
  - cycler=0.11.0=pyhd8ed1ab_0
  - debugpy=1.6.0=py39h5a03fae_0
  - decorator=5.1.1=pyhd8ed1ab_0
  - defusedxml=0.7.1=pyhd8ed1ab_0
  - dgl=0.8.1=py39_0
  - dgl-cuda10.2=0.8.1=py39_0
  - entrypoints=0.4=pyhd8ed1ab_0
  - executing=0.8.3=pyhd8ed1ab_0
  - ffmpeg=4.3=hf484d3e_0
  - flit-core=3.7.1=pyhd8ed1ab_0
  - fontconfig=2.13.1=h6c09931_0
  - fonttools=4.32.0=py39hb9d737c_0
  - freetype=2.11.0=h70c0345_0
  - fuzzywuzzy=0.18.0=pyhd8ed1ab_0
  - gettext=0.19.8.1=h73d1719_1008
  - giflib=5.2.1=h7b6447c_0
  - gmp=6.2.1=h2531618_2
  - gnutls=3.6.15=he1e5248_0
  - greenlet=1.1.2=py39h5a03fae_2
  - icu=68.2=h9c3ff4c_0
  - idna=3.3=pyhd3eb1b0_0
  - imbalanced-learn=0.9.1=pyhd8ed1ab_1
  - importlib-metadata=4.11.3=py39hf3d152e_1
  - importlib_resources=5.7.0=pyhd8ed1ab_0
  - intel-openmp=2021.4.0=h06a4308_3561
  - ipykernel=6.13.0=py39hef51801_0
  - ipython=8.2.0=py39hf3d152e_0
  - ipython_genutils=0.2.0=py_1
  - jedi=0.18.1=py39hf3d152e_1
  - jinja2=3.1.1=pyhd8ed1ab_0
  - joblib=1.1.0=pyhd8ed1ab_0
  - jpeg=9d=h7f8727e_0
  - jsonschema=4.4.0=pyhd8ed1ab_0
  - jupyter_client=7.2.2=pyhd8ed1ab_1
  - jupyter_core=4.9.2=py39hf3d152e_0
  - jupyterlab_pygments=0.2.2=pyhd8ed1ab_0
  - kiwisolver=1.4.2=py39hf939315_1
  - lame=3.100=h7b6447c_0
  - lcms2=2.12=h3be6417_0
  - ld_impl_linux-64=2.36.1=hea4e1c9_2
  - libbrotlicommon=1.0.9=h166bdaf_7
  - libbrotlidec=1.0.9=h166bdaf_7
  - libbrotlienc=1.0.9=h166bdaf_7
  - libffi=3.4.2=h7f98852_5
  - libgcc-ng=11.2.0=h1d223b6_15
  - libgfortran-ng=7.3.0=hdf63c60_0
  - libglib=2.68.4=h174f98d_1
  - libgomp=11.2.0=h1d223b6_15
  - libiconv=1.16=h516909a_0
  - libidn2=2.3.2=h7f8727e_0
  - libpng=1.6.37=hbc83047_0
  - libprotobuf=3.18.0=h780b84a_1
  - libsodium=1.0.18=h36c2ea0_1
  - libstdcxx-ng=11.2.0=he4da1e4_15
  - libtasn1=4.16.0=h27cfd23_0
  - libtiff=4.2.0=h85742a9_0
  - libunistring=0.9.10=h27cfd23_0
  - libuuid=1.0.3=h7f8727e_2
  - libuv=1.40.0=h7b6447c_0
  - libwebp=1.2.2=h55f646e_0
  - libwebp-base=1.2.2=h7f8727e_0
  - libxcb=1.13=h7f98852_1004
  - libxml2=2.9.12=h72842e0_0
  - littleutils=0.2.2=py_0
  - lz4-c=1.9.3=h295c915_1
  - markupsafe=2.1.1=py39hb9d737c_1
  - matplotlib-base=3.5.1=py39h2fa2bec_0
  - matplotlib-inline=0.1.3=pyhd8ed1ab_0
  - mistune=0.8.4=py39h3811e60_1005
  - mkl=2021.4.0=h06a4308_640
  - mkl-service=2.4.0=py39h7f8727e_0
  - mkl_fft=1.3.1=py39hd3c417c_0
  - mkl_random=1.2.2=py39h51133e4_0
  - munkres=1.1.4=pyh9f0ad1d_0
  - nbclient=0.6.0=pyhd8ed1ab_0
  - nbconvert=6.5.0=pyhd8ed1ab_0
  - nbconvert-core=6.5.0=pyhd8ed1ab_0
  - nbconvert-pandoc=6.5.0=pyhd8ed1ab_0
  - nbformat=5.3.0=pyhd8ed1ab_0
  - ncurses=6.3=h7f8727e_2
  - nest-asyncio=1.5.5=pyhd8ed1ab_0
  - nettle=3.7.3=hbbd107a_1
  - networkx=2.7.1=pyhd3eb1b0_0
  - notebook=6.4.10=pyha770c72_0
  - numexpr=2.8.1=py39h6abb31d_0
  - numpy=1.21.5=py39he7a7128_1
  - numpy-base=1.21.5=py39hf524024_1
  - ogb=1.3.3=pyhd8ed1ab_0
  - openh264=2.1.1=h4ff587b_0
  - openssl=3.0.3=h166bdaf_0
  - outdated=0.2.1=pyhd8ed1ab_0
  - packaging=21.3=pyhd3eb1b0_0
  - pandas=1.4.1=py39h295c915_1
  - pandoc=2.18=ha770c72_0
  - pandocfilters=1.5.0=pyhd8ed1ab_0
  - parso=0.8.3=pyhd8ed1ab_0
  - pcre=8.45=h9c3ff4c_0
  - pexpect=4.8.0=pyh9f0ad1d_2
  - pickleshare=0.7.5=py_1003
  - pillow=9.0.1=py39h22f2fdc_0
  - pip=21.2.4=py39h06a4308_0
  - pixman=0.40.0=h36c2ea0_0
  - prometheus_client=0.14.1=pyhd8ed1ab_0
  - prompt-toolkit=3.0.29=pyha770c72_0
  - protobuf=3.18.0=py39he80948d_0
  - psutil=5.9.0=py39hb9d737c_1
  - pthread-stubs=0.4=h36c2ea0_1001
  - ptyprocess=0.7.0=pyhd3deb0d_0
  - pure_eval=0.2.2=pyhd8ed1ab_0
  - pycairo=1.21.0=py39h0934665_1
  - pycparser=2.21=pyhd3eb1b0_0
  - pygments=2.11.2=pyhd8ed1ab_0
  - pyopenssl=22.0.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pyrsistent=0.18.1=py39hb9d737c_1
  - pysocks=1.7.1=py39h06a4308_0
  - python=3.9.7=hf930737_3_cpython
  - python-dateutil=2.8.2=pyhd3eb1b0_0
  - python-fastjsonschema=2.15.3=pyhd8ed1ab_0
  - python-levenshtein=0.12.2=py39hb9d737c_2
  - python_abi=3.9=2_cp39
  - pytorch=1.11.0=py3.9_cuda10.2_cudnn7.6.5_0
  - pytorch-mutex=1.0=cuda
  - pytz=2021.3=pyhd3eb1b0_0
  - pyzmq=22.3.0=py39headdf64_2
  - readline=8.1.2=h7f8727e_1
  - reportlab=3.5.68=py39he59360d_1
  - requests=2.27.1=pyhd3eb1b0_0
  - scipy=1.6.2=py39had2a1c9_1
  - send2trash=1.8.0=pyhd8ed1ab_0
  - setuptools=61.2.0=py39h06a4308_0
  - six=1.16.0=pyhd3eb1b0_1
  - soupsieve=2.3.1=pyhd8ed1ab_0
  - sqlalchemy=1.4.35=py39hb9d737c_0
  - sqlite=3.38.2=hc218d9a_0
  - stack_data=0.2.0=pyhd8ed1ab_0
  - tensorboardx=2.5=pyhd8ed1ab_0
  - terminado=0.13.3=py39hf3d152e_1
  - threadpoolctl=3.1.0=pyh8a188c0_0
  - tinycss2=1.1.1=pyhd8ed1ab_0
  - tk=8.6.11=h1ccaba5_0
  - torchaudio=0.11.0=py39_cu102
  - torchvision=0.12.0=py39_cu102
  - tornado=6.1=py39hb9d737c_3
  - tqdm=4.63.0=pyhd3eb1b0_0
  - traitlets=5.1.1=pyhd8ed1ab_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - tzdata=2022a=hda174b7_0
  - unicodedata2=14.0.0=py39hb9d737c_1
  - urllib3=1.26.8=pyhd3eb1b0_0
  - wcwidth=0.2.5=pyh9f0ad1d_2
  - webencodings=0.5.1=py_1
  - wheel=0.37.1=pyhd3eb1b0_0
  - xorg-kbproto=1.0.7=h7f98852_1002
  - xorg-libice=1.0.10=h7f98852_0
  - xorg-libsm=1.2.2=h470a237_5
  - xorg-libx11=1.7.2=h7f98852_0
  - xorg-libxau=1.0.9=h7f98852_0
  - xorg-libxdmcp=1.1.3=h7f98852_0
  - xorg-libxext=1.3.4=h7f98852_1
  - xorg-libxrender=0.9.10=h7f98852_1003
  - xorg-renderproto=0.11.1=h7f98852_1002
  - xorg-xextproto=7.3.0=h7f98852_1002
  - xorg-xproto=7.0.31=h7f98852_1007
  - xz=5.2.5=h7b6447c_0
  - zeromq=4.3.4=h9c3ff4c_1
  - zipp=3.8.0=pyhd8ed1ab_0
  - zlib=1.2.11=h7f8727e_4
  - zstd=1.4.9=haebb681_0

x.1.3 pip 安装

由于pip的“特殊性和极为特殊的依赖性”,往往并不能一次性安装好,使用pip循环遍历多次安装:即依次安装不好,将安装失败的注释掉,接着安装剩下的。一遍循环完毕后,将安装好的注释掉,将上一次安装失败的解注释,继续安装。循环往复,直到安装好。

pip install -r requirements.txt
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/

requirements.txt如下,

absl-py==1.0.0
antlr4-python3-runtime==4.9.3
astor==0.7.1
autograd==1.4
autograd-gamma==0.5.0
ax-platform==0.2.5.1
botorch==0.6.4
cachetools==5.0.0
captum==0.0.1
cilog==1.2.3
cloudpickle==2.0.0
dgllife==0.2.9
dive-into-graphs==0.2.0

torch-scatter==2.0.9
torch-sparse==0.6.13
torch-cluster==1.6.0
torch-spline_conv==1.2.1
torch-geometric==2.0.4

x.2 碰到问题

Traceback (most recent call last):
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/root/.vscode-server/extensions/ms-python.python-2022.6.0/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/root/.vscode-server/extensions/ms-python.python-2022.6.0/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/root/.vscode-server/extensions/ms-python.python-2022.6.0/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/yingmuzhi/high_ppi/HIGH-PPI/model_train.py", line 317, in <module>
    main()
  File "/home/yingmuzhi/high_ppi/HIGH-PPI/model_train.py", line 308, in main
    train(batch, p_x_all, p_edge_all, model, graph, ppi_list, loss_fn, optimizer, device,
  File "/home/yingmuzhi/high_ppi/HIGH-PPI/model_train.py", line 135, in train
    output = model(batch, p_x_all, p_edge_all, graph.edge_index_got, train_edge_id)
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/yingmuzhi/high_ppi/HIGH-PPI/gnn_models_sag.py", line 170, in forward
    embs = self.BGNN(x, edge, batch-1)
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/yingmuzhi/high_ppi/HIGH-PPI/gnn_models_sag.py", line 117, in forward
    x = self.conv1(x, edge_index)
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch_geometric/nn/conv/gcn_conv.py", line 210, in forward
    edge_index, edge_weight = gcn_norm(  # yapf: disable
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch_geometric/nn/conv/gcn_conv.py", line 66, in gcn_norm
    if is_torch_sparse_tensor(edge_index):
  File "/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch_geometric/utils/sparse.py", line 68, in is_torch_sparse_tensor
    if src.layout == torch.sparse_csc:
AttributeError: module 'torch' has no attribute 'sparse_csc'

cuda error

train gnn, train_num: 5328, valid_num: 1332
cuda:0
/opt/conda/envs/HIGH-PPI/lib/python3.9/site-packages/torch/cuda/__init__.py:145: UserWarning: 
NVIDIA A40 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_61 sm_70 sm_75 compute_37.
If you want to use the NVIDIA A40 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

  warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))

使用查看cuda版本

import torch

print(torch.version.cuda)

动手深度学习纸质书: https://j.youzan.com/2E82KT(半价购书)

torch_geometric error

请添加图片描述

安装torch和对应cudatoolkit。

x.2.1 anaconda(可选)

使用python3.9

conda create -n env_cp39_GNN python=3.9

x.2.2 torch

参考 https://pytorch.org/get-started/previous-versions/

使用torch1.11和cuda10.2。需要注意的是1.11后的使用+指定tookkit,如torch==1.12.0+cu102; 2.0以后的使用-指定toolkit,如pytorch==2.0.0 pytorch-cuda=11.7

# CUDA 10.2
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=10.2 -c pytorch
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值