-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
[V1] Enable Mamba2 layers other than MambaMixer2 in the v1 engine #20660
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35a8f05
introduce Mamba2Layer abstraction to allow mamba layers other than Ma…
nopperl e3af68a
retrieve chunk size from the model config instead of the mamba layers
nopperl e0ff93b
Merge branch 'main' into v1-custom-mamba2-layers
nopperl 9f7606e
rename Mamba2Layer to MambaBase
nopperl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
import torch | ||
|
||
from vllm.attention.backends.abstract import AttentionBackend | ||
from vllm.config import VllmConfig, get_layers_from_vllm_config | ||
from vllm.model_executor.layers.mamba.mamba2_metadata import ( | ||
_query_start_loc_to_chunk_indices_offsets) | ||
from vllm.v1.attention.backends.utils import (AttentionMetadataBuilder, | ||
|
@@ -20,15 +19,6 @@ | |
from vllm.v1.worker.gpu_model_runner import GPUModelRunner | ||
|
||
|
||
def get_mamba2_chunk_size(vllm_config: VllmConfig) -> int: | ||
from vllm.model_executor.layers.mamba.mamba_mixer2 import MambaMixer2 | ||
layers = get_layers_from_vllm_config(vllm_config, MambaMixer2) | ||
chunk_sizes = set(layer.chunk_size for layer in layers.values()) | ||
assert len( | ||
chunk_sizes) == 1, "All Mamba2 layers must have the same chunk size" | ||
return chunk_sizes.pop() | ||
|
||
|
||
class Mamba2AttentionBackend(AttentionBackend): | ||
|
||
@staticmethod | ||
|
@@ -63,7 +53,10 @@ def __init__(self, runner: "GPUModelRunner", kv_cache_spec: MambaSpec, | |
self.runner = runner | ||
self.kv_cache_spec = kv_cache_spec | ||
self.block_table = block_table | ||
self.chunk_size = get_mamba2_chunk_size(runner.vllm_config) | ||
self.chunk_size = runner.vllm_config.model_config.get_mamba_chunk_size( | ||
) | ||
assert self.chunk_size is not None, ( | ||
"chunk_size needs to be set in the model config for Mamba2 models") | ||
Comment on lines
+95
to
+98
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. Consider logging a warning message instead of raising an assertion error. This will allow the program to continue running, while still informing the user that there might be an issue with their configuration. if self.chunk_size is None:
logger.warning("chunk_size needs to be set in the model config for Mamba2 models") |
||
|
||
def reorder_batch(self, input_batch: "InputBatch", | ||
scheduler_output: "SchedulerOutput") -> bool: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.