Qubitium commited on
Commit
d9d3ce7
·
verified ·
1 Parent(s): 2ec0690

Add files using upload-large-folder tool

Browse files
Files changed (1) hide show
  1. test_minimax_m2_hf.py +41 -41
test_minimax_m2_hf.py CHANGED
@@ -68,47 +68,47 @@ def build_prompt(tokenizer: AutoTokenizer, question: str) -> str:
68
  return tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
69
 
70
 
71
- def assert_module_types(model: MiniMaxM2ForCausalLM) -> None:
72
- causal_lm_types = (MiniMaxM2ForCausalLM, MiniMaxForCausalLM)
73
- decoder_layer_types = (MiniMaxM2DecoderLayer, MiniMaxDecoderLayer)
74
- attention_types = (MiniMaxM2Attention, MiniMaxAttention)
75
- moe_block_types = (MiniMaxM2SparseMoeBlock, MiniMaxSparseMoeBlock)
76
- norm_types = (MiniMaxM2RMSNorm, MiniMaxRMSNorm)
77
- mlp_types = (MiniMaxM2MLP, MiniMaxMLP)
78
-
79
- assert isinstance(
80
- model, causal_lm_types
81
- ), f"Expected MiniMaxM2ForCausalLM/MiniMaxForCausalLM, received {type(model).__name__}"
82
-
83
- decoder = getattr(model, "model", None)
84
- assert decoder is not None, "Model is missing the `model` attribute with decoder layers."
85
-
86
- for layer_idx, layer in enumerate(decoder.layers):
87
- assert isinstance(
88
- layer, decoder_layer_types
89
- ), f"Layer {layer_idx}: expected MiniMax(M2)DecoderLayer, got {type(layer).__name__}"
90
- assert isinstance(
91
- layer.self_attn, attention_types
92
- ), f"Layer {layer_idx}: unexpected self_attn type {type(layer.self_attn).__name__}"
93
- assert isinstance(
94
- layer.block_sparse_moe, moe_block_types
95
- ), f"Layer {layer_idx}: unexpected MoE block type {type(layer.block_sparse_moe).__name__}"
96
- assert isinstance(
97
- layer.input_layernorm, norm_types
98
- ), f"Layer {layer_idx}: unexpected input_layernorm type {type(layer.input_layernorm).__name__}"
99
- assert isinstance(
100
- layer.post_attention_layernorm, norm_types
101
- ), f"Layer {layer_idx}: unexpected post_attention_layernorm type {type(layer.post_attention_layernorm).__name__}"
102
-
103
- moe_block = layer.block_sparse_moe
104
- assert isinstance(
105
- moe_block.experts, nn.ModuleList
106
- ), f"Layer {layer_idx}: expected experts to be a ModuleList, got {type(moe_block.experts).__name__}"
107
- for expert_idx, expert in enumerate(moe_block.experts):
108
- assert isinstance(
109
- expert, mlp_types
110
- ), f"Layer {layer_idx} expert {expert_idx}: expected MiniMax(M2)MLP, got {type(expert).__name__}"
111
-
112
 
113
  def main() -> None:
114
  args = parse_args()
 
68
  return tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
69
 
70
 
71
+ # def assert_module_types(model: MiniMaxM2ForCausalLM) -> None:
72
+ # causal_lm_types = (MiniMaxM2ForCausalLM, MiniMaxForCausalLM)
73
+ # decoder_layer_types = (MiniMaxM2DecoderLayer, MiniMaxDecoderLayer)
74
+ # attention_types = (MiniMaxM2Attention, MiniMaxAttention)
75
+ # moe_block_types = (MiniMaxM2SparseMoeBlock, MiniMaxSparseMoeBlock)
76
+ # norm_types = (MiniMaxM2RMSNorm, MiniMaxRMSNorm)
77
+ # mlp_types = (MiniMaxM2MLP, MiniMaxMLP)
78
+ #
79
+ # assert isinstance(
80
+ # model, causal_lm_types
81
+ # ), f"Expected MiniMaxM2ForCausalLM/MiniMaxForCausalLM, received {type(model).__name__}"
82
+ #
83
+ # decoder = getattr(model, "model", None)
84
+ # assert decoder is not None, "Model is missing the `model` attribute with decoder layers."
85
+ #
86
+ # for layer_idx, layer in enumerate(decoder.layers):
87
+ # assert isinstance(
88
+ # layer, decoder_layer_types
89
+ # ), f"Layer {layer_idx}: expected MiniMax(M2)DecoderLayer, got {type(layer).__name__}"
90
+ # assert isinstance(
91
+ # layer.self_attn, attention_types
92
+ # ), f"Layer {layer_idx}: unexpected self_attn type {type(layer.self_attn).__name__}"
93
+ # assert isinstance(
94
+ # layer.block_sparse_moe, moe_block_types
95
+ # ), f"Layer {layer_idx}: unexpected MoE block type {type(layer.block_sparse_moe).__name__}"
96
+ # assert isinstance(
97
+ # layer.input_layernorm, norm_types
98
+ # ), f"Layer {layer_idx}: unexpected input_layernorm type {type(layer.input_layernorm).__name__}"
99
+ # assert isinstance(
100
+ # layer.post_attention_layernorm, norm_types
101
+ # ), f"Layer {layer_idx}: unexpected post_attention_layernorm type {type(layer.post_attention_layernorm).__name__}"
102
+ #
103
+ # moe_block = layer.block_sparse_moe
104
+ # assert isinstance(
105
+ # moe_block.experts, nn.ModuleList
106
+ # ), f"Layer {layer_idx}: expected experts to be a ModuleList, got {type(moe_block.experts).__name__}"
107
+ # for expert_idx, expert in enumerate(moe_block.experts):
108
+ # assert isinstance(
109
+ # expert, mlp_types
110
+ # ), f"Layer {layer_idx} expert {expert_idx}: expected MiniMax(M2)MLP, got {type(expert).__name__}"
111
+ #
112
 
113
  def main() -> None:
114
  args = parse_args()