[KongchangAI]
· 2 min read· 1,204 words

7B Model Benchmarks: How KV Head Sharing, Sliding Windows, and Vocabulary Determine VRAM and Retrieval

7B Model Benchmarks: How KV Head Sharing, Sliding Windows, and Vocabulary Determine VRAM and Retrieval

Three 7B models differ by an order of magnitude in long-context capability due to KV head count, sliding window, and vocabulary design.

Based on a systematic benchmark on a single 16GB T4 GPU, the article compares LLaMA 7B, Mistral 7B v0.1, and Qwen2.5-7B on long-context retrieval and VRAM usage, showing that the deciding factors are not parameter count but three underlying designs: KV head count (32/8/4), whether a sliding window is used (4,096 tokens for Mistral), and vocabulary size (32,000 vs. 151,643). Passkey retrieval shows Mistral hits within 4,089 tokens and misses entirely beyond 4,098; with the window disabled, 8K works but 16K/32K fail. Per-token KV cache is 512/128/56 KiB, letting Qwen2.5 fit 64K tokens in 3.5 GiB. Combined with tokenization efficiency, LLaMA needs 9.5–22× the cache of Qwen2.5 for the same sentence, and decoding latency growth mainly comes from moving the cache.

Three Design Choices That Determine How Long a Context Your Small GPU Can Handle

LLaMA 7B, Mistral 7B v0.1, and Qwen2.5-7B are three commonly used models in the same size class, yet they differ enormously in their impact on VRAM and long-context retrieval. The difference isn't in parameter count but in three underlying design decisions: how many KV heads the attention layers retain (32, 8, and 4 respectively), whether attention is restricted to a sliding window (Mistral's window is 4,096 tokens), and vocabulary size (32,000 vs. 151,643 tokens). A systematic benchmark run on a single 16 GB T4 GPU quantifies the consequences of these three choices one by one.

Source article illustration

The conclusion is fairly direct: if you want long-context retrieval, the window is a hard boundary; if you want to save VRAM, KV head sharing and a more efficient vocabulary stack up to a gap of an order of magnitude.

Sliding Window: Retrieval Cuts Off Hard at the Window Edge

Benchmark: All Hits Within 4,089 Tokens, All Misses Beyond 4,098 Tokens

The clearest evidence comes from the passkey retrieval experiment. The researchers ran 134 trials, placing the "key" at positions 3,600 to 4,600 tokens from the end of the prompt. Mistral retrieved successfully in all 72 trials where the key fell within 4,089 tokens, and failed in all 62 trials where the distance was 4,098 tokens or more. The boundary is extremely sharp—this isn't accuracy degradation; the window itself is truncating.

Without the Window: No Difference Within 8K, Total Failure at 16K/32K

The researchers ran a control using the same weights with the sliding window disabled. The result: with 8K-token prompts, all test positions were retrieved successfully, showing that the limitation comes from the attention mask rather than model capability. But at 16K and 32K, the windowless model failed completely, while the windowed model could still retrieve nearby keys. This counterintuitive result shows that Mistral's window mechanism is reliable within the training distribution; once the context is forced far beyond the training range, the windowless version collapses because attention gets diluted.

Qwen2.5 takes a different path: across a range of up to 32K tokens, all 60 trials retrieved successfully, with no window boundary issues.

Sliding Window Attention is a sparse attention mechanism introduced by Mistral 7B. In standard causal attention, each token can see all the tokens before it; in sliding window attention, each token can only see tokens within a fixed window size (4,096 here) before it, and earlier tokens are masked out by the attention mask. The design rationale: in language modeling, nearby context is usually more important than distant context, and limiting the receptive field reduces attention compute and VRAM costs from O(n²) to O(n·w), where w is the window size. The cost is that information cannot propagate across the window boundary—although stacking multiple layers can indirectly extend the effective receptive field through layer-by-layer passing, single-pass retrieval relies on direct attention connections, so the window constitutes a hard boundary.

KV Cache VRAM: 512, 128, and 56 KiB per Token

