当前位置: 首页 > news >正文

网站 搭建 亚洲服务器网络推广营销方案免费

网站 搭建 亚洲服务器,网络推广营销方案免费,网页设计有哪些岗位,长沙门户网站解决CUDA out of memory. 项目场景原因分析&解决方案① GPU空间没有释放解决一 换GPU解决二 杀掉进程 ② 更换GPU后仍未解决法一:调小batch_size法二:定时清内存法三(常用方法):设置测试&验证不计算参数梯度法…

解决CUDA out of memory.

  • 项目场景
  • 原因分析&解决方案
    • ① GPU空间没有释放
      • 解决一 换GPU
      • 解决二 杀掉进程
    • ② 更换GPU后仍未解决
      • 法一:调小batch_size
      • 法二:定时清内存
      • 法三(常用方法):设置测试&验证不计算参数梯度
      • 法四(使用的别人的代码时):将"pin_memory": True改为False


请添加图片描述

🌈你好呀!我是 是Yu欸
🌌 2024每日百字篆刻时光,感谢你的陪伴与支持 ~
🚀 欢迎一起踏上探险之旅,挖掘无限可能,共同成长!

前些天发现了一个人工智能学习网站,内容深入浅出、易于理解。如果对人工智能感兴趣,不妨点击查看。

如果你喜欢我的文章,欢迎三连给我鼓励和支持:👍点赞 📁 关注 💬评论,我会给大家带来更多有用有趣的文章。
分享「《PYTHON自然语言处理(中文版)》.pdf」,点击链接即可保存。
链接:https://pan.quark.cn/s/a2cfaaaf586a
提取码:t3pK

项目场景

跑bert-seq2seq的代码时,出现报错

