在CentOS上安裝PyTorch的步驟如下:
首先,下載并安裝Miniconda,這是一個輕量級的Anaconda發行版,包含conda、Python以及依賴包。
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh
按照提示完成安裝。
創建一個新的Conda環境,并激活它。假設我們創建一個名為torch
的環境,并使用Python 3.10。
conda create -n torch python=3.10
conda activate torch
根據你的GPU型號和CentOS系統,從NVIDIA官方網站下載并安裝合適的CUDA Toolkit和cuDNN庫。
wget https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_530.30.02_linux.run
sudo sh cuda_12.1.1_530.30.02_linux.run
wget https://developer.nvidia.com/compute/machine-learning/cudnn/12.1.1.30/Production/12.1_20211031/cudnn-12.1.1.30-linux-x64-v8.0.4.30.tgz
tar -xzvf cudnn-12.1.1.30-linux-x64-v8.0.4.30.tgz
sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
在激活的Conda環境中,使用pip安裝PyTorch。你可以從PyTorch官方網站獲取安裝命令。
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
創建一個名為test_pytorch.py
的Python腳本,內容如下:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
運行此腳本以驗證PyTorch是否已成功安裝:
python test_pytorch.py
如果輸出顯示PyTorch的版本號和True
(表示CUDA可用),則表示安裝成功。
以上步驟應該可以幫助你在CentOS上成功安裝PyTorch。如果在安裝過程中遇到問題,可以參考PyTorch官方文檔或相關社區論壇尋求幫助。