GQA: what part of the share key header saves the cache
Grouping query attention allows multiple query heads to share fewer key headers.
Learning objectives and first steps2 objectives . 1 first fix
Try to do it after reading
- Explain GQA: Mechanisms and premises for sharing key headers to save part of the cache
- Positioning the mechanism ' s fault limits with fixed examples
Suggested first
- Multiple Attention with KV Cache
Issues and mechanisms
Grouping query attention allows multiple query heads to share fewer key headers. Queries can still be different, but the same group reads the same keys and values, reducing cache storage and bandwidth. It is a specific architecture choice between the multi-purpose attention that each query head has exclusive key values and the multi-check attention that all queries share a set of key values, and not the equivalent of a simple deletion of any existing cache.
Sets the query header Hq, the key-value header Hkv, and the common rules require that the number of query headers per group can be eliminated. The cache size is calculated using the actual stored Hkv, while the attention output is still generated by the Hq group query. Sharing reduces freedom of expression of key values, and training or switching formulas require compensating for this constraint; The quality and speed of the original paper correspond to its specific experiments and cannot be considered as a loss cap for all models.
A concrete example
The synthetic model has eight query headers. The multi-purpose option uses eight key headers, and the group programme shares one key head for each of the four queries. When layer numbers, length, head peacekeeping cache accuracy are the same, the key cache is changed from eight to two, that is, by three quarters. Query projection and final output did not shrink to a quarter; The total visibility also includes parameters versus workspaces, and the cache ratio cannot be described as the overall service savings ratio.
Borders and checks
Checks the group map, cache shape and position index of the query header to the key value header when it is wrong. For some to be calculated by broadcasting or repeating view, logical sharing does not mean that actual kernels will save bandwidth. Different parallel splitting can also change communications. Resource changes can be attributed to head-to-head sharing only if fixed input, weight and baseline for allocation are compared.
A method of verification
For the realization of the shared head, it is advisable to construct a short input that is clearly different from the content of each key header and to check which group it reads on each query. If the group map is wrong, the overall shape and cache size may be correct, but semantics have changed. Parallel reasoning also requires checking whether each device repeats the same key group of values and whether logic sharing really translates into physical reuse. The theoretically reduced number of caches is only the diagnostic starting point, and peak memory and bandwidth must be measured by actual realization.
Check understanding
Eight query heads, two key headers, and the cache should be counted as eight or two?
Calculated by using two really stored key headers; However, the cost of the search side to the output is still related to eight query headers and cannot be replaced with all dimensions in two.
Do multiple check points have a full equal price on a group head?
Prices generally vary. Key values indicate that they are merged and the function changes; There is a need for a clear approach to the transition and follow-up of training and for a reassessment of quality and resources.
Sources and reconciliations
Definitions, methods and interfaces are available.
- GQA — Training Generalized Multi-Query Transformer Models
- Hugging Face Transformers — How caching works
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.