LAM单图秒级打造超写实3D数字人头部CUDA out of memory

RuntimeError: CUDA out of memory. Tried to allocate 190.21 GiB. GPU 0 has a total capacity of 6.00 GiB of which 1.97 GiB is free. Of the allocated memory 2.90 GiB is allocated by PyTorch, and 53.60 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

RuntimeError: CUDA 内存不足。尝试分配 190.21 GiB。GPU 0 的总容量为 6.00 GiB,其中 1.97 GiB 空闲。已分配内存中,2.90 GiB 由 PyTorch 分配,53.60 MiB 由 PyTorch 保留但未分配。如果保留但未分配的内存较大,尝试设置 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True 以避免碎片化。有关内存管理的文档,请参阅 PyTorch 官方说明 


错误分析:

  1. 内存不足 :GPU 总显存为 6.00 GiB,但程序尝试分配 190.21 GiB,远超可用范围
  • 已分配内存 :PyTorch 已占用 2.90 GiB,另有 53.60 MiB 保留但未使用。
  • 解决方案提示
    • 减小批量大小(batch size) :降低每次迭代的数据量以减少显存占用。
  • 释放缓存 :使用 torch.cuda.empty_cache() 清理未使用的显存。
  • 设置环境变量 :通过 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True 优化内存分配策略,减少碎片化。
  • 混合精度训练 :使用 torch.cuda.amp 降低显存需求。
  • 检查显存占用 :运行 nvidia-smi 查看具体占用进程,必要时结束占用显存的进程。

资源要求:

4 vCPU

15.0 GiB

1 * NVIDIA T4

1 * 16 GB

你可能感兴趣的:(人工智能,python,LAM,人工智能)