CentOS 集成 PyTorch 实操教程
一 环境准备与系统检查
sudo yum update -ysudo yum install -y gcc gcc-c++ make cmake3 git wget python3 python3-pip python3-develnvidia-smi、nvcc --versioncudatoolkit 安装对应版本二 三种常用安装方式
pip install torch torchvision torchaudiopip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117--extra-index-url https://download.pytorch.org/whl/cu113/cu116/cu120conda install pytorch torchvision torchaudio cpuonly -c pytorchconda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorchdocker run --gpus all -it --rm pytorch/pytorch:latest bashpip install -r requirements.txt)后构建运行三 安装验证与常见问题
python - <<'PY' import torch print("torch:", torch.__version__) print("cuda:", torch.cuda.is_available()) if torch.cuda.is_available(): print("device:", torch.cuda.get_device_name(0)) PYnvcc --version 找不到:安装/配置 CUDA Toolkit,或改用 conda 的 cudatoolkitpip install -U pip),使用国内镜像或官方 whl 源torch.cuda.is_available() 为 False:检查 驱动版本、CUDA 与 PyTorch 版本匹配、容器是否启用 --gpus四 进阶与部署
gcc >= 7.3.0、cmake >= 3.12.0;克隆 PyTorch 仓库后 git submodule update --init --recursive,按需设置环境变量并执行 python setup.py installtorch.jit.trace/script)或 ONNX 导出,服务端可用 ONNX Runtime 推理