The useful part, up front

What you’ll take away

  • Query heads, stored KV heads and attention-head outputs are separate counts; grouped sharing does not remove query results.
  • Two queries can combine the same stored values into (3, 2) and (1, 6); distinct queries can also agree under explicitly different conditions.
  • Repeating histories that were already shared preserves the reference operands. Pooling independent histories does not generally preserve them.
  • The declared 32-layer, batch-two, eight-KV-head cache contains 1 GiB of dense payload; total memory and runtime performance need separate evidence.
01

Eight questions can use two sets of stored information

A model description can list eight attention heads but only two key-value heads. That is not necessarily a missing part or a counting mistake. Grouped-query attention lets several query heads use the same stored keys and values [1]. A query supplies numbers used to decide how strongly to attend to each available position. Keys take part in that comparison, while values supply the numbers combined into the result. Sharing the keys and values does not require sharing the query that reads them.

Imagine eight readers using two notebooks. Readers zero through three use the first notebook, and readers four through seven use the second. The analogy concerns shared numerical information, not people inside a model. Each reader can look for something different. We will replace the analogy with exact invented vectors, including two different results obtained from the same stored values. Then we will separate this sharing arrangement from a very different operation: averaging information that was originally independent. No trained model or hardware experiment is involved.

Eight query heads, three different sharing arrangements. Declared head counts at fixed Hq = 8. Sharing structure alone does not establish equal learned functions or model quality.
Declared head counts at fixed Hq = 8. Sharing structure alone does not establish equal learned functions or model quality. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
Name the history used by each query group. Hypothetical contiguous assignment: (0, 0, 0, 0, 1, 1, 1, 1). Each query keeps its own calculation while reading its assigned history.
Hypothetical contiguous assignment: (0, 0, 0, 0, 1, 1, 1, 1). Each query keeps its own calculation while reading its assigned history. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
02

Read the query, stored-history and output counts separately

For the eight-query example, ordinary multi-head attention could keep eight separate key/value histories. Our grouped arrangement keeps two. A single shared key/value history gives the multi-query endpoint [1]. In all three descriptions, there are still eight query heads producing eight attention-head results. What changes is which histories they may use. Counting eight results does not tell you whether the storage contains eight different histories, two histories shared by groups, or one history shared by everyone.

The Transformers 4.49.0 Llama configuration documents separate num_attention_heads and num_key_value_heads fields, alongside the head dimension [3]. Those names help identify the intended roles when reading that version's configuration. They do not establish the settings of every model called Llama, or prove that an arbitrary file can be converted by changing a number. Start with the actual architecture description. A report that says only '32 heads' leaves a crucial question unanswered: does it mean queries, stored keys and values, or an output axis?

03

The same two values can give results of (3, 2) and (1, 6)

Give one shared history two key vectors, (1, 0) and (0, 1), and two corresponding value vectors, (4, 0) and (0, 8). Each pair of numbers is a vector with two coordinates. Choose query A so that, after scoring and the softmax conversion, its positive weighting strengths are in the ratio three to one. Its normalized weights are therefore three quarters and one quarter. Query B reverses that ratio. Different queries can produce those two weightings while using exactly the same keys; the Technical mode shows an explicit construction using the documented attention formula [2].

For query A, take three quarters of (4, 0) and one quarter of (0, 8). The result is (3, 2). For query B, take one quarter of the first value and three quarters of the second, giving (1, 6). Nothing in the shared value history changed between the two calculations. What changed was the query-dependent mixture. The results are attention vectors, not probabilities of two answers or measurements of intelligence. Their purpose is to make a precise point visible: sharing the ingredients does not force every query head to use the same proportions.

These ingredients also set a boundary. Giving more weight to (4, 0) raises the first coordinate while lowering the second. The two coordinates cannot vary independently in this particular mixture. Every result lies along the straight segment between the two stored value vectors; for finite scores, both weights are positive and the result lies between its endpoints. Shared values therefore permit different results within a defined set. They do not make every imaginable pair of numbers available to a query.

