Skip to content

Commit

Permalink
init method is executed after from_quantized(), so it cannot obtain t…
Browse files Browse the repository at this point in the history
…he correct layer_modules (ModelCloud#112)

Co-authored-by: LRL-ModelCloud <lrl@modelcloud.ai>
  • Loading branch information
LRL-ModelCloud and LRL-ModelCloud authored Jun 28, 2024
1 parent e3a9f96 commit ede2154
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions gptqmodel/models/deepseek_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class DeepSeekV2GPTQ(BaseGPTQModel):

# DeepSeek-V2 uses 160 experts, v2-lite is auto-switched during __init__
layer_modules = [
# DeepSeek-V2 and DeepSeek-V2-Lite use same model_type, but different self_attn
# so we provide different layer_modules usage.
# DeepSeek-V2-Lite usage
["self_attn.q_proj", "self_attn.kv_a_proj_with_mqa", "self_attn.kv_b_proj"],

# DeepSeek-V2 usage, included in layer 0-59
["self_attn.q_a_proj", "self_attn.q_b_proj", "self_attn.kv_a_proj_with_mqa", "self_attn.kv_b_proj"],

Expand All @@ -34,33 +39,4 @@ class DeepSeekV2GPTQ(BaseGPTQModel):
# included in layer 1-59
["mlp.shared_experts.gate_proj", "mlp.shared_experts.up_proj"],
["mlp.shared_experts.down_proj"],
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

num_experts = getattr(self.model.config, self.dynamic_expert_index)

# DeepSeek-V2 and DeepSeek-V2-Lite use same model_type, but different self_attn, expert count, etc
# so we need to adjust the layer_modules based on the expert count
# DeepSeek-V2-Lite uses 64
if num_experts == 64:
self.layer_modules = [
# DeepSeek-V2-Lite usage
["self_attn.q_proj", "self_attn.kv_a_proj_with_mqa", "self_attn.kv_b_proj"],

["self_attn.o_proj"],

# included in layer 0
["mlp.gate_proj", "mlp.up_proj"],
["mlp.down_proj"],

# included in layer 1-59, uses dynamic_expert_index
[f"mlp.experts.{EXPERT_INDEX_PLACEHOLDER}.gate_proj",
f"mlp.experts.{EXPERT_INDEX_PLACEHOLDER}.up_proj"],
[f"mlp.experts.{EXPERT_INDEX_PLACEHOLDER}.down_proj"],

# included in layer 1-59
["mlp.shared_experts.gate_proj", "mlp.shared_experts.up_proj"],
["mlp.shared_experts.down_proj"],
]
]

0 comments on commit ede2154

Please sign in to comment.