Linux與PyTorch的集成方式主要有以下幾種:
pip install torch torchvision torchaudio
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
(以CUDA 11.8為例)conda install pytorch torchvision torchaudio cpuonly -c pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch -c nvidia
docker pull pytorch/pytorch:latest
docker run --gpus all -it pytorch/pytorch:latest
驗證安裝:
通過Python代碼檢查版本及CUDA可用性:
import torch
print(torch.__version__)
print(torch.cuda.is_available()) # 若為GPU版本,返回True表示CUDA可用
注意事項:
venv
或conda
)隔離項目依賴。