The per-token KV cache overhead for the three models is 512 KiB (LLaMA), 128 KiB (Mistral), and 56 KiB (Qwen2.5), respectively. This gap directly determines how long a context can fit on a 16 GB T4:

  • LLaMA runs out of VRAM at 32K tokens;
  • Mistral's cache tops out at 512 MiB;
  • Qwen2.5 can fit 64K tokens within 3.5 GiB.

The drop in KV heads from 32 to 4 is the main cause of this gap, and Qwen2.5 adds a vocabulary advantage on top of that.

KV Cache is the intermediate state saved during autoregressive decoding to avoid redundant computation: each time a new token is generated, the model needs the Key and Value vectors of all previous tokens, so these vectors are cached. Its per-token VRAM footprint is roughly 2 × layers × KV heads × head dimension × bytes per data type, where the factor of 2 accounts for Key and Value. KV head sharing (Grouped-Query Attention, GQA) lets multiple Query heads share the same set of Key/Value heads, thereby compressing the cache proportionally: LLaMA 7B retains 32 KV heads (i.e., standard multi-head attention), Mistral reduces this to 8, and Qwen2.5 reduces it to 4. This is the main reason the three models have per-token caches of 512, 128, and 56 KiB, and it also explains why the context length supportable under a fixed VRAM budget differs by several times.

Vocabulary Efficiency: A 38–58% Token Reduction Is No Small Matter

A larger vocabulary isn't just a wider embedding layer. The researchers measured tokenization efficiency on 1,997 parallel sentences across 15 languages: Qwen2.5's tokenizer reduced token counts by 38–58% in five languages and by 3–11% in the other ten. Fewer tokens means shorter sequences, a smaller cache footprint, and less computation.

Combining vocabulary efficiency with KV head sharing, the researchers conclude that for the same sentence, LLaMA requires 9.5 to 22.0 times the cache VRAM of Qwen2.5. The lower and upper bounds of this range correspond to different languages—the larger the tokenization efficiency gap, the higher the multiplier.

The relationship between vocabulary size and tokenization efficiency is easy to overlook. The larger the vocabulary, the longer the character sequence a single token can typically cover, and the fewer tokens a given piece of text is split into. Qwen2.5 uses a vocabulary of 151,643, while LLaMA and Mistral use 32,000, so the former can express the same content in fewer tokens on multilingual text. Since KV cache, attention computation, and decoding steps are all proportional to token count, tokenization compression rates translate directly into VRAM and latency gains. Note that a large vocabulary also brings larger embedding and output-layer parameters; this is a fixed model-weight cost, unlike the KV cache that grows with context—in long-context scenarios, the dynamic gains from token reduction far outweigh this fixed cost.

Decoding Latency: Cache Size Is Almost the Latency Itself

In a general-purpose runtime, decoding latency grows with cache size. More notably, the researchers separately measured the cost of copying the cache and found that this item alone accounts for roughly the portion of latency growth. In other words, slow long-context decoding is largely slow because of moving the cache around, not the attention computation itself. This points to a direction for inference optimization: reducing the per-token cache footprint may yield more direct gains than optimizing kernels.

How to Choose: Three Actionable Conclusions

If you need reliable long-context retrieval, Mistral's sliding window is a hard constraint—a key beyond the window will definitely not be found; if you must have ultra-long context, Qwen2.5 performs stably within 32K, with no obvious positional failures in the benchmark.

If VRAM is tight and context needs are limited, Mistral's 128 KiB/token and 512 MiB cache ceiling are very friendly on small GPUs, as long as the task falls within the window.

For multilingual scenarios, differences in vocabulary efficiency amplify into a 9.5–22× cache gap; when selecting a model, it's worth treating tokenization compression rate as a first-class evaluation metric rather than looking only at parameter count and benchmark scores.

The code and results are publicly available, and all the above numbers can be reproduced on a single GPU.

#LLaMA 7B#Mistral 7B#Qwen2.5-7B#KV cache#sliding window attention#GQA#long-context retrieval#vocabulary size
Share:

Related articles