大语言模型(LLM)显存占用计算

公式:

\[ M = \dfrac{(P \times B)}{ (32 / Q)} \times 1.2 \]

符号 描述
M 所需 GPU 显存(单位:GB)
GPU memory expressed in Gigabyte.
P 模型参数数量(单位:B,例如 7B 表示 70 亿参数)
The amount of parameters in the model. E.g. a 7B model has 7 billion parameters.
B 每个参数占用的字节数,通常为 4 字节
4 bytes, expressing the bytes used for each parameter.
32 每 4 字节包含 32 位
There are 32 bits in 4 bytes.
Q 加载位宽(例如 16-bit、8-bit、4-bit)
The amount of bits that should be used for loading the model. E.g. 16 bits, 8 bits or 4 bits.
1.2 表示加载模型时额外的 20% 显存开销
Represents a 20% overhead of loading additional things in GPU memory.
back to WMW