Shared values, different query-dependent mixtures. Original two-position calculation: keys (1, 0), (0, 1); values (4, 0), (0, 8). Both positions allowed; no dropout.
Original two-position calculation: keys (1, 0), (0, 1); values (4, 0), (0, 8). Both positions allowed; no dropout. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
04

Different queries are allowed to agree, too

The example proves that shared histories can produce different results. It does not prove that every pair of query heads must differ. Keep the same keys and values, but use a query that gives the two positions equal scores. Equal scores receive equal weights, so the result is half of (4, 0) plus half of (0, 8), or (2, 4). Several different queries can produce that same balance. Sharing neither demands identical outputs nor guarantees diversity; the actual numerical relationship decides.

There is a second way agreement can occur. Imagine replacing both stored values with the identical vector (5, 7). Three-quarter versus one-quarter weighting now makes no difference: every normalized mixture of those two identical values is still (5, 7). This deliberately simple boundary helps interpret a test. If every value in a test is identical, a wrong weighting may remain invisible in the output. To explore whether queries use a shared history differently, choose values that can distinguish the possibilities instead of treating one matching result as proof that all intermediate relationships match.

05

The order of the groups is part of the computation

With eight queries and two groups, our contiguous assignment is (0, 0, 0, 0, 1, 1, 1, 1). Each number says which history that query head reads. Alternating the two histories would instead give (0, 1, 0, 1, 0, 1, 0, 1). Both assignments have eight entries and use each history four times. Their totals look equally reasonable, but several query heads now read a different history. A matching tensor size cannot reveal which assignment was intended.

To expose the difference, make all queries zero so each history's two positions receive equal weights. Keep group zero's values (4, 0) and (0, 8), whose mean is (2, 4). Give group one the values (10, 2) and (-2, 6), whose mean is (4, 4). Query head one returns (2, 4) under our contiguous map and (4, 4) under the alternating map. The calculation isolates the group assignment: neither the values nor the query changed. PyTorch's illustrative repeat_interleave formulation corresponds to consecutive repetitions [2]; another layout needs its own explicitly correct mapping.

06

Repeating shared values is different from merging independent ones

Suppose we already have the two shared histories. For a reference calculation, we could make four identical copies of each and give one copy to every query in its group. Each query would still receive the same numbers, so the mathematical result would be unchanged. This is a way to explain a sharing operation. It does not mean that every efficient implementation actually makes those copies in memory. The documentation's equivalent formulation describes a relationship, while an implementation's storage choices require separate evidence [2].

Now start from genuinely independent histories. Let head A have (2, 0) at both positions, and head B have (0, 6) at both positions. Use zero scores, so each head averages its own values. Their results are (2, 0) and (0, 6). Averaging the histories together gives (1, 3) at both positions; both results become (1, 3). This tensor-level counterexample shows why merging arbitrary histories is not automatically lossless. The original GQA work describes checkpoint conversion followed by additional training [1]. That is a different task from repeating information that was already shared.

Pooling independent histories can change both results. Original tensor-level counterexample with two positions and equal weights. It is not an experiment converting a trained checkpoint.
Original tensor-level counterexample with two positions and equal weights. It is not an experiment converting a trained checkpoint. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
07

Count stored heads when counting stored bytes

The group map tells us why the cache estimate uses stored key-value heads rather than the number of queries that read them. In a simple dense representation, every retained position has one key vector and one value vector per KV head. If four queries use the same stored history, counting that history four times would describe a physically expanded reference, not the compact representation we set out to count. The declared storage boundary must come before the multiplication.

For one layer, multiply the number of independent sequences by retained positions, then by KV heads. Multiply again by the total number of coordinates in a key plus a value, and by the bytes used for each coordinate. Sum across layers. These are our element-counting steps for the explicit tensor shapes [2]. They assume every counted layer has the stated dimensions and storage precision. We are counting dense K/V payload alone: no claim is made that the resulting number includes model weights, spare allocation, metadata or temporary computation.

