Linux与PyTorch的集成方式主要有以下几种:
pip install torch torchvision torchaudiopip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118(以CUDA 11.8为例)conda install pytorch torchvision torchaudio cpuonly -c pytorchconda install pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch -c nvidiadocker pull pytorch/pytorch:latestdocker run --gpus all -it pytorch/pytorch:latest验证安装:
通过Python代码检查版本及CUDA可用性:
import torch  
print(torch.__version__)  
print(torch.cuda.is_available())  # 若为GPU版本,返回True表示CUDA可用  
注意事项:
venv或conda)隔离项目依赖。