RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

这篇具有很好参考价值的文章主要介绍了RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

这是我遇到的问题,刚开始的时候怎么也解决不了。

RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

然后我去搜了一下解决方法,具体方法如下:

方法一:

仅需减小batchsize

改文件的配置cfg的batchsize=1,一般在cfg文件下的查找batch或batchsize,将batchsize调小后,再次运行,类似于改下面

RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

方法二 : 

上述方法还没解决,不改batchsize,可以考虑下面的方法的链接

不计算梯度:

ps: 在报错的哪一行代码的上面,加上下面一行代码,不计算梯度

with torch.no_grad()

不计算梯度的方法

方法三:

释放内存:链接如下

释放内存

if hasattr(torch.cuda, 'empty_cache'):

 torch.cuda.empty_cache()ps: 在报错的那一行代码的上面,加上下面两行代码,释放无关的内存

if hasattr(torch.cuda, 'empty_cache'):

 torch.cuda.empty_cache()

方法四:

解决方法:将img-size调小

RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

把原本的[640,640]改为上图所示

方法5:

也就是我解决的方法,我仔细地看了一下的那个报错,发现并不是batchsize的问题,也不是储存的问题,因为我的batchsize=1,储存还有 3G左右,所以排除了。

RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

 RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

 RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

 RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

 RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.

我的pycharm,还有其他的所有东西都在D盘,所以就把D盘设置成100000-100000了,

然后问题就解决了,然后程序就跑起来了。 文章来源地址https://www.toymoban.com/news/detail-410694.html

到了这里,关于RuntimeError:CUDA out of memory.Tried to allocate 20.00MiB.的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • RuntimeError: DefaultCPUAllocator: not enough memory: you tried to allocate 1105920 bytes.

    问题 RuntimeError: [enforce fail at ..c10coreCPUAllocator.cpp:76] data. DefaultCPUAllocator: not enough memory: you tried to allocate 1105920 bytes. 今天在使用自己电脑跑YOLOV7的时候,因为自己没有GPU所以使用CPU来跑测试模型,使用CPU来进行一张独立的图像进行预测,跑一张图像完全没有问题,非常的ni

    2023年04月13日
    浏览(28)
  • 报错解决:RuntimeError: CUDA out of memory.

    在进行深度学习的模型训练时,经常会遇到显存溢出的报错: RuntimeError: CUDA out of memory. 输出如下图所示: 打开一个终端,输入以下命令查看GPU使用情况: 输出如下图所示: 使用nvidia-htop可以进一步查看更为详细的内容。 nvidia-htop:A tool for enriching the output of nvidia-smi. 可以通

    2024年02月12日
    浏览(42)
  • RuntimeError: CUDA out of memory.【多种场景下的解决方案】

    RuntimeError: CUDA out of memory.【多种场景下的解决方案】 🌈 个人主页:高斯小哥 🔥 高质量专栏:【Matplotlib之旅:零基础精通数据可视化】 🏆🏆关注博主,随时获取更多关于深度学习、PyTorch、Python领域的优质内容!🏆🏆   随着深度学习的繁荣发展,GPU已成为推动这一浪

    2024年02月22日
    浏览(39)
  • AI绘画——使用stable-diffusion生成图片时提示RuntimeError: CUDA out of memory处理方法

    RuntimeError: CUDA out of memory. Tried to allocate 1.50 GiB (GPU 0; 8.00 GiB total capacity; 5.62 GiB already allocated; 109.75 MiB free; 5.74 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 1、添加参数–n_

    2024年02月02日
    浏览(44)
  • docker 报错 library initialization failed - unable to allocate file descriptor table - out of memory

    docker容器,启动的时候 容器日志报: library initialization failed - unable to allocate file descriptor table - out of memory docker启动容器时,若未给容器配置ulimit,则从docker守护进程上设置的默认ulimits继承, 这个值太大? 会报这个错 官方文档: dockerd | Docker Docs ulimit nofile这个值太大报错的

    2024年04月29日
    浏览(24)
  • DefaultCPUAllocator: not enough memory: you tried to allocate

    DefaultCPUAllocator: not enough memory: you tried to allocate XXX 问题:系统内存不足。 解决方案(1):重启电脑/使用任务管理器关闭多余应用释放系统内存(临时方案) 任务管理器启用方式:ctrl+alt+del 到达进程页面-右键进程结束任务 解决方案(2):增加电脑虚拟内存(建议选该方案

    2024年02月12日
    浏览(30)
  • docker 启动报错 library initialization failed - unable to allocate file descriptor table - out of memory

    docker 启动报错 library initialization failed - unable to allocate file descriptor table - out of memory 1.报错日志 library initialization failed - unable to allocate file descriptor table - out of memory/cm-server/aiboxCloud-web/boot/entrypoint.sh: line 2: 6 Aborted (core dumped) java -Xms1024m -Xmx2048m -jar -XX:+PrintGCDateStamps -XX:+PrintGCDetai

    2024年02月11日
    浏览(46)
  • Unity 报错之 打包安卓闪退 Could not allocate memory: System out of memory

    更换机器打包,打包机器上没有开发使用的Unity版本,所以更换了Unity2019.4.8f1版本进行导出安卓工程,在安卓工程中打包出现闪退问题。 Unity: Could not allocate memory: System out of memory! Trying to allocate: 4227858432B with 16 alignment. MemoryLabel: DynamicArray Allocation happened at: Line:78 in Memory overv

    2024年02月13日
    浏览(40)
  • CUDA报错:Out of Memory

    如果报错里提示Pytorch reserved的内存远大于Already allocated的内存,那么就是因为分配显存时单位过大,导致出现大量内存碎片无法继续分配(与操作系统内存管理同理)。 我们可以限制一次分配的最大单位来解决这个问题。 随后代码便可正常运行了。

    2024年02月15日
    浏览(48)
  • torch.cuda.OutOfMemoryError: CUDA out of memory.

    训练清华ChatGLM-6B时报错, 原因是显存不够 torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 96.00 MiB (GPU 0; 23.70 GiB total capacity; 4.37 GiB already allocated; 64.81 MiB free; 4.37 GiB reserved in total by PyTorch) If reserved memory is allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentatio

    2024年02月06日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包