Files
myWiki/concepts/grouped-query-attention.md

35 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Grouped-Query Attention (GQA)
created: 2025-04-15
updated: 2026-05-01
type: concept
tags: []
sources: []
---
# Grouped-Query Attention (GQA)
**分组查询注意力**,在 MHA 和 MQA 之间的折中方案,由 Ainslie 等 2023 年提出。
## 定义
GQA 将 Q 头分为 G 组,每组共享一个 KV 头。标准 MHA 是 G = h每组1个Q头MQA 是 G = 1所有Q头共享一个KV头
## 核心洞见
并非所有注意力都需要独立的 KV 头——GQA 证明分组共享 KV 可以在几乎不损失质量的前提下大幅减少 KV 缓存。这也是 Llama 3 系列采用的设计。
## 关键参数
- **组数 G**: G = h → MHAG = 1 → MQA1 < G < h GQA
- **缓存减少**: KV 缓存缩减为 MHA G/h典型的 8 分组可将缓存减少 87.5%
- **质量**: G = 4~8 时质量与 MHA 接近
## 相关概念
- [[multi-head-attention]] 标准 MHA (G = h)
- [[multi-query-attention]] 极端 MQA (G = 1)
- [[multi-head-latent-attention]] 更激进的 MLA 压缩
- [[kv-cache-bottleneck]] 缓存瓶颈驱动 GQA 设计
- [[llm-attention-survey-2026]] 综述参考