Files
hwd32 eaea556056 docs(05): 补 PyTorch 实机跑通记录
- torch 2.12.0 + torchvision 0.27.0 + torchaudio 2.11.0
- CUDA True | GPU: NVIDIA GeForce RTX 5060 Ti 验证通过
- 装 5 分钟(清华源代理)
- 附实机安装日志和验证输出
- README 进度表 05 改成 
2026-06-14 12:12:20 +08:00

136 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 05 PyTorch 验证
## 目标
装 PyTorch + cu128,验证能调用 5060 Ti。
> **本机实测版本**2026-06-14):
> - Python 3.11.15
> - torch 2.12.0
> - torchvision 0.27.0
> - torchaudio 2.11.0
> - triton 3.7.0
> - CUDA Toolkit 12.8(系统层) + CUDA Runtime 13.0.96PyTorch 自带)
> - 下载耗时:5 分钟(清华源代理)
## 装 venv
**WSL2 Ubuntu 终端**
```bash
cd /mnt/d/llm-code
uv venv --python 3.11 .venv
source .venv/bin/activate
```
**应当看到**命令行前缀变成 `(.venv) eric@...`
## 装 PyTorch(用清华源代理,国内最快)
```bash
uv pip install torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/cu128 \
--extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple
```
| 参数 | 用途 |
|------|------|
| `--index-url` | 强制走 PyTorch 官方源(拉 cu128 专用 wheel|
| `--extra-index-url` | 补充源,其他依赖走清华(`pypi.tuna.tsinghua.edu.cn`|
**不要**同时加 `--index-url``-i`uv 会报"重复"。
**预计 5-15 分钟**(约 2.5 GB 下载)。
### 实机安装日志(2026-06-14
```
Resolved 33 packages in 2.11s
Prepared 33 packages in 5m 00s
Installed 33 packages in 5m 19s
+ torch==2.12.0
+ torchaudio==2.11.0
+ torchvision==0.27.0
+ triton==3.7.0
+ nvidia-cublas==13.1.1.3
+ nvidia-cuda-runtime==13.0.96
+ nvidia-cudnn-cu13==9.20.0.48
+ nvidia-nccl-cu13==2.29.7
+ ...(共 33 个包,含 NVIDIA 13.x 系列 CUDA 库)
```
> **注意**:装 PyTorch 2.12 时它**自动拉了 CUDA 13.x 的运行时包**cublas/cudnn/nccl 等),但**用的是系统层的 CUDA Toolkit 12.8**`nvcc`)来编译扩展。这两套并存,**没问题**——PyTorch 编译时认 12.8,运行用 13.0,版本对得上。
## 验证(关键!)
```bash
python -c "import torch; print('CUDA:', torch.cuda.is_available(), '| GPU:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'NONE')"
```
**应输出**
```
CUDA: True | GPU: NVIDIA GeForce RTX 5060 Ti
```
### 实机输出(2026-06-14
```
(.venv) eric@ERIC-GEM12:/mnt/d/llm-code$ python -c "import torch; print('CUDA:', torch.cuda.is_available(), '| GPU:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'NONE')"
CUDA: True | GPU: NVIDIA GeForce RTX 5060 Ti
```
**PyTorch 链路全打通**
## 跑个真测试(确认能算东西)
```bash
python -c "
import torch
x = torch.randn(1000, 1000, device='cuda')
y = torch.randn(1000, 1000, device='cuda')
z = x @ y
print('矩阵乘法 OK, 形状:', z.shape, '设备:', z.device)
print('显存占用:', torch.cuda.memory_allocated()/1e9, 'GB')
"
```
**应输出**
```
矩阵乘法 OK, 形状: torch.Size([1000, 1000]) 设备: cuda:0
显存占用: 8.0... GB
```
## 镜像版本必须匹配
| torch | torchvision | torchaudio |
|------|------|------|
| 2.7.0 | 0.22.0 | 2.7.0 |
| 2.7.1 | 0.22.1 | 2.7.1 |
| 2.8.0 | 0.23.0 | 2.8.0 |
**不要混搭**(如 torch 2.7.1 + torchvision 0.22.0,会出兼容警告)。
## 常见问题
### 输出 `CUDA: False`
按顺序排查:
1. `nvidia-smi` 在 WSL2 能不能看到卡
2. `nvcc --version` 是不是 12.8
3. 重新装一遍 PyTorch(可能是装时网络断了,下了不完整的 wheel)
### 装时报 `pip` 相关错
```bash
deactivate
uv venv --python 3.11 .venv --clear
source .venv/bin/activate
# 重装
```
### 装完 import 报 `libcudart.so not found`
CUDA Toolkit 没装好,回到 [03 WSL2 + CUDA 12.8](./03-wsl2-ubuntu.md) 重新装。
## 下一步
✅ 通过后 → [06 ComfyUI 装出图](./06-comfyui-image.md)