[Bugfix] Keep the GLM-5.3 kpool tail and Qwen4 QSA ring out of the null block (#59528)

Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yifan Qiao
2026-10-08 20:44:04 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 2ddde19e8e
commit 240785b82c
5 changed files with 45 additions and 24 deletions
+5 -2
View File
@@ -127,7 +127,9 @@ def circular_qsa_slot_mapping(
valid = (requests >= 0) & (requests < block_table.shape[0]) & (positions >= 0)
safe_requests = requests.clamp(0, block_table.shape[0] - 1)
physical_blocks = block_table[safe_requests, 0].long()
valid &= physical_blocks >= 0
# Dummy and padding requests own no ring and sit on the null block,
# which must never be written.
valid &= physical_blocks > 0
slots = physical_blocks * compressor_state_size + positions.remainder(
compressor_state_size
)
@@ -288,7 +290,8 @@ def _build_qsa_metadata_kernel(
mask=valid,
other=-1,
)
valid &= physical_block >= 0
# Dummy and padding requests own no ring and sit on the null block.
valid &= physical_block > 0
slot = physical_block * circular_buffer_size + (
logical_position % circular_buffer_size
)
+7 -2
View File
@@ -702,11 +702,15 @@ def _kpool_tail_slot_mapping_kernel(
end = tl.load(query_start_loc_ptr + pid + 1)
end = tl.where(pid == num_reqs - 1, num_actual_tokens, end)
own_block = tl.load(block_table_ptr + pid * block_table_stride).to(tl.int64)
# Every scheduled request owns a tail block; the runners give dummy and
# padding requests the null block, which must never be written.
has_block = own_block != 0
for i in range(start, end, BLOCK):
offs = i + tl.arange(0, BLOCK)
mask = offs < end
pos = tl.load(positions_ptr + offs, mask=mask, other=0).to(tl.int64)
tl.store(out_ptr + offs, own_block * kpool + pos % kpool, mask=mask)
slot = tl.where(has_block, own_block * kpool + pos % kpool, -1)
tl.store(out_ptr + offs, slot, mask=mask)
else:
offs = num_actual_tokens + (pid - num_reqs) * BLOCK + tl.arange(0, BLOCK)
mask = offs < num_tokens
@@ -759,7 +763,8 @@ def compute_kpool_tail_slot_mapping(
req = req.clamp_(min=0, max=num_reqs - 1)
own_block = block_table[:num_reqs, 0].index_select(0, req).to(torch.int64)
pos = positions[:num_actual_tokens].to(torch.int64)
out[:num_actual_tokens] = own_block * kpool + torch.remainder(pos, kpool)
slots = own_block * kpool + torch.remainder(pos, kpool)
out[:num_actual_tokens] = torch.where(own_block != 0, slots, -1)
return out