admin管理员组文章数量:1611911
问题现场
环境:pytorch=1.+,python=3.6,1个GPU
当对预训练的bert模型进行fine-tuning,模型训练的batchsize设置为256时,报错。大概意思是GPU内存超了,总共22g(模型结构、参数等会占用5g内存)内存,16g的内存以及被分配出去了,剩下的78M,不够分配给120M了。
RuntimeError: CUDA out of memory. Tried to allocate 120.00 MiB (GPU 0; 22.38 GiB total capacity;
16.74 GiB already allocated; 78.06 MiB free; 16.85 GiB reserved in total by PyTorch)
解决方案
1.调小一些batchsize。
举个例子,来计算下batchsize跟占用内存之间的关系:
2.“变相”增加batchsize的大小。
补充:
模型训练时的信息,每张卡,受限于内存,能接受的最大batchsize数是128,这里可以看下内存占用情况。
参考:
1.调小batchsiize:https://github/pytorch/pytorch/issues/16417
2.训练trick:https://github/huggingface/transformers/issues/906
本文标签: allocateMemoryPytorchRuntimeErrorCUDAMIB
版权声明:本文标题:PytorchRuntimeError:CUDA out of memory.Tried to allocate 120.00 MiB (GPU 0; 22.38 GiB total capacity 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728621154a1166373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论