-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[vllm] fix: verl + vllm-ascend(version 0.9.1) running failed issue #2782
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Copyright 2024 Bytedance Ltd. and/or its affiliates | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # To support different vLLM versions, we add the model into SUPPORTED_MOE_MODELS separately to avoid triggering | ||
| # unsupported issues. | ||
| SUPPORTED_MOE_MODELS = [] | ||
|
|
||
| try: | ||
| from vllm.model_executor.models.deepseek_v2 import DeepseekV2ForCausalLM, DeepseekV3ForCausalLM | ||
|
|
||
| SUPPORTED_MOE_MODELS.append(DeepseekV2ForCausalLM) | ||
| SUPPORTED_MOE_MODELS.append(DeepseekV3ForCausalLM) | ||
| except ImportError: | ||
| pass | ||
|
|
||
| try: | ||
| from vllm.model_executor.models.mixtral import MixtralForCausalLM | ||
|
|
||
| SUPPORTED_MOE_MODELS.append(MixtralForCausalLM) | ||
| except ImportError: | ||
| pass | ||
|
|
||
| try: | ||
| from vllm.model_executor.models.qwen2_moe import Qwen2MoeForCausalLM | ||
|
|
||
| SUPPORTED_MOE_MODELS.append(Qwen2MoeForCausalLM) | ||
| except ImportError: | ||
| pass | ||
|
|
||
| try: | ||
| from vllm.model_executor.models.qwen3_moe import Qwen3MoeForCausalLM | ||
|
|
||
| SUPPORTED_MOE_MODELS.append(Qwen3MoeForCausalLM) | ||
| except ImportError: | ||
| pass | ||
|
|
||
| try: | ||
| from vllm.model_executor.models.kimi_vl import KimiVLForConditionalGeneration | ||
|
|
||
| SUPPORTED_MOE_MODELS.append(KimiVLForConditionalGeneration) | ||
| except ImportError: | ||
| pass | ||
|
|
||
|
|
||
| def patch_vllm_moe_model_weight_loader(model): | ||
| # this is a work around to load the weight of vllm fused moe model | ||
| # it is from a bug from vllm 0.8.2 | ||
| # all the weights are supposed to have a weight_loader, but the moe weights | ||
| # do not have a weight_loader, so we need to patch it | ||
| # (True, 'model.embed_tokens.weight') | ||
| # (True, 'model.layers.0.self_attn.qkv_proj.weight') | ||
| # (True, 'model.layers.0.self_attn.qkv_proj.bias') | ||
| # (True, 'model.layers.0.self_attn.o_proj.weight') | ||
| # (True, 'model.layers.0.mlp.gate.weight') | ||
| # (True, 'model.layers.0.mlp.shared_expert.gate_up_proj.weight') | ||
| # (True, 'model.layers.0.mlp.shared_expert.down_proj.weight') | ||
| # (False, 'model.layers.0.mlp.shared_expert_gate.weight') use default | ||
| # (False, 'model.layers.0.input_layernorm.weight') use default | ||
| # (False, 'model.layers.0.post_attention_layernorm.weight') use default | ||
| # (False, 'model.layers.0.mlp.experts.w13_weight') use mlp.experts.weight_loader | ||
| # (False, 'model.layers.0.mlp.experts.w2_weight') use mlp.experts.weight_loader | ||
|
|
||
| # Define MLP attribute mapping for different model types | ||
| MLP_ATTR_MAPPING = { | ||
| MixtralForCausalLM: "block_sparse_moe", | ||
| } | ||
| DEFAULT_MLP_ATTR = "mlp" | ||
|
|
||
| if not isinstance(model, tuple(SUPPORTED_MOE_MODELS)): | ||
| return | ||
|
|
||
| model = getattr(model, "model", None) or getattr(model, "language_model", None) | ||
| if model is None: | ||
| raise ValueError("The provided model does not have a valid 'model' or 'language_model' attribute.") | ||
|
|
||
| for layer in model.layers: | ||
| mlp_attr = MLP_ATTR_MAPPING.get(type(model), DEFAULT_MLP_ATTR) | ||
| mlp = getattr(layer, mlp_attr) | ||
|
|
||
| param_dict = dict(mlp.named_parameters()) | ||
| for name, param in param_dict.items(): | ||
| if "w13_weight" in name or "w2_weight" in name: | ||
| param.weight_loader = mlp.experts.weight_loader | ||
leo-pony marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
Oops, something went wrong.
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.