Skip to content

[model] fix load_weights function for dpsk fusedmoe class #16170

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions vllm/model_executor/models/deepseek_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Inference-only DeepseekV2/DeepseekV3 model."""
from typing import Any, Dict, Iterable, Optional, Set, Tuple, Union
from typing import Any, Dict, Iterable, Optional, Set, Tuple, Union, Callable

import torch
from torch import nn
Expand Down Expand Up @@ -782,7 +782,11 @@
continue

param = params_dict[name]
weight_loader = param.weight_loader

if hasattr(param, 'weight_loader'):
weight_loader = param.weight_loader
else:
weight_loader = get_fusedmoe_weight_loader(self.model, name)
weight_loader(param,
loaded_weight,
name,
Expand Down Expand Up @@ -814,6 +818,20 @@
pass


import re
def get_layer_index(layer_name: str) -> Optional[int]:

Check failure on line 822 in vllm/model_executor/models/deepseek_v2.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E402)

vllm/model_executor/models/deepseek_v2.py:822:1: E402 Module level import not at top of file
pattern = r"layers\.(\d+)"
match = re.search(pattern, layer_name)
if match:
return int(match.group(1))
return None

def get_fusedmoe_weight_loader(model: DeepseekV2ForCausalLM,
name: str) -> Optional[Callable]:
layer_idx = get_layer_index(name)
weight_loader = model.layers[layer_idx].mlp.experts.weight_loader
return weight_loader

def get_spec_layer_idx_from_weight_name(config: PretrainedConfig,
weight_name: str) -> Optional[int]:
if hasattr(config,
Expand Down
Loading