KV heads, sliding windows and vocabulary size affect memory and retrieval in 7B models
The paper compares three 7B-class language models on one 16 GB T4 GPU: the original LLaMA 7B, Mistral 7B v0.1 and Qwen2.5-7B. It looks at three design choices: how many KV heads[1] the attention layers keep (32, 8 and 4), whether attention is limited to a sliding window[2] of 4,096 tokens in Mistral, and how large the vocabulary is (32,000 versus 151,643 tokens).
In a passkey retrieval[3] test with 134 trials, Mistral found the key in all 72 trials where it lay within 4,089 tokens of the end of the prompt, and in none of the 62 trials where it lay 4,098 or more tokens away. With the window turned off, the same weights found the key at every tested position in 8K-token prompts, so the authors conclude the mask causes the limit. Qwen2.5 retrieved the key in all 60 trials up to 32K tokens.
KV cache[4] memory per token is 512, 128 and 56 KiB for the three models. LLaMA runs out of memory at 32K tokens, Qwen2.5 holds 64K tokens in 3.5 GiB, and Mistral's cache stops at 512 MiB. On 1,997 parallel sentences in 15 languages, Qwen2.5's tokenizer removes 38-58% of tokens for five languages and 3-11% for the other ten, and with KV sharing LLaMA needs 9.5-22.0 times more cache memory than Qwen2.5 for the same sentence. Decode latency in a common runtime grows with cache size, and copying the cache alone costs about as much as that growth.
Read the original arxiv.orgDiscussion
Sources
-
arXiv
Shared KV Heads, Sliding Windows, and Vocabulary Size: Measured Memory and Retrieval Trade-offs in LLaMA 7B, Mistral 7B, and Qwen2.5-7B


