显存容量 / 分配器碎片
CUDA out of memory (GPU 显存不足与碎片) 排查指南
报错看似显存不够用,但实际常见两种截然不同的原因:可用物理 HBM 真的见底,或者 PyTorch 缓存分配器出现大量空洞碎片。
典型日志特征
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 79.15 GiB total capacity; 75.80 GiB already allocated; 1.12 GiB free)根本原因与次生级联症状辨析
当报错中 `allocated` 明显低于显卡容量而 `reserved` 接近上限时,说明分配器保留块被碎片分割;若两者均接近硬件上限,则需削减激活值、批次大小、上下文或增加并行切片。
重启节点前先收集的取证命令
nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True,max_split_size_mb:128"
python3 -c "import torch; print(torch.cuda.memory_summary())"安全排查与恢复步骤
- 对照报错行中的 `already allocated` 与 `reserved in total by PyTorch`,先区分真超限与碎片。
- 存在明显保留差值时设置 `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True` 重试。
- 真耗尽显存时开启 activation checkpointing、调小微批次、改用 BF16/FP8 或提升 TP/FSDP 切分度。
Live diagnosis, no signup
粘贴你的 GPU 日志,立即排查首发故障
提交前会在当前浏览器本地自动遮罩 IP、密钥和私有路径,安全分离根因。
Before uploading, review cloud data handling and local options.
training_logs.txt
No log to hand? Try one:
Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.
3 free cloud diagnoses per day
常见问题
nvidia-smi 显示还有几 GB 空闲为什么仍报 CUDA OOM?
单次张量申请需要连续虚拟地址或块大小不足,也可能是同节点其他进程正在抢占同一张卡。
如何在上线前提前估算显存需求?
可使用 Denpex 简体中文大模型显存计算器(/zh/vram-calculator)预估权重和 KV 缓存。
相关简体中文 GPU 排障条目
vLLM KV 缓存不足 (No available memory for the cache blocks)宿主机内存 OOM-killer (SIGKILL / exit 137) 诊断NCCL Watchdog 超时排查与源头节点定位打开免费 LLM 显存计算器
英文完整百科档案:查看完整英文参考 (English)
免费试用 Denpex 30 天。完全免费。
无需信用卡,无自动续费。使用团队已复盘的故障日志亲自验证诊断效果。
开启 30 天免费 Team 团队评估
30 天内每日最多 50 次诊断。验证企业工作邮箱即可激活试用,回放已解决的历史故障并将根因证据与团队确认结论对比。