[Perf][Attention] Avoid redundant sparse attention metadata operations (#57885)

Signed-off-by: Woosuk Kwon <woosuk@inferact.ai>
Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
Woosuk Kwon
2026-09-21 00:08:43 -07:00
committed by GitHub
co-authored by OpenAI Codex
parent 3c84ad13ed
commit 97dc6b19d2
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -1261,7 +1261,6 @@ class DeepseekV32IndexerMetadataBuilder(AttentionMetadataBuilder):
assert num_decode_tokens + num_prefill_tokens == num_tokens
compressed_slot_mapping = slot_mapping
compressed_seq_lens = seq_lens
indexer_block_table = block_table
if self.compress_ratio > 1:
kernel_block_size = self.kernel_block_size
@@ -1297,10 +1296,12 @@ class DeepseekV32IndexerMetadataBuilder(AttentionMetadataBuilder):
self.compressed_slot_mapping_buffer[:padded_num_tokens],
dim=0,
)
compressed_seq_lens = seq_lens // self.compress_ratio
prefill_metadata = None
if num_prefills > 0:
compressed_seq_lens = (
seq_lens // self.compress_ratio if self.compress_ratio > 1 else seq_lens
)
# This CPU value is an upper bound for async-spec extend rows. It
# is safe for chunking/allocation because CUDA metadata below is
# built from exact device seq_lens and gather ignores the tail.
+1 -1
View File
@@ -613,7 +613,7 @@ class DeepseekSparseSWAMetadataBuilder(AttentionMetadataBuilder):
)
is_valid_token = self.is_valid_token[: slot_mapping.shape[0]]
is_valid_token.copy_(slot_mapping >= 0)
torch.ge(slot_mapping, 0, out=is_valid_token)
if replay_start is None:
# Graph captures build without it; their dummy batches replay nothing.
replay_start = self.no_replay_start