-
Notifications
You must be signed in to change notification settings - Fork 458
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
Added support for DeepseekV2 model #382
base: main
Are you sure you want to change the base?
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"model_type": "deepseekv2", | ||
"architectures": [ | ||
"DeepseekV2ForCausalLM" | ||
], | ||
"pre_weights": [ | ||
{ | ||
"name": "model.embed_tokens.weight", | ||
"is_embed": true | ||
} | ||
], | ||
"post_weights": [ | ||
{ | ||
"name": "model.norm.weight" | ||
}, | ||
{ | ||
"name": "lm_head.weight", | ||
"is_embed": true, | ||
"aliases": [ | ||
"model.embed_tokens.weight" | ||
] | ||
} | ||
], | ||
"num_layers_config_key": "num_hidden_layers", | ||
"layer_templates": { | ||
"weights": [ | ||
{ | ||
"name" : "model.layers.${layer_index}.self_attn.q_proj.weight" | ||
}, | ||
{ | ||
"name" : "model.layers.${layer_index}.self_attn.kv_a_proj_with_mqa.weight" | ||
}, | ||
{ | ||
"name" : "model.layers.${layer_index}.self_attn.kv_a_layernorm.weight" | ||
}, | ||
{ | ||
"name" : "model.layers.${layer_index}.self_attn.kv_b_proj.weight" | ||
}, | ||
{ | ||
"name" : "model.layers.${layer_index}.self_attn.o_proj.weight" | ||
}, | ||
{ | ||
"name": "model.layers.${layer_index}.input_layernorm.weight" | ||
}, | ||
{ | ||
"name": "model.layers.${layer_index}.post_attention_layernorm.weight" | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,6 +326,57 @@ def sliceable(self) -> bool: | |
def has_defined_spaces(self) -> bool: | ||
return False | ||
|
||
class DeepseekV2TensorNames(ArchitectureInfo, BaseModel): | ||
ARCHITECTURE_NAME: ClassVar[str] = "DeepseekV2ForCausalLM" | ||
num_local_experts: int | ||
|
||
def name(self) -> str: | ||
return "DeepseekV2" | ||
|
||
@classmethod | ||
def from_config(cls, config: PretrainedConfig): | ||
return DeepseekV2TensorNames(num_local_experts=config.n_routed_experts) | ||
|
||
def pre_weights(sef, config: PretrainedConfig) -> List[WeightInfo]: | ||
return DEEPSEEKV2_INFO.pre_weights(config) | ||
|
||
def post_weights(self, config: PretrainedConfig) -> List[WeightInfo]: | ||
return DEEPSEEKV2_INFO.post_weights(config) | ||
|
||
def num_layers_config_key(self) -> str: | ||
return DEEPSEEKV2_INFO.num_layers_config_key() | ||
|
||
def layer_weights( | ||
self, index: int, config: PretrainedConfig | ||
) -> Optional[List[WeightInfo]]: | ||
num_experts = self.num_local_experts | ||
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. Nit: Any reason for local aliasing? I see it is also present in the Mixtral code, but any reason you left it in? |
||
prefix = f"model.layers.{index}" | ||
tensor_names = [] | ||
|
||
if index > 0: | ||
for expert_idx in range(num_experts): | ||
for param in ("gate_proj", "up_proj", "down_proj"): | ||
tensor_names.append( | ||
prefix + f".mlp.experts.{expert_idx}.{param}.weight" | ||
aditya-29 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
tensor_names.append(prefix + ".mlp.gate.weight") | ||
|
||
tensor_names.append(prefix + ".mlp.shared_experts.gate_proj.weight") | ||
tensor_names.append(prefix + ".mlp.shared_experts.up_proj.weight") | ||
tensor_names.append(prefix + ".mlp.shared_experts.down_proj.weight") | ||
|
||
res = [WeightInfo(name=name) for name in tensor_names] | ||
|
||
for weight_info in DEEPSEEKV2_INFO.layer_weights(index, config): | ||
res.append(weight_info) | ||
|
||
return res | ||
|
||
def sliceable(self) -> bool: | ||
return True | ||
|
||
def has_defined_spaces(self) -> bool: | ||
return False | ||
|
||
def _load_json_arch(name: str) -> JsonArchitectureInfo: | ||
text = importlib.resources.read_text(mergekit._data.architectures, name) | ||
|
@@ -353,6 +404,7 @@ def _load_all_architectures() -> ( | |
JSON_ARCHITECTURES, NAME_TO_ARCH = _load_all_architectures() | ||
MISTRAL_INFO = _load_json_arch("mistral.json") | ||
QWEN2_INFO = _load_json_arch("qwen2.json") | ||
DEEPSEEKV2_INFO = _load_json_arch("deepseekv2.json") | ||
|
||
|
||
def get_architecture_info(config: PretrainedConfig) -> ArchitectureInfo: | ||
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. Unless I am mistaken which I could be, there needs to be a clause within the |
||
|
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.
Unless I'm mistaken I don't think this weight exists in the model. Please see here: https://huggingface.co/deepseek-ai/DeepSeek-V2/raw/main/model.safetensors.index.json