如何计算最佳批量大小 [英] How to calculate optimal batch size

查看:31
本文介绍了如何计算最佳批量大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我会遇到问题:

分配形状张量时的OOM

OOM when allocating tensor with shape

e.q.

分配形状为 (1024, 100, 160) 的张量时出现 OOM

OOM when allocating tensor with shape (1024, 100, 160)

其中 1024 是我的批量大小,我不知道其余的是什么.如果我减少模型中的批量大小或神经元数量,它运行良好.

Where 1024 is my batch size and I don't know what's the rest. If I reduce the batch size or the number of neurons in the model, it runs fine.

是否有一种通用的方法可以根据模型和 GPU 内存计算最佳批量大小,从而使程序不会崩溃?

Is there a generic way to calculate optimal batch size based on model and GPU memory, so the program doesn't crash?

简而言之:就我的模型而言,我想要最大的批量大小,这将适合我的 GPU 内存并且不会使程序崩溃.

In short: I want the largest batch size possible in terms of my model, which will fit into my GPU memory and won't crash the program.

推荐答案

您可以使用以下方法估算最大批量大小:

You can estimate the largest batch size using:

最大批量大小 = 可用 GPU 内存字节数/4/(张量大小 + 可训练参数)

这篇关于如何计算最佳批量大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