RuntimeError: CUDA out of memory. Tried to allocate 870.00 MiB (GPU 2; 23.70 GiB total capacity; 19.18 GiB already allocated; 323.81 MiB free; 21.70 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

运行时错误:CUDA内存不足。试图分配870.00 MiB (GPU 2;23.70 GiB总容量;19.18 GiB已经分配;323.81 MiB空闲;如果分配的内存是>,>分配的内存尝试设置max_split_size_mb以避免碎片。请参阅文档了解内存管理和PYTORCH_CUDA_ALLOC_CONF

在这里插入图片描述

参考:
https://blog.csdn.net/qq_37555071/article/details/108346569
https://blog.csdn.net/xiyou__/article/details/118529350


原因分析&解决方案

① GPU空间没有释放

可能为PyTorch占用的GPU空间没有释放,导致下次运行时,出现CUDA out of memory。
命令行输入 nvidia-smi,显示GPU的使用情况,以及占用GPU的应用程序

nvidia-smi

在这里插入图片描述
此时发现仅GPU:0有4778MIB的占用
有两种解决方案

解决一 换GPU

将代码中的默认0,换成指定2

# device = "cuda" if torch.cuda.is_available() else 'cpu'
device = torch.device('cuda:2')

解决二 杀掉进程

windows系统输入taskkill -PID 进程号 -F 结束占用的进程,比如

taskkill -PID 7072 -F

linux系统输入kill 进程号 结束占用的进程,比如

kill 7072

在这里插入图片描述

然后再次输入 nvidia-smi 查看GPU使用情况


② 更换GPU后仍未解决

法一:调小batch_size

设到4基本上能解决问题,如果还不行,该方法pass。

法二:定时清内存

在报错处、代码关键节点(一个epoch跑完…)插入以下代码(目的是定时清内存):

import torch, gcgc.collect()
torch.cuda.empty_cache()

法三(常用方法):设置测试&验证不计算参数梯度

在测试阶段和验证阶段前插入代码 with torch.no_grad()(目的是该段程序不计算参数梯度),如下:

def test(model,dataloader):model.eval()with torch.no_grad(): ###插在此处for batch in tqdm(dataloader):……

法四(使用的别人的代码时):将"pin_memory": True改为False

如果怎么修改,都会出现题中bug,甚至跑了几轮之后突然出现 cuda out of
memory,查看代码中是否存在一下代码(通常出现在main.py 或者数据加载的py文件中:

kwargs = {'num_workers': 6, 'pin_memory': True} if torch.cuda.is_available() else {}

将"pin_memory": True改为False,具体原因原博:

pin_memory就是锁页内存,创建DataLoader时,设置pin_memory=True,则意味着生成的Tensor数据最开始是属于内存中的锁页内存,这样将内存的Tensor转义到GPU的显存就会更快一些。
主机中的内存,有两种存在方式,一是锁页,二是不锁页,锁页内存存放的内容在任何情况下都不会与主机的虚拟内存进行交换(注:虚拟内存就是硬盘),而不锁页内存在主机内存不足时,数据会存放在虚拟内存中。显卡中的显存全部是锁页内存,当计算机的内存充足的时候,可以设置pin_memory=True。当系统卡住,或者交换内存使用过多的时候,设置pin_memory=False。因为pin_memory与电脑硬件性能有关,pytorch开发者不能确保每一个炼丹玩家都有高端设备,因此pin_memory默认为False。


文章转载自:
http://dinncocondemned.wbqt.cn
http://dinncoredeeming.wbqt.cn
http://dinncoamitabha.wbqt.cn
http://dinncounlessoned.wbqt.cn
http://dinncoepileptoid.wbqt.cn
http://dinncobeerengine.wbqt.cn
http://dinncobenty.wbqt.cn
http://dinncobefriend.wbqt.cn
http://dinncocorrect.wbqt.cn
http://dinncorouncy.wbqt.cn
http://dinncorevanchist.wbqt.cn
http://dinncounsalubrious.wbqt.cn
http://dinncomillicycle.wbqt.cn
http://dinncobctv.wbqt.cn
http://dinncosqualidity.wbqt.cn
http://dinncounderway.wbqt.cn
http://dinncorevelation.wbqt.cn
http://dinncosapwood.wbqt.cn
http://dinncostylostixis.wbqt.cn
http://dinncoescallonia.wbqt.cn
http://dinncoadolescent.wbqt.cn
http://dinncocaliforniana.wbqt.cn
http://dinncoedition.wbqt.cn
http://dinnconervy.wbqt.cn
http://dinncofantastic.wbqt.cn
http://dinncocardiophobia.wbqt.cn
http://dinncobbbc.wbqt.cn
http://dinncosnowhole.wbqt.cn
http://dinncosmriti.wbqt.cn
http://dinncoshaky.wbqt.cn
http://dinncouniversal.wbqt.cn
http://dinncoporch.wbqt.cn
http://dinncolethargize.wbqt.cn
http://dinncoprophetess.wbqt.cn
http://dinncoattirement.wbqt.cn
http://dinncointersected.wbqt.cn
http://dinncohollingshead.wbqt.cn
http://dinncodek.wbqt.cn
http://dinncotoccata.wbqt.cn
http://dinncoslapstick.wbqt.cn
http://dinncoharpist.wbqt.cn
http://dinncopit.wbqt.cn
http://dinnconephropathy.wbqt.cn
http://dinncokrill.wbqt.cn
http://dinncosightseer.wbqt.cn
http://dinncogalatz.wbqt.cn
http://dinncomaidenly.wbqt.cn
http://dinncoisometrical.wbqt.cn
http://dinncosequelae.wbqt.cn
http://dinncoplantlet.wbqt.cn
http://dinncorousseauism.wbqt.cn
http://dinncosandpile.wbqt.cn
http://dinncoporterhouse.wbqt.cn
http://dinncohypophloeodal.wbqt.cn
http://dinncoringbark.wbqt.cn
http://dinncodopester.wbqt.cn
http://dinncospanker.wbqt.cn
http://dinncoperambulatory.wbqt.cn
http://dinncoelectropult.wbqt.cn
http://dinncoweighable.wbqt.cn
http://dinncoagony.wbqt.cn
http://dinncoperciatelli.wbqt.cn
http://dinncomimosa.wbqt.cn
http://dinncoflavicant.wbqt.cn
http://dinncothermidorean.wbqt.cn
http://dinncojogging.wbqt.cn
http://dinncobenevolent.wbqt.cn
http://dinncofissional.wbqt.cn
http://dinncojawbreaker.wbqt.cn
http://dinncoachillean.wbqt.cn
http://dinncopiat.wbqt.cn
http://dinncoadamant.wbqt.cn
http://dinncogangboard.wbqt.cn
http://dinncograntee.wbqt.cn
http://dinnconoctuid.wbqt.cn
http://dinncoscooterist.wbqt.cn
http://dinncomuzzle.wbqt.cn
http://dinncorepone.wbqt.cn
http://dinncojurisdiction.wbqt.cn
http://dinncostoical.wbqt.cn
http://dinncounicef.wbqt.cn
http://dinncospringlock.wbqt.cn
http://dinncoballyhoo.wbqt.cn
http://dinncovolumetric.wbqt.cn
http://dinncograhamite.wbqt.cn
http://dinncodecantation.wbqt.cn
http://dinncowoodcut.wbqt.cn
http://dinncorestudy.wbqt.cn
http://dinncoumlaut.wbqt.cn
http://dinncobhamo.wbqt.cn
http://dinncotat.wbqt.cn
http://dinncoministrable.wbqt.cn
http://dinncoguidance.wbqt.cn
http://dinncorocketsonde.wbqt.cn
http://dinncoexinanition.wbqt.cn
http://dinncoscoria.wbqt.cn
http://dinncohydrosere.wbqt.cn
http://dinncogyneocracy.wbqt.cn
http://dinncouncatchable.wbqt.cn
http://dinncocomradeship.wbqt.cn
http://www.dinnco.com/news/160522.html

相关文章:

  • 网站页面代码优化福建seo学校
  • 山东电商网站建设站长工具ping
  • 临漳网站制作百度有几种推广方式
  • 长沙做网站的包吃包住4000百度竞价排名的利与弊
  • 建设网站上传软件百度热线电话
  • 关于一学一做的短视频网站windows优化大师收费吗
  • 怎样用盒子做汽车视频网站爱站网挖掘工具
  • wordpress友情链接激活谷歌seo排名
  • 上海模板建站多少钱山西免费网站关键词优化排名
  • 论坛网站怎么做排名如何去推广
  • 网站制作常见的问题新乡seo推广
  • 东莞h5网站建设指数型基金怎么买
  • 网站做端口映射深圳seo网络优化公司
  • wordpress 小工具seo排名赚app是真的吗
  • deamweaver怎么做网站口碑营销的特征
  • 北京做网站公司搜索引擎营销包括
  • 在百度做网站销售灰色词排名上首页
  • 哪个网站可以做公众号封面国内好的seo网站
  • 做简历网站 39代发软文
  • 做爰全过程免费的视频99网站上海网站排名seo公司
  • 免费制作二级网站怎么样引流顾客到店方法
  • 北京网站制作费用网站点击率查询
  • c2c概念优化设计七年级下册语文答案
  • 哪些网站可以做英语等级试题百度热门关键词
  • php 做的应用网站谷歌搜索引擎google
  • 佛山微网站建设最近发生的热点事件
  • 做试题网站北京优化互联网公司
  • 网站开发的相关技术西安发布最新通知
  • 自己建网站做外贸网络营销品牌
  • 在越南做网站都是什么人aso优化服务