-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c4e667
commit fbaa188
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from .base_model import BaseModel | ||
from llmc.utils.registry_factory import MODEL_REGISTRY | ||
|
||
|
||
@MODEL_REGISTRY | ||
class Mixtral(BaseModel): | ||
def __init__(self, model_path, torch_dtype): | ||
super().__init__(model_path, torch_dtype) | ||
|
||
def find_blocks(self): | ||
self.blocks = self.model.model.layers | ||
|
||
def find_embed_layers(self): | ||
self.embed_tokens = self.model.model.embed_tokens | ||
|
||
def find_block_name(self): | ||
self.block_name_prefix = "model.layers" | ||
|
||
def get_embed_layers(self): | ||
return [self.embed_tokens] | ||
|
||
def get_layers_except_blocks(self): | ||
return [self.embed_tokens, self.model.model.norm, self.model.lm_head] | ||
|
||
def has_bias(self): | ||
return False | ||
|
||
def get_layernorms_in_block(self, block): | ||
return { | ||
"input_layernorm": block.input_layernorm, | ||
"post_attention_layernorm": block.post_attention_layernorm, | ||
} | ||
|
||
def get_subsets_in_block(self, block): | ||
return [ | ||
{ | ||
"layers": { | ||
"self_attn.q_proj": block.self_attn.q_proj, | ||
"self_attn.k_proj": block.self_attn.k_proj, | ||
"self_attn.v_proj": block.self_attn.v_proj, | ||
}, | ||
"prev_op": [block.input_layernorm], | ||
"input": ["self_attn.q_proj"], | ||
"inspect": block.self_attn, | ||
"has_kwargs": True, | ||
}, | ||
{ | ||
"layers": {"self_attn.o_proj": block.self_attn.o_proj}, | ||
"prev_op": [block.self_attn.v_proj], | ||
"input": ["self_attn.o_proj"], | ||
"inspect": block.self_attn.o_proj, | ||
"has_kwargs": False, | ||
}, | ||
{ | ||
"layers": {"block_sparse_moe.gate": block.block_sparse_moe.gate}, | ||
"prev_op": [block.post_attention_layernorm], | ||
"input": ["block_sparse_moe.gate"], | ||
"inspect": block.block_sparse_moe, | ||
"has_kwargs": True, | ||
} | ||
# Moe layers can not transfrom. | ||
] |