[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:
co-authored by
OpenAI Codex
parent
3c84ad13ed
commit
97dc6b19d2
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user