-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[Model] FalconMamba Support #9325
[Model] FalconMamba Support #9325
Conversation
👋 Hi! Thank you for contributing to the vLLM project. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can do one of these:
🚀 |
hidden_size: int, | ||
eps: float = 1e-6, | ||
var_hidden_size: Optional[int] = None, | ||
is_learnable: bool = True) -> 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.
RMSNorm weights are non learnable for FalconMamba model.
The idea is to add support for non learnable RMSNorm weights, so we can benefit from the same forward types of this class.
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.
Could you explain this a bit more? It seems like this might have been done to work around some issues that popped up during weight loading. Is that right?
And am I right that the weights will always be 1.0 for Falcon Mamba, i.e. we could skip the application of the weights for dt_layernorm
, b_layernorm
, and c_layernorm
?
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.
- The idea is to register weights as parameters when they are learnable and register them as buffers whenever they are not so that they will not be included in the state_dict of the model.
the same logic is applied here https://pytorch.org/docs/stable/_modules/torch/nn/modules/normalization.html#RMSNorm (pytorch implementation of RMSNorm)
2.Yes , you are right.
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.
Thanks for the explanation -- I think it would be better to handle this in FalconMambaForCausalLM.load_weights
, since it's a special case that only applies to FalconMamba currently.
In load_weights, could you add a condition to check if dt_layernorm, b_layernorm, or c_layernorm is in the name? If this is the case, we can set the weight loader to a function that explicitly sets all of the elements to 1.0, which will make things explicitly clear.
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.
Thanks for the review
I managed to integrate FalconMamba inside mamba.py.
for rmsnorm , i reveretd the changes , but i think there is no need to handle dt_layernorm, b_layernorm, or c_layernorm inside load_weights since they have been initialised as nn.parameters(torch.ones(hidden_size)) inside RMSNorm initial implementation which is compatible with FalconMamba dt,b,c rmsnorms.
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.
Overall looks good, thanks for the contribution!
I left a few inline comments. Biggest thing for me is to understand what's happening with the layernorm weight to see if this is the right approach.
In a subsequent PR, we should definitely factor out the mixer layer (cc @mzusman if you still plan to tackle it, or I can do it as well)
|
||
from ...utils import check_outputs_equal | ||
|
||
MODELS = ["tiiuae/falcon-mamba-tiny-dev"] |
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.
Instead of adding the test_falcon_mamba.py
file, could you add this to the list of models in test_mamba.py
?
@@ -11,7 +11,7 @@ Text-only Language Models | |||
^^^^^^^^^^^^^^^^^^^^^^^^^ | |||
|
|||
Text Generation | |||
--------------- | |||
--------------- |
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.
nit: remove spurious whitespace
@@ -156,7 +161,7 @@ Text Generation | |||
- Mamba | |||
- :code:`state-spaces/mamba-130m-hf`, :code:`state-spaces/mamba-790m-hf`, :code:`state-spaces/mamba-2.8b-hf`, etc. | |||
- ✅︎ | |||
- | |||
- |
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.
ditto, spurious whitespace
hidden_size: int, | ||
eps: float = 1e-6, | ||
var_hidden_size: Optional[int] = None, | ||
is_learnable: bool = True) -> 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.
Could you explain this a bit more? It seems like this might have been done to work around some issues that popped up during weight loading. Is that right?
And am I right that the weights will always be 1.0 for Falcon Mamba, i.e. we could skip the application of the weights for dt_layernorm
, b_layernorm
, and c_layernorm
?
self.layer_idx = layer_idx | ||
self.config = config | ||
self.mixer = FalconMambaMixer(config, layer_idx) | ||
|
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.
Just wondering: Is there no feed-forward section for FalconMamba?
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.
Yes, there is no feed forward section in Falcon Mamba , it is a sequence of consecutive mamba1 blocks with extra RMSNorm on input dependant parameters.
# (param_name, shard_name, shard_id) | ||
("qkv_proj", "q_proj", "q"), | ||
("qkv_proj", "k_proj", "k"), | ||
("qkv_proj", "v_proj", "v"), | ||
("gate_up_proj", "gate_proj", 0), | ||
("gate_up_proj", "up_proj", 1), |
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.
There's no stacked params at all, right? So I think all of this can be deleted
@dataclass | ||
class FalconMambaCacheParams: | ||
is_prompt: bool = False | ||
conv_state: torch.Tensor = torch.Tensor() | ||
ssm_state: torch.Tensor = torch.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.
Looks like this isn't used anywhere, could you remove it? (Needs to be cleaned up in mamba.py too -- I can send a PR to do that)
packed_modules_mapping = { | ||
"qkv_proj": [ | ||
"q_proj", | ||
"k_proj", | ||
"v_proj", | ||
], | ||
} | ||
|
||
# LoRA specific attributes | ||
supported_lora_modules = [ | ||
"qkv_proj", | ||
"o_proj", |
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.
The references to qkv_proj
and o_proj
should be removed since they aren't relevant to this model
if ".self_attn." in name: | ||
name = name.replace(".self_attn", "") |
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.
This can be deleted as well, no?
for param_name, weight_name, shard_id in stacked_params_mapping: | ||
if weight_name not in name: | ||
continue | ||
name = name.replace(weight_name, param_name) | ||
# Skip loading extra bias for GPTQ models. | ||
if name.endswith(".bias") and name not in params_dict: | ||
continue | ||
param = params_dict[name] | ||
weight_loader = param.weight_loader | ||
weight_loader(param, loaded_weight, shard_id) | ||
break | ||
else: |
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.
And then if there are no stacked params, I think this branch of the if statement can be removed.
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.
What do you think about modifying mamba.py
to support FalconMamba instead of adding it in its own file? Seems like you would only need to handle the additional layernorms in a couple of spots
@@ -156,7 +161,7 @@ Text Generation | |||
- Mamba | |||
- :code:`state-spaces/mamba-130m-hf`, :code:`state-spaces/mamba-790m-hf`, :code:`state-spaces/mamba-2.8b-hf`, etc. | |||
- ✅︎ | |||
- | |||
- |
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.
nit: spurious whitespace
hidden_size: int, | ||
eps: float = 1e-6, | ||
var_hidden_size: Optional[int] = None, | ||
is_learnable: bool = True) -> 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.
Thanks for the explanation -- I think it would be better to handle this in FalconMambaForCausalLM.load_weights
, since it's a special case that only applies to FalconMamba currently.
In load_weights, could you add a condition to check if dt_layernorm, b_layernorm, or c_layernorm is in the name? If this is the case, we can set the weight loader to a function that explicitly sets all of the elements to 1.0, which will make things explicitly clear.
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.
Looks good. Thank you for the contribution!
@@ -27,7 +27,6 @@ def __init__( | |||
self.variance_epsilon = eps | |||
self.variance_size_override = (None if var_hidden_size == hidden_size | |||
else var_hidden_size) | |||
|
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.
nit: best not to introduce whitespace-only changes to files
Signed-off-by: charlifu <[email protected]>
Signed-off-by: Vinay Damodaran <[email protected]>
Signed-off-by: Alvant <[email protected]>
Signed-off-by: Amit Garg <[email protected]>
Signed-off-by: qishuai <[email protected]>
Signed-off-by: Sumit Dubey <[email protected]>
This PR adds the support for FalconMamba in VLLM.
In summary , FalconMamba is the same Mamba class without the feed forward block and with the B_C_dt_rms LayerNorm.
Note that FalconMamba is now supported in transformers>=4.45.
I tried with this model https://huggingface.co/tiiuae/falcon-mamba-7b-instruct/ and it worked well locally.
Fixes: #7478
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Adding or changing kernels
Each custom kernel needs a schema and one or more implementations to be registered with PyTorch.
Tensors
require meta-functions. Meta-functions should be implemented and registered in python so that dynamic dims can be handled automatically. See above documents for a description of meta-functions.torch.libary.opcheck()
to test the function registration and meta-function for any registered ops. Seetests/kernels
for examples.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!