当前位置:   article > 正文

PyTorch——报错解决:RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.94 GiB total c_torch.cuda.outofmemoryerror: cuda out of memory. t

torch.cuda.outofmemoryerror: cuda out of memory. tried to allocate 20.00 mib

1、完整报错

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.00 GiB total capacity; 2.41 GiB already allocated; 5.70 MiB free; 2.56 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

2、原因

batch_size过大,导致内存容量撑不住了。
通过打开任务管理器,我们很清楚的发现,原因就是内存容量不足,导致报错。
在这里插入图片描述

3、解决方法

减小batch_size

正常运行:
在这里插入图片描述
任务管理器检测情况:
在这里插入图片描述

参考文章

  1. 深度学习中的batch的大小对学习效果有何影响?
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/220635
推荐阅读
相关标签
  

闽ICP备14008679号