7/30
Part 2 of 7 · The memory budgetLearn
The weights take a fixed share, and each conversation's cache takes the rest
The numbers come from the model card: 7.61 billion parameters, 28 layers, and 28 query heads sharing 4 key and value heads. The config file gives a hidden size of 3,584, so each head is 3,584 / 28 = 128 numbers wide. NVIDIA lists 80 GB of memory for the H100 SXM.
# Qwen2.5-7B-Instruct
params = 7.61e9
# bf16, a 16-bit number format: 2 bytes a value
bytes_per_value = 2
layers, kv_heads, head_dim = 28, 4, 3584 // 28
weights_gb = params * bytes_per_value / 1e9
# a key and a value, every layer
kv_per_token = 2 * layers * kv_heads * head_dim * bytes_per_value
# one 2,000-token conversation
kv_per_seq_gb = kv_per_token * 2000 / 1e9
# keep 10 GB for activations
room_gb = 80 - weights_gb - 10
print(f"weights {weights_gb:.1f} GB, cache {kv_per_token:,} bytes a token, {kv_per_seq_gb:.3f} GB a sequence")
print(f"{room_gb:.1f} GB of room holds {int(room_gb // kv_per_seq_gb)} sequences")
After the 15.2 GB of weights and a 10 GB reserve, how many 2,000-token conversations fit in the H100's 80 GB?
Pick one to see what it prints.
Pick an answer above to see the rest