Gqla Attention
Group-Query Latent Attention (GQLA).
Implements Group-Query Latent Attention, arXiv:2605.15250 (Meng, 2026). GQLA is a minimal modification of Multi-Head Latent Attention (MLA, DeepSeek-V2/V3) whose trained weights expose two algebraically equivalent decoding paths over the same parameters:
MQA-absorb path (default): identical to MLA. The key cache stores the low-rank latent
c_KV; at decode time the up-projection is absorbed into the query, giving a single MQA-style head per layer. Pins the H100 roofline ats_q = 1.GQA path: expands the latent into
num_groupsfull key/value heads and runs standard grouped-query attention with a per-group expanded cache. Selected whens_q > 1(e.g.s_q = 2on commodity GPUs such as the H20), enabling Multi-Token Prediction gains and up to 8-way zero-redundancy tensor parallelism along the head axis.
Both paths are algebraically equivalent for the forward output, so the
runtime can switch between them with no retraining and no custom
kernels. Here we expose a single decode_path configuration knob
("mqa_absorb" or "gqa") and the gqla_num_groups parameter
that controls how many GQA groups the expanded path uses.
- Reference:
Meng, F. (2026). “GQLA: Group-Query Latent Attention for Hardware-Adaptive Large Language Model Decoding”. arXiv:2605.15250.
- class src.model.attention.latent.gqla_attn.GQLAAttention(*args: Any, **kwargs: Any)[source]
Bases:
ModuleGroup-Query Latent Attention (Meng 2026) with two decoding paths.
Stores a low-rank latent
c_KVof rankgqla_latent_rankfrom which keys and values are reconstructed by up-projections. At forward time the latent is always expanded (the difference between the two decoding paths is purely a kernel/weight-absorption choice at deployment; the module’s algebraic output is identical). Thedecode_pathattribute is recorded for introspection and tested for shape correctness.- Parameters:
config – Configuration object. Relevant attributes: hidden_size, num_heads, dropout, use_bitnet, mode, and the optional
gqla_latent_rank(defaulthidden_size // 2),gqla_num_groups(defaultnum_heads // 4, must dividenum_heads), andgqla_decode_path("mqa_absorb"or"gqa"; default"gqa").
Input dimensionality.
- num_heads
Number of query heads.
- head_dim
Per-head dimensionality.
- latent_rank
Latent compression rank.
- num_groups
Number of GQA groups for the expanded path.
- group_size
num_heads // num_groups.
- decode_path
Selected decoding path (recorded for introspection).
- dkv_proj
Latent down-projection.
- uk_proj, uv_proj
Key/value up-projections.
- q_proj
Query projection.
- out_proj
Output projection.
- dropout
Dropout layer.
- mode
"encoder"or"decoder".
- Raises:
ValueError – If
hidden_sizenot divisible bynum_heads; ifgqla_num_groupsdoes not dividenum_heads.
- forward(x: torch.Tensor, logical_layer_idx: int | None = None) torch.Tensor[source]
Compute GQLA attention.
- Parameters:
x – Input tensor of shape
(batch_size, seq_len, hidden_size).logical_layer_idx – Unused; accepted for interface compatibility.
- Returns:
Output tensor of shape
(batch_size, seq_len, hidden_size).