解决:RuntimeError: CUDA out of memory. Tried to allocate 160.00 MiB (GPU 0; 10.76 GiB total capacity..

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

完整报错:

RuntimeError: CUDA out of memory. Tried to allocate 160.00 MiB (GPU 0; 10.76 GiB total capacity; 9.58 GiB already allocated; 135.31 MiB free; 9.61 GiB reserved in total by PyTorch)

 

问题分析:

内存分配不足:需要160MB,,但GPU只剩下135.31MB。

解决办法:

1.减小batch_size。注意batchsize的调整要配合学习率的调整,一般是正比关系,BS增大两倍,LR增大两倍或者根号二倍。减小也是相应更改。


2.运行torch.cuda.empty_cache()函数。加在训练开始前即可。


3.释放GPU内存,kill掉没用的进程。


4.更改使用的显卡。这里大多指在服务器上运行,没有制定显卡,都默认使用第一张,或者多人使用,产生的不足。
 

5.降低num_workers,num_workers参数是加载数据的线程数目,有可能电脑(服务器)的线程数不满足所配置的参数。如果电脑是8线程,参数调为8就不合适,可相应降低。但num_worker越小,训练越慢,可权衡后调整。

综合调小了num_workers和 batch_size后,报错消失,代码正常运行。以上五种方法都试一下,大部分报错可解决。文章来源地址https://www.toymoban.com/news/detail-598044.html

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

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

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

相关文章

  • 报错解决: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日
    浏览(40)
  • 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日
    浏览(26)
  • RuntimeError: CUDA out of memory.【多种场景下的解决方案】

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

    2024年02月22日
    浏览(36)
  • 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日
    浏览(41)
  • 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日
    浏览(21)
  • 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日
    浏览(41)
  • 【已解决】探究CUDA out of memory背后原因,如何释放GPU显存?

    研究过深度学习的同学,一定对类似下面这个CUDA显存溢出错误不陌生 RuntimeError: CUDA out of memory. Tried to allocate 916.00 MiB (GPU 0; 6.00 GiB total capacity; 4.47 GiB already allocated; 186.44 MiB free; 4.47 GiB reserved in total by PyTorch) 本文探究CUDA的内存管理机制,并总结该问题的解决办法 在实验开始前

    2023年04月20日
    浏览(87)
  • 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)
  • Ubuntu下跑Aplaca报错:torch.cuda.0utofMemoryError: CUDA out of memory.解决办法(查看CUDA占用情况&清除GPU缓存)

    错误提示: torch.cuda.0utofMemoryError: CUDA out of memory.Tried to allocate 2.00 MiB (PU 0; 23.69 GiB total capacity; 237 BiB already allocated; 18.38 MiB fre; 2.50 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_

    2024年02月11日
    浏览(37)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包