torch.cuda.OutOfMemoryError: CUDA out of memory.解决方案(亲测有效)

本文讲述了作者在深度学习项目中遇到CUDA内存溢出的问题,通过调整batch_size和理解内存管理设置,成功解决了torch.cuda.OutOfMemoryError,提示其他开发者如何处理类似情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

torch.cuda.OutOfMemoryError: CUDA out of memory.解决方案

背景

这几天在调深度学习代码的时候,调到最后发现报torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 240.00 MiB (GPU 0; 23.69 GiB total capacity; 22.68 GiB already allocated; 174.44 MiB free; 22.78 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错,而使用nvidia-smi命令查看显卡状况时发现显卡还有内存。
在这里插入图片描述

解决方式调小batch_size

将batch_size调小即可,batch_size一般在configs文件夹里面,我将batch_size从80调到了32,这个时候模型就跑起来了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值