-
-
Notifications
You must be signed in to change notification settings - Fork 20.4k
[Spec Decode] Enable efficient speculative decoding with FlashInfer-MLA #25984
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 1 commit
c5c5606
4d5fbdc
d0c7b36
156b8df
d7ffbd2
e1ac9d8
99b6fe3
9e2a52b
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 |
|---|---|---|
|
|
@@ -190,7 +190,7 @@ | |
| import functools | ||
| from abc import abstractmethod | ||
| from dataclasses import dataclass, field | ||
| from typing import Generic, Optional, TypeVar, Union | ||
| from typing import ClassVar, Generic, Optional, TypeVar, Union | ||
|
|
||
| import torch | ||
| from tqdm import tqdm | ||
|
|
@@ -436,6 +436,26 @@ class MLACommonMetadataBuilder(AttentionMetadataBuilder[M]): | |
| NOTE: Please read the comment at the top of the file before trying to | ||
| understand this class | ||
| """ | ||
|
|
||
| # Whether the backend supports reordering the batch such that | ||
| # short sequences (i.e. verification for speculative decoding) are | ||
| # classified as decode requests. | ||
| # If True, this will increase `reorder_batch_threshold` (below) when | ||
| # speculative decoding is enabled. | ||
| supports_spec_as_decode: ClassVar[bool] = False | ||
|
|
||
| # Whether the backend supports grouping decode requests with | ||
| # different query lengths in the same batch. If False, when | ||
| # `reorder_batch_threshold > 1`, any decode requests which do not | ||
| # have the same query length as the first decode request will | ||
| # fall back to the prefill kernel. | ||
| supports_nonuniform_decode: ClassVar[bool] = False | ||
|
Collaborator
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. nit: is this needed if its always set to false? (I think we should set this for FlashAttnMLA since it does support
Collaborator
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. I think we maybe can actually just unify
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. @LucasWilkinson I'm pretty sure there can be a full matrix of options here, and that different combinations are useful. For example:
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. I will update FlashAttnMLA to reflect the correct defaults, but I don't know how to support each of these 3 cases cleanly with only a single flag. Let me know if you would still prefer a different interface.
Collaborator
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. I think for the case I think if backend that |
||
|
|
||
| # The threshold for reordering the batch into decode and prefill requests. | ||
| # If > 1, the batch will be reordered such that requests with | ||
| # query length <= threshold are classified as decode requests. | ||
| # Use `supports_spec_as_decode` (above) to set this automatically | ||
| # when speculative decoding is enabled. | ||
| reorder_batch_threshold: int = 1 | ||
|
|
||
| @staticmethod | ||
|
|
@@ -479,6 +499,7 @@ def __init__(self, | |
| self.model_config = vllm_config.model_config | ||
| parallel_config = vllm_config.parallel_config | ||
| self.compilation_config = vllm_config.compilation_config | ||
| self.vllm_config = vllm_config | ||
| self.device = device | ||
|
|
||
| self.num_heads = self.model_config.get_num_attention_heads( | ||
|
|
@@ -551,6 +572,10 @@ def __init__(self, | |
| device=device, | ||
| ) | ||
|
|
||
| supports_spec_as_decode = self.supports_spec_as_decode | ||
| self._init_reorder_batch_threshold(self.reorder_batch_threshold, | ||
| supports_spec_as_decode) | ||
|
|
||
| def _build_fi_prefill_wrappers(self, prefill: FlashInferPrefillMetadata): | ||
| qo_indptr = prefill.query_start_loc | ||
|
|
||
|
|
@@ -680,8 +705,10 @@ def build(self, | |
| query_seq_lens_cpu) | ||
|
|
||
| num_decodes, num_prefills, num_decode_tokens, num_prefill_tokens = \ | ||
| split_decodes_and_prefills(common_attn_metadata, | ||
| decode_threshold=self.reorder_batch_threshold) | ||
| split_decodes_and_prefills( | ||
| common_attn_metadata, | ||
| decode_threshold=self.reorder_batch_threshold, | ||
| require_uniform=not self.supports_nonuniform_decode) | ||
|
|
||
| # Note(hc): update seq_lens of decode reqs under DCP. | ||
| if self.dcp_world_size > 1: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.