AI-generated example, checked by executing the arithmetic below. It uses a fictional model configuration. TIHMLO publishes the linked planning worksheet.
A file containing nominally 4-bit weights for an 8-billion-parameter model suggests a first-pass weights estimate near 4 GB. A running model also needs memory for its context. To estimate one part of that difference, model the key and value cache separately from the weights.
Count the cache for one stream
In a simplified dense cache, each token stores one key and one value for each KV head in each layer. A configuration with 32 layers, 8 KV heads, 128 values per head and a 16-bit cache therefore uses:
32 layers × 8 KV heads × 128 values × 2 (key and value) × 2 bytes/value = 131,072 bytes per cached token
Enter fullscreen mode
Exit fullscreen mode
A grouped-query model can have fewer KV heads than query heads. Use the KV count from the model configuration.…