yujiepan commited on
Commit
134dbcc
·
verified ·
1 Parent(s): 187c83c

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
.meta.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "torch": "2.11.0",
3
+ "transformers": "5.5.0"
4
+ }
README.md ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - MiniMaxAI/MiniMax-M2.7
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [MiniMaxAI/MiniMax-M2.7](https://huggingface.co/MiniMaxAI/MiniMax-M2.7).
8
+
9
+ | File path | Size |
10
+ |------|------|
11
+ | model.safetensors | 7.4MB |
12
+
13
+
14
+ ### Example usage:
15
+
16
+ - vLLM
17
+
18
+ ```bash
19
+ vllm serve tiny-random/minimax-m2.7 \
20
+ --trust-remote-code \
21
+ --tensor-parallel-size 1 \
22
+ --reasoning-parser minimax_m2_append_think \
23
+ --enable-auto-tool-choice \
24
+ --tool-call-parser minimax_m2
25
+ ```
26
+
27
+ - SGLang
28
+
29
+ ```bash
30
+ python -m sglang.launch_server \
31
+ -trust-remote-code \
32
+ --model-path tiny-random/minimax-m2.7 \
33
+ --tp-size 1 \
34
+ --tool-call-parser minimax-m2 \
35
+ --reasoning-parser minimax-append-think
36
+ ```
37
+
38
+ - Transformers
39
+
40
+ ```python
41
+ import torch
42
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
43
+
44
+ model_id = "tiny-random/minimax-m2.7"
45
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
46
+ model = AutoModelForCausalLM.from_pretrained(
47
+ model_id,
48
+ dtype=torch.bfloat16,
49
+ trust_remote_code=True,
50
+ )
51
+ pipe = pipeline('text-generation', model=model,
52
+ tokenizer=tokenizer, trust_remote_code=True)
53
+ print(pipe('Write an article about Artificial Intelligence.', max_new_tokens=16))
54
+ ```
55
+
56
+ ### Codes to create this repo:
57
+
58
+ <details>
59
+ <summary>Click to expand</summary>
60
+
61
+ ```python
62
+ import json
63
+ from pathlib import Path
64
+
65
+ import accelerate
66
+ import torch
67
+ import transformers
68
+ from huggingface_hub import file_exists, hf_hub_download
69
+ from transformers import (
70
+ AutoConfig,
71
+ AutoModelForCausalLM,
72
+ AutoTokenizer,
73
+ GenerationConfig,
74
+ set_seed,
75
+ )
76
+
77
+ source_model_id = "MiniMaxAI/MiniMax-M2.7"
78
+ save_folder = "/tmp/tiny-random/minimax-m27"
79
+
80
+ processor = AutoTokenizer.from_pretrained(source_model_id)
81
+ processor.save_pretrained(save_folder)
82
+
83
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
84
+ config_json = json.load(f)
85
+
86
+ del config_json['auto_map'] # is already supported in transformers codebase
87
+ config_json["attn_type_list"] = [1, 1]
88
+ config_json['head_dim'] = 32
89
+ config_json['hidden_size'] = 8
90
+ config_json['intermediate_size'] = 32
91
+ config_json['num_attention_heads'] = 8
92
+ config_json['num_key_value_heads'] = 4
93
+ config_json['num_hidden_layers'] = 2
94
+ config_json['mlp_intermediate_size'] = 32
95
+ config_json['rotary_dim'] = 16
96
+ del config_json['quantization_config']
97
+
98
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
99
+ json.dump(config_json, f, indent=2)
100
+
101
+ config = AutoConfig.from_pretrained(
102
+ save_folder,
103
+ trust_remote_code=True,
104
+ )
105
+ torch.set_default_dtype(torch.bfloat16)
106
+ model = AutoModelForCausalLM.from_config(config, trust_remote_code=True)
107
+ torch.set_default_dtype(torch.float32)
108
+ print(model)
109
+
110
+ # according to source model, gate is in FP32
111
+ for i in range(config.num_hidden_layers):
112
+ model.model.layers[i].mlp.gate = model.model.layers[i].mlp.gate.float()
113
+ model.model.layers[i].mlp.e_score_correction_bias = model.model.layers[i].mlp.e_score_correction_bias.float()
114
+ if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'):
115
+ model.generation_config = GenerationConfig.from_pretrained(
116
+ source_model_id, trust_remote_code=True,
117
+ )
118
+ set_seed(42)
119
+ model = model.cpu()
120
+ with torch.no_grad():
121
+ for name, p in sorted(model.named_parameters()):
122
+ torch.nn.init.normal_(p, 0, 0.1)
123
+ print(name, p.shape)
124
+ model.save_pretrained(save_folder)
125
+ print(model)
126
+ ```
127
+
128
+ </details>
129
+
130
+ ### Printing the model:
131
+
132
+ <details><summary>Click to expand</summary>
133
+
134
+ ```text
135
+ MiniMaxM2ForCausalLM(
136
+ (model): MiniMaxM2Model(
137
+ (embed_tokens): Embedding(200064, 8)
138
+ (layers): ModuleList(
139
+ (0-1): 2 x MiniMaxM2DecoderLayer(
140
+ (self_attn): MiniMaxM2Attention(
141
+ (q_proj): Linear(in_features=8, out_features=256, bias=False)
142
+ (k_proj): Linear(in_features=8, out_features=128, bias=False)
143
+ (v_proj): Linear(in_features=8, out_features=128, bias=False)
144
+ (o_proj): Linear(in_features=256, out_features=8, bias=False)
145
+ (q_norm): MiniMaxM2RMSNorm((256,), eps=1e-06)
146
+ (k_norm): MiniMaxM2RMSNorm((128,), eps=1e-06)
147
+ )
148
+ (mlp): MiniMaxM2SparseMoeBlock(
149
+ (gate): MiniMaxM2TopKRouter()
150
+ (experts): MiniMaxM2Experts(
151
+ (act_fn): SiLUActivation()
152
+ )
153
+ )
154
+ (input_layernorm): MiniMaxM2RMSNorm((8,), eps=1e-06)
155
+ (post_attention_layernorm): MiniMaxM2RMSNorm((8,), eps=1e-06)
156
+ )
157
+ )
158
+ (norm): MiniMaxM2RMSNorm((8,), eps=1e-06)
159
+ (rotary_emb): MiniMaxM2RotaryEmbedding()
160
+ )
161
+ (lm_head): Linear(in_features=8, out_features=200064, bias=False)
162
+ )
163
+ ```
164
+
165
+ </details>
chat_template.jinja ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {# ----------‑‑‑ special token variables ‑‑‑---------- #}
2
+ {%- set toolcall_begin_token = '<minimax:tool_call>' -%}
3
+ {%- set toolcall_end_token = '</minimax:tool_call>' -%}
4
+ {#- Tool Rendering Functions ============================================== -#}
5
+ {%- macro render_tool_namespace(namespace_name, tool_list) -%}
6
+ {%- for tool in tool_list -%}
7
+ <tool>{{ tool.function | tojson(ensure_ascii=False) }}</tool>
8
+ {% endfor -%}
9
+ {%- endmacro -%}
10
+ {%- macro visible_text(content) -%}
11
+ {%- if content is string -%}
12
+ {{ content }}
13
+ {%- elif content is iterable and content is not mapping -%}
14
+ {%- for item in content -%}
15
+ {%- if item is mapping and item.type == 'text' -%}
16
+ {{- item.text }}
17
+ {%- elif item is string -%}
18
+ {{- item }}
19
+ {%- endif -%}
20
+ {%- endfor -%}
21
+ {%- else -%}
22
+ {{- content }}
23
+ {%- endif -%}
24
+ {%- endmacro -%}
25
+ {#- System Message Construction ============================================ -#}
26
+ {%- macro build_system_message(system_message) -%}
27
+ {%- if system_message and system_message.content -%}
28
+ {{- visible_text(system_message.content) }}
29
+ {%- else -%}
30
+ {%- if model_identity is not defined -%}
31
+ {%- set model_identity = "You are a helpful assistant. Your name is MiniMax-M2.7 and is built by MiniMax." -%}
32
+ {%- endif -%}
33
+ {{- model_identity }}
34
+ {%- endif -%}
35
+
36
+ {#- Handle current_date -#}
37
+ {%- if system_message and system_message.current_date -%}
38
+ {{- '\n' ~ 'Current date: ' + system_message.current_date }}
39
+ {%- endif -%}
40
+ {#- Handle current_location -#}
41
+ {%- if system_message and system_message.current_location -%}
42
+ {{- '\n' ~ 'Current location: ' + system_message.current_location }}
43
+ {%- endif -%}
44
+ {%- endmacro -%}
45
+ {#- Main Template Logic ================================================= -#}
46
+ {#- Extract system message (only first message if it's system) -#}
47
+ {%- set system_message = none -%}
48
+ {%- set conversation_messages = messages -%}
49
+ {%- if messages and messages[0].role == "system" -%}
50
+ {%- set system_message = messages[0] -%}
51
+ {%- set conversation_messages = messages[1:] -%}
52
+ {%- endif -%}
53
+ {#- Get the last user message turn, for interleved thinking -#}
54
+ {%- set ns = namespace(last_user_index=-1) %}
55
+ {% for m in conversation_messages %}
56
+ {%- if m.role == 'user' %}
57
+ {% set ns.last_user_index = loop.index0 -%}
58
+ {%- endif %}
59
+ {%- endfor %}
60
+ {#- Render system message -#}
61
+ {{- ']~!b[' ~ ']~b]system' ~ '\n' }}
62
+ {{- build_system_message(system_message) }}
63
+ {#- Render tools if available -#}
64
+ {%- if tools -%}
65
+ {{- '\n\n' ~ '# Tools' ~ '\n' ~ 'You may call one or more tools to assist with the user query.\nHere are the tools available in JSONSchema format:' ~ '\n' }}
66
+ {{- '\n' ~ '<tools>' ~ '\n' }}
67
+ {{- render_tool_namespace("functions", tools) }}
68
+ {{- '</tools>' ~ '\n\n' }}
69
+ {{- 'When making tool calls, use XML format to invoke tools and pass parameters:' ~ '\n' }}
70
+ {{- '\n' ~ toolcall_begin_token }}
71
+ <invoke name="tool-name-1">
72
+ <parameter name="param-key-1">param-value-1</parameter>
73
+ <parameter name="param-key-2">param-value-2</parameter>
74
+ ...
75
+ </invoke>
76
+ {{- '\n' ~ toolcall_end_token }}
77
+ {%- endif -%}
78
+ {{- '[e~[\n' }}
79
+
80
+ {#- Render messages -#}
81
+ {%- set last_tool_call = namespace(name=none) -%}
82
+ {%- for message in conversation_messages -%}
83
+ {%- if message.role == 'assistant' -%}
84
+ {#- Only render reasoning_content if no user message follows -#}
85
+ {{- ']~b]ai' ~ '\n' }}
86
+
87
+ {%- set reasoning_content = '' %}
88
+ {%- set content = visible_text(message.content) %}
89
+ {%- if message.reasoning_content is string %}
90
+ {%- set reasoning_content = message.reasoning_content %}
91
+ {%- else %}
92
+ {%- if '</think>' in content %}
93
+ {%- set reasoning_content = content.split('</think>')[0].strip('\n').split('<think>')[-1].strip('\n') %}
94
+ {%- set content = content.split('</think>')[-1].strip('\n') %}
95
+ {%- endif %}
96
+ {%- endif %}
97
+ {%- if reasoning_content and loop.index0 > ns.last_user_index -%}
98
+ {{- '<think>' ~ '\n' ~ reasoning_content ~ '\n' ~ '</think>' ~ '\n\n' }}
99
+ {%- endif -%}
100
+ {%- if content -%}
101
+ {{- content }}
102
+ {%- endif -%}
103
+ {%- if message.tool_calls -%}
104
+ {{- '\n' ~ toolcall_begin_token ~ '\n' }}
105
+
106
+ {%- for tool_call in message.tool_calls -%}
107
+ {%- if tool_call.function %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {{- '<invoke name="' + tool_call.name + '">' }}
111
+ {% set _args = tool_call.arguments %}
112
+ {%- for k, v in _args.items() %}
113
+ {{- '<parameter name="' + k + '">' }}
114
+ {{- v | tojson(ensure_ascii=False) if v is not string else v }}
115
+ {{- '</parameter>' }}
116
+ {% endfor %}
117
+ {{- '</invoke>' ~ '\n' }}
118
+ {%- endfor -%}
119
+
120
+ {{- toolcall_end_token}}
121
+ {%- set last_tool_call.name = message.tool_calls[-1].name -%}
122
+ {%- else -%}
123
+ {%- set last_tool_call.name = none -%}
124
+ {%- endif -%}
125
+ {{- '[e~[' ~ '\n' }}
126
+
127
+ {%- elif message.role == 'tool' -%}
128
+ {%- if last_tool_call.name is none -%}
129
+ {{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
130
+ {%- endif -%}
131
+ {%- if loop.first or (conversation_messages[loop.index0 - 1].role != 'tool') -%}
132
+ {{- ']~b]tool' }}
133
+ {%- endif -%}
134
+ {%- if message.content is string -%}
135
+ {{- '\n<response>' }}
136
+ {{- message.content }}
137
+ {{- '</response>' }}
138
+ {%- else -%}
139
+ {%- for tr in message.content -%}
140
+ {{- '\n<response>' }}
141
+ {{- tr.output if tr.output is defined else (tr.text if tr.type == 'text' and tr.text is defined else tr) }}
142
+ {{- '\n</response>' }}
143
+ {%- endfor -%}
144
+ {%- endif -%}
145
+ {%- if loop.last or (conversation_messages[loop.index0 + 1].role != 'tool') -%}
146
+ {{- '[e~[\n' -}}
147
+ {%- endif -%}
148
+
149
+ {%- elif message.role == 'user' -%}
150
+ {{- ']~b]user' ~ '\n' }}
151
+ {{- visible_text(message.content) }}
152
+ {{- '[e~[' ~ '\n' }}
153
+ {%- endif -%}
154
+ {%- endfor -%}
155
+
156
+ {#- Generation prompt -#}
157
+ {%- if add_generation_prompt -%}
158
+ {{- ']~b]ai' ~ '\n' ~ '<think>' ~ '\n' }}
159
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MiniMaxM2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "attn_type_list": [
7
+ 1,
8
+ 1
9
+ ],
10
+ "bos_token_id": 200034,
11
+ "dtype": "bfloat16",
12
+ "eos_token_id": 200020,
13
+ "head_dim": 32,
14
+ "hidden_act": "silu",
15
+ "hidden_size": 8,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 32,
18
+ "max_position_embeddings": 196608,
19
+ "mlp_intermediate_size": 32,
20
+ "model_type": "minimax_m2",
21
+ "mtp_transformer_layers": 1,
22
+ "num_attention_heads": 8,
23
+ "num_experts_per_tok": 8,
24
+ "num_hidden_layers": 2,
25
+ "num_key_value_heads": 4,
26
+ "num_local_experts": 256,
27
+ "num_mtp_modules": 3,
28
+ "output_router_logits": false,
29
+ "pad_token_id": null,
30
+ "qk_norm_type": "per_layer",
31
+ "rms_norm_eps": 1e-06,
32
+ "rope_parameters": {
33
+ "rope_theta": 5000000,
34
+ "rope_type": "default"
35
+ },
36
+ "rotary_dim": 16,
37
+ "router_aux_loss_coef": 0.001,
38
+ "router_jitter_noise": 0.0,
39
+ "scoring_func": "sigmoid",
40
+ "shared_intermediate_size": 0,
41
+ "tie_word_embeddings": false,
42
+ "transformers_version": "5.5.0",
43
+ "use_cache": true,
44
+ "use_mtp": true,
45
+ "use_qk_norm": true,
46
+ "use_routing_bias": true,
47
+ "vocab_size": 200064
48
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 200019,
3
+ "do_sample": true,
4
+ "eos_token_id": 200020,
5
+ "temperature": 1.0,
6
+ "top_k": 40,
7
+ "top_p": 0.95,
8
+ "transformers_version": "5.5.0",
9
+ "trust_remote_code": true
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f279f05fbc6f7d57725c55179104dd39c644b1c16db6e020617c5cf0755537b
3
+ size 7420752
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b81e5e5cba2b169e86a0771825a927e9d41b4c4484ded4a286410f41f702f17
3
+ size 15523144
tokenizer_config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": "]~!b[",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "[e~[",
7
+ "extra_special_tokens": [
8
+ "<code_interpreter>",
9
+ "<commit_after>",
10
+ "<commit_before>",
11
+ "<commit_msg>",
12
+ "<empty_output>",
13
+ "<filename>",
14
+ "<fim_middle>",
15
+ "<fim_pad>",
16
+ "<fim_prefix>",
17
+ "<fim_suffix>",
18
+ "<function_call>",
19
+ "<gh_stars>",
20
+ "]<]speech[>[",
21
+ "]<]image[>[",
22
+ "]<]video[>[",
23
+ "]<]start of speech[>[",
24
+ "]<]end of speech[>[",
25
+ "]<]start of image[>[",
26
+ "]<]end of image[>[",
27
+ "]<]start of video[>[",
28
+ "]<]end of video[>[",
29
+ "]<]vision pad[>[",
30
+ "]~!b[",
31
+ "<issue_closed>",
32
+ "<issue_comment>",
33
+ "<issue_start>",
34
+ "<jupyter_code>",
35
+ "<jupyter_output>",
36
+ "<jupyter_start>",
37
+ "<jupyter_text>",
38
+ "<reponame>",
39
+ "[e~[",
40
+ "]!d~[",
41
+ "]!p~[",
42
+ "]~b]",
43
+ "<jupyter_error>",
44
+ "<add_file>",
45
+ "<delete_file>",
46
+ "<rename_file>",
47
+ "<edit_file>",
48
+ "<commit_message>",
49
+ "<empty_source_file>",
50
+ "<repo_struct>",
51
+ "<code_context>",
52
+ "<file_content>",
53
+ "<source_files>",
54
+ "<pr_start>",
55
+ "<review_comment>",
56
+ "<filepath>",
57
+ "<file_sep>"
58
+ ],
59
+ "is_local": false,
60
+ "model_max_length": 40960000,
61
+ "tokenizer_class": "TokenizersBackend",
62
+ "unk_token": "]!d~["
63
+ }