Conda에서 pyg 설치하기 (CUDA 버전 맞추기)
연구실 서버를 고쳐야 하는데 실험을 중단할 순 없으니 학과 서버를 대여하기로 했다.
그래서 개발환경을 다시 설정해야하는데...
연구실 GPU의 CUDA version이 달라서 완전히 똑같은 세팅을 할 순 없었다.
Update: 2024.11.06 (CUDA 10.1)
아니 이번에는 cuda 버전이 10.1이다
더 낮은 버전이다.......
미치겠다
하루종일 또 시간 걸려서 겨우 설치했다
cuda 10.1이 되는 pytorch를 1.8.1로 설치하고 나머지는 아래 참고
[3] 덕분에 해결했다
(pyg_env) $ python -c "import torch; print(torch.__version__)"
1.8.1+cu101
(pyg_env) $ python -c "import torch; print(torch.version.cuda)"
10.1
(pyg_env) $ pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Looking in links: https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Collecting torch-scatter
Downloading https://data.pyg.org/whl/torch-1.8.0%2Bcu101/torch_scatter-2.0.8-cp38-cp38-linux_x86_64.whl (7.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.9/7.9 MB 11.4 MB/s eta 0:00:00
Installing collected packages: torch-scatter
Successfully installed torch-scatter-2.0.8
(pyg_env) $ pip install --no-index torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Looking in links: https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Collecting torch-sparse
Downloading https://data.pyg.org/whl/torch-1.8.0%2Bcu101/torch_sparse-0.6.12-cp38-cp38-linux_x86_64.whl (3.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 5.6 MB/s eta 0:00:00
Requirement already satisfied: scipy in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-sparse) (1.8.1)
Requirement already satisfied: numpy<1.25.0,>=1.17.3 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from scipy->torch-sparse) (1.22.3)
Installing collected packages: torch-sparse
Successfully installed torch-sparse-0.6.12
(pyg_env) $ pip install --no-index torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Looking in links: https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Collecting torch-cluster
Downloading https://data.pyg.org/whl/torch-1.8.0%2Bcu101/torch_cluster-1.5.9-cp38-cp38-linux_x86_64.whl (1.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 3.7 MB/s eta 0:00:00
Installing collected packages: torch-cluster
Successfully installed torch-cluster-1.5.9
(pyg_env) $ pip install --no-index torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Looking in links: https://pytorch-geometric.com/whl/torch-1.8.1+cu101.html
Collecting torch-spline-conv
Downloading https://data.pyg.org/whl/torch-1.8.0%2Bcu101/torch_spline_conv-1.2.1-cp38-cp38-linux_x86_64.whl (705 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 705.1/705.1 kB 2.8 MB/s eta 0:00:00
Installing collected packages: torch-spline-conv
Successfully installed torch-spline-conv-1.2.1
(pyg_env) $ pip uninstall torch-geometric -y
Found existing installation: torch-geometric 2.6.1
Uninstalling torch-geometric-2.6.1:
Successfully uninstalled torch-geometric-2.6.1
(pyg_env) $ pip install torch-geometric==2.0.4
Collecting torch-geometric==2.0.4
Downloading torch_geometric-2.0.4.tar.gz (407 kB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: tqdm in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (4.66.6)
Requirement already satisfied: numpy in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (1.22.3)
Requirement already satisfied: scipy in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (1.8.1)
Requirement already satisfied: pandas in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (1.4.2)
Requirement already satisfied: jinja2 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (3.1.4)
Requirement already satisfied: requests in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (2.32.3)
Requirement already satisfied: pyparsing in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (3.1.4)
Requirement already satisfied: scikit-learn in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from torch-geometric==2.0.4) (1.1.1)
Requirement already satisfied: MarkupSafe>=2.0 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from jinja2->torch-geometric==2.0.4) (2.1.5)
Requirement already satisfied: python-dateutil>=2.8.1 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from pandas->torch-geometric==2.0.4) (2.9.0)
Requirement already satisfied: pytz>=2020.1 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from pandas->torch-geometric==2.0.4) (2024.2)
Requirement already satisfied: charset-normalizer<4,>=2 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from requests->torch-geometric==2.0.4) (3.4.0)
Requirement already satisfied: idna<4,>=2.5 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from requests->torch-geometric==2.0.4) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from requests->torch-geometric==2.0.4) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from requests->torch-geometric==2.0.4) (2024.8.30)
Requirement already satisfied: joblib>=1.0.0 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from scikit-learn->torch-geometric==2.0.4) (1.4.2)
Requirement already satisfied: threadpoolctl>=2.0.0 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from scikit-learn->torch-geometric==2.0.4) (3.5.0)
Requirement already satisfied: six>=1.5 in ./anaconda3/envs/pyg_env/lib/python3.8/site-packages (from python-dateutil>=2.8.1->pandas->torch-geometric==2.0.4) (1.16.0)
Building wheels for collected packages: torch-geometric
Building wheel for torch-geometric (setup.py) ... done
Created wheel for torch-geometric: filename=torch_geometric-2.0.4-py3-none-any.whl size=616578 sha256=a52536651ee4984ecf8c36639145a9b40b034c6ecbec57c9a2113ad34cd82796
Stored in directory: /home/XXXXX/.cache/pip/wheels/c1/be/e9/b90ded2a496c975a539af002fe1f0f2a22a97af13b41866d6e
Successfully built torch-geometric
Installing collected packages: torch-geometric
Successfully installed torch-geometric-2.0.4
(pyg_env) $ python -c "from torch_geometric.nn import GCNConv; print('PyTorch Geometric installed successfully')"
PyTorch Geometric installed successfully
(pyg_env) $ python -c "import torch; print(torch.cuda.is_available())"
True
PyTorch 버전 확인하기
구글에 torch cuda 11.1을 입력하면 Previous PyTorch Versions라고 공식 홈페이지를 찾을 수 있다.
최신 버전을 사용하기를 권장하지만, 실험 세팅이나 라이브러리 dependency 때문에 항상 최신버전을 사용할 수 없다.
그런 개발자들을 위해 이곳 [1]에서 각자 환경에 맞는 torch를 찾으면 된다.
cuda version이 11.1이지만, 정확히 11.1을 맞출 필요는 없다. (아마도) 11.1 이하이면 된다.
지금 당장 설치할 것이 아니다. 버전에 맞는 명령어를 일단 찾아준다.
Pytorch-geometric 설치하기
이제 pytorch geometric install 홈페이지를 찾아간다.
불행히도 cuda버전이 11.1인건 보이지 않는다.
스크롤을 아래로 내리면 CUDA 버전에 맞게 알아서 설치해준다고 한다.
근데 설치되는 명령어를 잘 보면, pytorch의 버전 이름에 cpu가 붙는 경우가 있다.
그래서 pytorch를 다시 설치해야한다.
Summary
1) CUDA 버전에 맞는 torch 버전을 찾아둔다. (아직 설치하지 않음)
2) pytorch-geometric을 먼저 설치한다. CUDA버전에 맞추어 자동으로 설치 가능하다.
conda install pyg=*=*cu* -c pyg
3) 사실 2)에서 pytorch를 설치하는데, cuda버전에만 맞고 종종 cpu버전으로 자동 설치될 수 있다.
그래서 1)에서 찾은 torch 버전으로 재설치한다.
나의 경우 아래 10.2 버전으로 재설치했다.
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch
4) torch가 cuda를 잘 읽는지 확인한다.
$ python -c "import torch; print(torch.cuda.is_available())"
>>> True
>>> exit()
$
References
[1] PyTorch https://pytorch.org/get-started/previous-versions/
[2] pytorch-geometric https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html
[3] https://github.com/pyg-team/pytorch_geometric/issues/8523
'Tutorial, Guide' 카테고리의 다른 글
[LaTeX] Greek letters and usages (수학, 과학의 그리스 문자의 쓰임) (0) | 2024.03.25 |
---|---|
vscode 업데이트로 접속이 안될 때 (0) | 2023.12.19 |
Python의 round는 사사오입? 오사오입? (1) | 2023.10.01 |
[LaTeX] 여러가지 수학 폰트들 (mathcal, mathbb 등) (0) | 2023.08.30 |
[Error] ValueError: Expected more than 1 value per channel when training, got input size ~ (0) | 2023.08.23 |