08

A complete ledger gives 1 GiB for the declared grouped cache

Use a larger invented configuration for a storage example: 32 layers, two independent sequences, 4,096 retained positions per sequence, 32 query heads and eight KV heads. Each key and each value has 128 coordinates, stored at two bytes per coordinate. The query count helps describe the sharing ratio, but eight is the head count used in the cache multiplication. These numbers are chosen for clear arithmetic; they are not the specification of a real product.

One layer's keys contain 2 × 4,096 × 8 × 128 = 8,388,608 coordinates. At two bytes each, that is 16 MiB. Values take another 16 MiB, so the layer needs 32 MiB of dense K/V payload. Across 32 layers, the total is 1 GiB, or 1,073,741,824 bytes. Here MiB means 1,048,576 bytes and GiB means 1,073,741,824 bytes. Keeping every other assumption fixed but using 32 independent KV heads would give 4 GiB. The fourfold comparison concerns these stored tensors, not the entire model or its execution time.

Account for each side of the compact cache. Hypothetical: 32 layers, batch 2, 4,096 positions, 8 KV heads, 128 coordinates for each K and V, 2 bytes per coordinate. Payload only.
Hypothetical: 32 layers, batch 2, 4,096 positions, 8 KV heads, 128 coordinates for each K and V, 2 bytes per coordinate. Payload only. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
09

A sharing ratio does not settle the workload or runtime

The fourfold saving above holds because we changed one factor: stored heads. If we keep eight KV heads but increase the batch from two independent sequences to eight, the cache returns to 4 GiB. The architecture still shares four query heads per KV group. The workload simply asks it to retain four times as many equally long sequences. A report can therefore truthfully describe head sharing while showing no reduction against a different, smaller batch. Compare the declared factors before judging the result.

Likewise, a 1 GiB K/V payload is not a claim of 1 GiB total memory. Other resident data and temporary work are outside that count. The attention documentation describes implementation selection and numerical differences between kernels [2], so the illustrative repeat operation cannot establish an actual allocation or timing result. A useful performance report needs observations from the chosen model, software, workload and hardware. Our calculation answers which entries are counted. It does not predict how quickly those entries are read or whether the resulting model answers a question well.

10

Use a reference that checks sharing, outputs and the counting boundary

A useful record starts with the separate query and KV head counts, then names the group used by each query. Give the groups distinguishable values so that swapping them can be detected. Next compare a grouped calculation with a reference that repeats only the histories already intended to be shared. Our own bounded arithmetic checks cover 210 such constructed cases and preserve the eight-query example's exact output vectors. They check the stated mathematics; they do not certify a framework, checkpoint or device.

Finally, label the number you are reporting. An output vector answers what a query retrieved from the available values. A payload total answers how many bytes the defined stored tensors contain. A runtime measurement would answer another question and would need an actual execution record. Read the architecture fields in their documented version [3], preserve the grouping relation [2], and keep those conclusions separate. Eight query heads with two KV histories is then a precise, understandable arrangement: several distinct calculations can read shared numerical material without requiring a separate stored copy for every result.

Keep architecture, reference arithmetic and runtime evidence distinct. An ordered interpretation method. The article executes finite arithmetic; an actual model/runtime measurement would require separate evidence.
An ordered interpretation method. The article executes finite arithmetic; an actual model/runtime measurement would require separate evidence. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
Follow the evidence

Sources & further reading

Explore the references behind this guide. External pages may change after our review.

  1. GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints
    Ainslie et al. / Google Research / arXiv · Accessed 7 Nov 2026
  2. torch.nn.functional.scaled_dot_product_attention — PyTorch 2.15 documentation
    PyTorch contributors · Accessed 7 Nov 2026
  3. LLaMA · Hugging Face
    Hugging Face · Accessed 7 Nov 2026

Article updated 7 Nov 2026.

Found something we should revisit?

Good explanations get better with thoughtful feedback.

Suggest a correction