Repository navigation
[K3 Perf] Optimize k3 mamba metadata preparation, 6.6~7.6x kernel performance improvement #52388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
beba6f9
5413a66
c6a9461
fa59e4d
8e3f0ae
173a3c2
32e3584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,6 +296,8 @@ def commit_recoverssm_state( | |
|
|
||
|
|
||
| class KimiK3KDAMetadataBuilder(GDNAttentionMetadataBuilder): | ||
| mamba_aligned_state_indices: torch.Tensor | None = None | ||
|
|
||
| def __init__( | ||
| self, | ||
| kv_cache_spec: MambaSpec, | ||
|
|
@@ -357,12 +359,13 @@ def build( # type: ignore[override] | |
| # offsets = torch.arange(1 + num_speculative_blocks, dtype=torch.int32) | ||
| # indices = (start[:, None] + offsets).to(torch.int64) | ||
| # block_table_tensor = torch.gather(block_table, 1, indices) | ||
| block_table_tensor = _mamba_get_block_table_tensor( | ||
| m.block_table_tensor, | ||
| m.seq_lens, | ||
| self.kv_cache_spec, | ||
| self.vllm_config.cache_config.mamba_cache_mode, | ||
| ) | ||
| if self.vllm_config.cache_config.mamba_cache_mode == "align": | ||
| assert self.mamba_aligned_state_indices is not None, ( | ||
| "Aligned Mamba state indices must be precomputed" | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently when
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, fixed! |
||
| block_table_tensor = self.mamba_aligned_state_indices[: m.num_reqs] | ||
| else: | ||
| block_table_tensor = m.block_table_tensor | ||
|
|
||
| if not self.use_spec_decode or num_decode_draft_tokens_cpu is None: | ||
| spec_sequence_masks_cpu = None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if there's any cleanup we can do now, or in the future once MRV1 goes away -- Can we remove
_mamba_get_block_table_tensor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it for now as fallback will need it, I also add a TODO to remove them when MRv2 is used by default.