﻿# SGLang GQA repair: query-head tiles must preserve the KV-group boundary

Why SGLang query heads could read the wrong KV group when a 24-head group crossed a 16-head tile, and how to qualify the merged indexing repair.

Author: Retrivium editorial team
Updated: 2026-11-18
Canonical URL: https://retrivium.ai/journal/daily-20261116-sglang-gqa-kv-head-group-mapping/
Language: en

Published on 18 November 2026. SGLang PR 47802 merged on 15 November at 07:06:05 UTC, inside the research window from 14 November, 14:00:21 UTC, to 16 November, 02:00:21 UTC. The proposal was opened on 1 November. The new event is a merged implementation, not a newly announced model or evidence that every stable package already contains the fix.

## A query-head group is an indexing contract

Grouped-query attention associates several query heads with one key/value head. For the shape discussed in the [upstream change](https://github.com/sgl-project/sglang/pull/47802), 48 query heads and 2 KV heads give groups of 24. With zero-based indexing, query heads 0 through 23 belong to KV head 0, and heads 24 through 47 belong to KV head 1. That association must survive the implementation's division of work into tiles. A tile is an execution convenience; it must not silently redefine which KV data a query head reads.

## A contiguous tile can cross the group boundary

The affected grouped decode path uses a tile width of 16 heads. A contiguous tile containing heads 16 through 31 crosses the boundary at head 24. Assigning that entire tile to the first KV group therefore makes heads 24 through 31 read the wrong KV head. This explains why testing only shapes whose groups align with the tile can miss the problem. The mathematical grouping remains valid; the incorrect association is introduced by the kernel's work layout rather than by the model configuration itself.

## Whole tiles and masking repair different parts

The [pinned kernel implementation](https://github.com/sgl-project/sglang/blob/40723a52ded9229e221a437254f34bc8a3327251/python/sglang/kernels/ops/attention/decode_attention.py) assigns a whole number of tiles to each KV group and masks the incomplete final tile. In the 24-head example, each group needs two 16-head tiles. Across two groups that means four tiles, with inactive positions in each group's final tile. The mapping must start from the current group's own first head. Allocating another tile without changing the indexing would not by itself establish correctness; masking without sufficient work coverage could instead omit valid heads.

## Use inputs that expose the wrong association

A proposed acceptance case can give the KV groups deliberately distinguishable synthetic data, then compare decode output against an independent reference for the same mathematical operation. Inspect the heads around the group boundary, rather than only an aggregate tensor statistic. Specify dtype and numerical tolerance before interpreting differences. Identical KV groups would be a weak fixture because a wrong association could accidentally produce the expected answer. This procedure has not been run by Retrivium and establishes no new benchmark result.

## Shape coverage and rollout remain separate

The [pinned regression test](https://github.com/sgl-project/sglang/blob/40723a52ded9229e221a437254f34bc8a3327251/test/registered/attention/test_triton_attention_kernels.py) includes group sizes 24, 20, 8, 16 and 32. These exercise nonaligned and aligned cases, but do not certify every model, sharding arrangement or kernel backend. An operator still needs the installed revision, actual head counts after configuration, selected backend and a bounded correctness result. A merged source change is useful evidence for that qualification. It should not be converted into a blanket accuracy guarantee or a claim that an uninspected production image has already been repaired.

Related reading: [SGLang quantized GEMM backends](/journal/sglang-quantized-gemm-backends/); [Define an inference benchmark](/journal/inference-benchmark-method/).
