Skip to content
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] Add DeepSeek-V2 support #51

Merged
merged 9 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions gptqmodel/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
from .starcoder2 import Starcoder2GPTQ
from .xverse import XverseGPTQ
from .yi import YiGPTQ
from .deepseek_v2 import DeepSeekV2GPTQ
1 change: 1 addition & 0 deletions gptqmodel/models/_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"minicpm",
"qwen2_moe",
"dbrx_converted",
"deepseek_v2"
]

EXLLAMA_DEFAULT_MAX_INPUT_LENGTH = 2048
Expand Down
2 changes: 2 additions & 0 deletions gptqmodel/models/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .starcoder2 import Starcoder2GPTQ
from .xverse import XverseGPTQ
from .yi import YiGPTQ
from .deepseek_v2 import DeepSeekV2GPTQ

MODEL_MAP = {
"bloom": BloomGPTQ,
Expand Down Expand Up @@ -70,6 +71,7 @@
"qwen2_moe": Qwen2MoeGPTQ,
"dbrx": DbrxGPTQ,
"dbrx_converted": DbrxConvertedGPTQ,
"deepseek_v2": DeepSeekV2GPTQ,
}


Expand Down
33 changes: 33 additions & 0 deletions gptqmodel/models/deepseek_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from ._const import EXPERT_INDEX_PLACEHOLDER
from .base import BaseGPTQModel


class DeepSeekV2GPTQ(BaseGPTQModel):
# deepseek_v2 requires custom model code
require_trust_remote_code = True

# allow dynamic expert index for layer_modules so we don't need to write out 64 layers here
# config.num_experts contains the actual expert count used for index
dynamic_expert_index = "n_routed_experts"

base_modules = ["model.embed_tokens", "model.norm"]

layers_node = "model.layers"
layer_type = "DeepseekV2DecoderLayer"
layer_modules = [
# 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"],
["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"],
]
Loading