如何计算最佳批量 [英] How to calculate optimal batch size
问题描述
有时我遇到问题:
分配具有形状的张量时的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屋!