验证与安装
验证与安装
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
# 官方索引安装(cu 后为 CUDA 版本,如 cu124)
pip install torch --index-url https://download.pytorch.org/whl/cu<版本号>| 判断顺序 | 先 torch.cuda.is_available(),再看 torch.version.cuda |
|---|---|
| 常见错配 | CPU 版 wheel 装进了 GPU 机器 |
| 排查点 | which python 与 pip 是否同一环境 |
容器镜像里 torch 与 CUDA 已配好:推理部署优先容器化,宿主机手工装 torch 仅用于开发验证。