错误:

RuntimeError: CUDA out of memory. Tried to allocate 170.00 MiB (GPU 0; 3.82 GiB total capacity; 1.94 GiB already allocated; 169.19 MiB free; 1.96 GiB reserved in total by PyTorch)

我们可以看见内存是还有很多的,但是在运行程序的时候还是会出现CUDA out of memory

解决方法

一、正确调用指定GPU

我们在调用GPU时,并没有使用到指定“内存”,使用的是显存,这样就会导致我们在跑程序的时出现内存溢出
将下面的代码添加到代码中

os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
os.environ['CUDA_VISIBLE_DEVICES'] = '1'
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")#判断CUDA是否能使用,不可以就使用CPU

二、杀死进程

这里我们杀死进程要注意的是,杀死进程是否可以pass掉,不然会导致你有的程序终止掉,切记切记

kill id号

eg:

三、减小batchSize

每次读取的数据减小,或者说减小每次训练的数据大小

四、关机重启

要是前面三个方法还是没有解决问题,关机重新启动试一试。
还是不行我也表示~~~~~~sorry

希望这篇文章对你有用!
谢谢点赞评论!

RuntimeError: CUDA out of memory. Tried to allocate 170.00 MiB (GPU 0; 3.82 GiB total capacity; 1.94相关推荐

  1. 报错`RuntimeError: CUDA out of memory. Tried to allocate 256.00 MiB (GPU 0; 9.78 GiB total capaci

    报错RuntimeError: CUDA out of memory. Tried to allocate 256.00 MiB (GPU 0; 9.78 GiB total capacity; 8. ...

  2. RuntimeError: CUDA out of memory.Tried to allocate 20.00 MiB GPU 0 ,3.94 GiB total capacity 3.36 G

    RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.94 GiB total capacity; 3.36 ...

  3. RuntimeError: CUDA out of memory. Tried to allocate 50.00 MiB (GPU 0; 4.00 GiB total capacity; 682.9

    1. 问题 训练模型时报错: RuntimeError: CUDA error: out of memory CUDA kernel errors might be asynchronously re ...

  4. 解决:RuntimeError: CUDA out of memory. Tried to allocate 64.00 MiB (GPU 0; 4.00 GiB total capacity; 2

    引发pytorch:CUDA out of memory错误的原因有两个: 1.当前要使用的GPU正在被占用,导致显存不足以运行你要运行的模型训练命令不能正常运行 解决方法: 1.换另外的GPU 2. ...

  5. [881]内存不足RuntimeError: CUDA out of memory. Tried to allocate 16.00 MiB (GPU 0; 2.00 GiB total cap...

    今天第一次在服务器上跑代码 也是第一次接触cuda显存卡 碰到了标题问题 将解决办法记录下来 1. 首先去查看cuda显存占用情况: nvidia-smi 显示所有GPU的当前信息状态(图源网络 不想 ...

  6. RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 4.00 GiB total capacity; 2.44

    调试手写数字识别代码时出现的问题,将cpu的代码改用gpu训练时虽然可以训练,详见上一条博客(Mnist手写数字识别cpu训练与gpu训练),但是会出现Error.查找资料后以下是解决过程. 先说结论 ...

  7. RuntimeError: CUDA out of memory. Tried to allocate 132.00 MiB (GPU 2; 3.95 GiB total capacity; 3.41

    pytorch报错:RuntimeError: CUDA out of memory. Tried to allocate 132.00 MiB (GPU 2; 3.95 GiB total capa ...

  8. CUDA out of memory. Tried to allocate 392.00 MiB (GPU 0; 10.76 GiB total capacity; 652.77 MiB alread

    在使用Pytorch中,出现CUDA out of memory. Tried to allocate 392.00 MiB (GPU 0; 10.76 GiB total capacity; 652 ...

  9. CUDA out of memory. Tried to allocate 16.00 MiB (GPU 0; 6.00 GiB total capacity;总结(1)

    CUDA out of memory. Tried to allocate 16.00 MiB (GPU 0; 6.00 GiB total capacity; 4.54 GiB already al ...

最新文章

  1. 6.微信小程序的如何使用全局属性
  2. Asp.net单点登录解决方案
  3. Python3 中hasattr()、getattr()、setattr()、delattr()函数及示例代码数
  4. 最简单的c#Remoting编程
  5. 实训七(项目准备与创建)
  6. JSONP 初步学习--但是还是有疑问
  7. 一些开发点滴[java]
  8. python门牌制作
  9. python缓存memoryerror_Python安装会抛出大量MemoryError()的
  10. 含泪整理最优质平板Rhino犀牛模型素材,你想要的这里都有
  11. RabbitMQ安装问题
  12. 修改hexo的主题nexT中的Pisces主题宽度
  13. ChucK初步(8)
  14. C语言解析FLM(ELF)格式文件
  15. 上海浦东机场的wifi使用攻略
  16. linux在磁盘容量扩容后扩容文件系统
  17. WebRTC系列-Qos系列之接收NACK
  18. Conflux v2.2.0 网络 Hardfork 升级公告
  19. word转换成excel导致身份证错乱的解决办法
  20. 全球市场动荡持续,澳元和液化天然气(LNG)价格跌至近11年最低水平

热门文章

  1. 2021年中国基于Web的医疗计费软件市场趋势报告、技术动态创新及2027年市场预测
  2. 360密盘两月即被破解 10万年成笑话
  3. 物联网领域 百度云与阿里云对比
  4. php在线支付之支付宝
  5. 支付宝在线支付接口开发教程与总结
  6. 微信小程序的开发之城市json数据
  7. 从0开始学web-day2
  8. 自动化专业课和计算机技术联系,机械制造及其自动化专业介绍
  9. 物联网操作系统Zephyr(入门篇)之1.1 Zephyr源码架构
  10. Python 实战分析某招聘网站数据分析岗位的招聘情况