paper-with-me

홈 › Papers

Cost-Optimal Grouped-Query Attention for Long-Context Modeling

2025-03-12 · Yingfa Chen, Yutong Wu, Chenyang Song, Zhen Leng Thai, Xingyu Shen, Xu Han, Zhiyuan Liu, Maosong Sun

Grouped-Query Attention (GQA) is a widely adopted strategy for reducing the computational cost of attention layers in large language models (LLMs). However, current GQA configurations are often suboptimal because they overlook how context length influences inference cost. Since inference cost grows with context length, the most cost-efficient GQA configuration should also vary accordingly. In this work, we analyze the relationship among context length, model size, GQA configuration, and model loss, and introduce two innovations: (1) we decouple the total head size from the hidden size, enabling more flexible control over attention FLOPs; and (2) we jointly optimize the model size and the GQA configuration to arrive at a better allocation of inference resources between attention layers and other components. Our analysis reveals that commonly used GQA configurations are highly suboptimal for long-context scenarios. More importantly, we propose a recipe for deriving cost-optimal GQA configurations. Our results show that for long-context scenarios, one should use fewer attention heads while scaling up model size. Configurations selected by our recipe can reduce both memory usage and FLOPs by more than 50% compared to Llama-3's GQA, with *no degradation in model capabilities*. Our findings offer valuable insights for designing efficient long-context LLMs. The code is available at https://www.github.com/THUNLP/cost-optimal-gqa .

📄 PDF Abstract BibTeX arXiv:2503.09579

Code (1)

thunlp/cost-optimal-gqa 공식 구현

Methods 이 논문이 사용한 방법론

Softmax The Softmax output function transforms a previous layer's output into a vector of probabilities. It is commonly used for multiclass classification. Given an input vector $x$…
Attention 설명 없음

Similar Papers 제목 키워드 기반

Grouped Query Experts: Mixture-of-Experts on GQA Self-Attention

2026-06-18 · Vishesh Tripathi, Abhay Kumar arxiv

Self-attention is central to Transformer performance and is often the most expensive part of the Transformer at long context lengths because its pairwise token interactions scale quadratically with sequence length. Stand…

Weighted Grouped Query Attention in Transformers

2024-07-15 · Sai Sena Chinnakonduru, Astarag Mohapatra

The attention mechanism forms the foundational blocks for transformer language models. Recent approaches show that scaling the model achieves human-level performance. However, with increasing demands for scaling and cons…

Decoder

QCQA: Quality and Capacity-aware grouped Query Attention

2024-06-08 · Vinay Joshi, Prashant Laddha, Shambhavi Sinha, Om Ji Omer 외

Excessive memory requirements of key and value features (KV-cache) present significant challenges in the autoregressive inference of large language models (LLMs), restricting both the speed and length of text generation.…

Text Generation

Grouped Value Attention: Efficient KV Caching via On-Demand Key Reconstruction

2026-09-08 · Vishesh Tripathi, Abhay Kumar, Ramsha Khan arxiv

The KV cache is a primary bottleneck for Transformer decoding: its memory footprint and cache-read traffic grow with sequence length. Grouped-query attention (GQA) reduces this cost by sharing key-value heads, but still …

Mixture of Attention Schemes (MoAS): Learning to Route Between MHA, GQA, and MQA

2025-12-16 · Esmail Gumaan arxiv

The choice of attention mechanism in Transformer models involves a critical trade-off between modeling quality and inference efficiency. Multi-Head Attention (MHA) offers the best quality but suffers from large Key-Value…