Difficulty: Hard Tags: Transformers, Grouped-Query Attention, KV Cache
A serving team switches from multi-head attention to grouped-query attention (GQA) to reduce KV-cache memory. A capacity calculator incorrectly uses the number of query heads for key/value storage. Compute the KV-cache memory under the stated configuration.
For batch B, layers L, cached tokens T, query heads Hq, key/value
heads Hkv, head dimension D, and bytes per scalar b:
M = 2 * B * L * T * Hkv * D * b
The configuration is valid only if Hq % Hkv == 0.
b, l, t, hq, hkv, d, bytes_per_scalar (all positive integers).
None if Hq is not divisible by Hkv; otherwise the cache size in
bytes (int).
10^5, b in {1,2,4,8}.Input
B=1, L=32, T=4096, Hq=32, Hkv=8, D=128, bytes_per_scalar=2
Output
536870912
Explanation: The cache stores keys and values for 8 KV heads, not 32
query heads: 2*1*32*4096*8*128*2 = 536870912 bytes.
No results yet
Run your code to check it against the examples, or submit to run every test.