-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
[LoRA] feat: Support LoRA for DeepSeek V4 #52986
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 all commits
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 |
|---|---|---|
|
|
@@ -1001,14 +1001,17 @@ def make_expert_params_mapping( | |
| See `build_expert_params_mapping` for the returned tuple format. | ||
| """ | ||
| has_base_layer = any(".base_layer." in n for n, _ in model.named_parameters()) | ||
| prefix = "base_layer." if has_base_layer else "" | ||
| # These loaders index ``params_dict[full_name]``, so both sides get it. | ||
| return RoutedExperts.build_expert_params_mapping( | ||
| ckpt_gate_proj_name, | ||
| ckpt_down_proj_name, | ||
| ckpt_up_proj_name, | ||
| num_experts, | ||
| num_redundant_experts, | ||
| routed_experts_prefix, | ||
| "base_layer." if has_base_layer else "", | ||
| lora_base_layer_prefix=prefix, | ||
| lora_base_layer_prefix_on_param_name=prefix, | ||
| ) | ||
|
|
||
| @staticmethod | ||
|
|
@@ -1020,6 +1023,7 @@ def build_expert_params_mapping( | |
| num_redundant_experts: int = 0, | ||
| routed_experts_prefix: str = "routed_experts", | ||
| lora_base_layer_prefix: str = "", | ||
| lora_base_layer_prefix_on_param_name: str = "", | ||
|
Member
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. do we need this argument?
Contributor
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. They must be independent because the two resolution paths use different namespaces: |
||
| include_fused: bool = False, | ||
| ) -> list[tuple[str, str, int, str]]: | ||
| """ | ||
|
|
@@ -1034,7 +1038,14 @@ def build_expert_params_mapping( | |
| ckpt_up_proj_name: Name of up projection in checkpoint | ||
| num_experts: Number of logical (non-redundant) experts | ||
| num_redundant_experts: Number of redundant experts | ||
| lora_base_layer_prefix: Prefix to add if this layer is a LoRA base layer | ||
| lora_base_layer_prefix: LoRA ``base_layer.`` prefix for the | ||
| ``weight_name`` (checkpoint) side | ||
| lora_base_layer_prefix_on_param_name: same, for the ``param_name`` | ||
| side. Independent because ``get_expert_mapping`` resolves | ||
| ``param_name`` via ``getattr`` against this layer's bare | ||
| ``w13_weight``/``w2_weight`` (no prefix), while | ||
| ``make_expert_params_mapping`` indexes the model-wide | ||
| ``params_dict`` (prefix included). | ||
| include_fused: Prepend the fused pre-fused-checkpoint entries | ||
|
|
||
| Returns: | ||
|
|
@@ -1060,8 +1071,10 @@ def build_expert_params_mapping( | |
| if routed_experts_prefix != "": | ||
| routed_experts_prefix = f"{routed_experts_prefix}." | ||
|
|
||
| w13 = f"experts.{lora_base_layer_prefix}{routed_experts_prefix}w13_" | ||
| w2 = f"experts.{lora_base_layer_prefix}{routed_experts_prefix}w2_" | ||
| w13 = ( | ||
| f"experts.{lora_base_layer_prefix_on_param_name}{routed_experts_prefix}w13_" | ||
| ) | ||
| w2 = f"experts.{lora_base_layer_prefix_on_param_name}{routed_experts_prefix}w2_" | ||
|
|
||
| fused_mapping = [] | ||
| if include_fused: | ||
|
|
||
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.
QQ: could you please explain this in detail?
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 transparently forwards attribute misses to the wrapped base_layer. When LoRA is applied, vLLM wraps the original layer in a LoRA shim (FusedMoEWithLoRA/BaseLayerWithLoRA) and demotes the original into a .base_layer. submodule. The weight loader resolves params via recursive getattr (AutoWeightsLoader). Without getattr, getattr(shim, "weight") raises AttributeError, So getattr makes shim.weight resolve to shim.base_layer.weight.
Mechanically: it checks own _parameters/_buffers/modules first, then for public names forwards to base_layer; private (-prefixed) names stay local.