yujiepan commited on
Commit
401a310
·
verified ·
1 Parent(s): d3418a3

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
README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: text-generation
4
+ inference: true
5
+ widget:
6
+ - text: Hello!
7
+ example_title: Hello world
8
+ group: Python
9
+ ---
10
+
11
+ This tiny model is for debugging. It is randomly initialized with the config adapted from [MiniMaxAI/MiniMax-M1-80k](https://huggingface.co/MiniMaxAI/MiniMax-M1-80k).
12
+
13
+ ### Example usage:
14
+
15
+ ```python
16
+ import torch
17
+
18
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
19
+
20
+ model_id = "yujiepan/minimax-m1-tiny-random"
21
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
22
+ model = AutoModelForCausalLM.from_pretrained(
23
+ model_id,
24
+ torch_dtype=torch.bfloat16,
25
+ trust_remote_code=True,
26
+ )
27
+ pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, trust_remote_code=True)
28
+ print(pipe('Write an article about Artificial Intelligence.'))
29
+ ```
30
+
31
+ ### Codes to create this repo:
32
+
33
+ ```python
34
+ import json
35
+ from pathlib import Path
36
+
37
+ import torch
38
+
39
+ import accelerate
40
+ from huggingface_hub import file_exists, hf_hub_download
41
+ from transformers import (
42
+ AutoConfig,
43
+ AutoModelForCausalLM,
44
+ AutoTokenizer,
45
+ GenerationConfig,
46
+ set_seed,
47
+ )
48
+
49
+ source_model_id = "MiniMaxAI/MiniMax-M1-80k"
50
+ save_folder = "/tmp/yujiepan/minimax-m1-tiny-random"
51
+
52
+ processor = AutoTokenizer.from_pretrained(source_model_id)
53
+ processor.save_pretrained(save_folder)
54
+
55
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
56
+ config_json = json.load(f)
57
+
58
+ config_json["attn_type_list"] = [0, 1] # one lightning, one attention
59
+ for k, v in config_json['auto_map'].items():
60
+ config_json['auto_map'][k] = f'{source_model_id}--{v}'
61
+ config_json['head_dim'] = 32
62
+ config_json['hidden_size'] = 64
63
+ config_json['intermediate_size'] = 128
64
+ config_json['num_attention_heads'] = 2
65
+ config_json['num_experts_per_tok'] = 2
66
+ config_json['num_hidden_layers'] = 2
67
+ config_json['num_key_value_heads'] = 1
68
+ config_json['num_local_experts'] = 8
69
+ config_json['rotary_dim'] = 16
70
+ config_json['tie_word_embeddings'] = True
71
+
72
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
73
+ json.dump(config_json, f, indent=2)
74
+
75
+ config = AutoConfig.from_pretrained(
76
+ save_folder,
77
+ trust_remote_code=True,
78
+ )
79
+ print(config)
80
+ automap = config_json['auto_map']
81
+ torch.set_default_dtype(torch.bfloat16)
82
+ model = AutoModelForCausalLM.from_config(config, trust_remote_code=True)
83
+ torch.set_default_dtype(torch.float32)
84
+
85
+ if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'):
86
+ model.generation_config = GenerationConfig.from_pretrained(
87
+ source_model_id, trust_remote_code=True,
88
+ )
89
+ set_seed(42)
90
+ model = model.cpu() # cpu is more stable for random initialization across machines
91
+ with torch.no_grad():
92
+ for name, p in sorted(model.named_parameters()):
93
+ torch.nn.init.normal_(p, 0, 0.2)
94
+ print(name, p.shape)
95
+ model.save_pretrained(save_folder)
96
+ print(model)
97
+ with open(f"{save_folder}/config.json", "r", encoding='utf-8') as f:
98
+ config_json = json.load(f)
99
+ config_json['auto_map'] = automap
100
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
101
+ json.dump(config_json, f, indent=2)
102
+ for python_file in Path(save_folder).glob('*.py'):
103
+ python_file.unlink()
104
+ ```
added_tokens.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "<begin_of_document>": 200034,
3
+ "<beginning_of_sentence>": 200019,
4
+ "<code_interpreter>": 200023,
5
+ "<commit_after>": 200018,
6
+ "<commit_before>": 200016,
7
+ "<commit_msg>": 200017,
8
+ "<empty_output>": 200015,
9
+ "<end_of_document>": 200021,
10
+ "<end_of_image>": 200030,
11
+ "<end_of_sentence>": 200020,
12
+ "<end_of_speech>": 200028,
13
+ "<end_of_video>": 200032,
14
+ "<filename>": 200006,
15
+ "<fim_middle>": 200002,
16
+ "<fim_pad>": 200004,
17
+ "<fim_prefix>": 200001,
18
+ "<fim_suffix>": 200003,
19
+ "<function_call>": 200022,
20
+ "<gh_stars>": 200007,
21
+ "<image>": 200025,
22
+ "<issue_closed>": 200010,
23
+ "<issue_comment>": 200009,
24
+ "<issue_start>": 200008,
25
+ "<jupyter_code>": 200013,
26
+ "<jupyter_error>": 200035,
27
+ "<jupyter_output>": 200014,
28
+ "<jupyter_start>": 200011,
29
+ "<jupyter_text>": 200012,
30
+ "<pad>": 200000,
31
+ "<reponame>": 200005,
32
+ "<speech>": 200024,
33
+ "<start_of_image>": 200029,
34
+ "<start_of_speech>": 200027,
35
+ "<start_of_video>": 200031,
36
+ "<video>": 200026,
37
+ "<vision_pad>": 200033
38
+ }
config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MiniMaxM1ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "attn_type_list": [
7
+ 0,
8
+ 1
9
+ ],
10
+ "auto_map": {
11
+ "AutoConfig": "MiniMaxAI/MiniMax-M1-80k--configuration_minimax_m1.MiniMaxM1Config",
12
+ "AutoModelForCausalLM": "MiniMaxAI/MiniMax-M1-80k--modeling_minimax_m1.MiniMaxM1ForCausalLM"
13
+ },
14
+ "head_dim": 32,
15
+ "hidden_act": "silu",
16
+ "hidden_size": 64,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 128,
19
+ "layernorm_full_attention_alpha": 3.5565588200778455,
20
+ "layernorm_full_attention_beta": 1.0,
21
+ "layernorm_linear_attention_alpha": 3.5565588200778455,
22
+ "layernorm_linear_attention_beta": 1.0,
23
+ "layernorm_mlp_alpha": 3.5565588200778455,
24
+ "layernorm_mlp_beta": 1.0,
25
+ "max_position_embeddings": 10240000,
26
+ "model_type": "MiniMaxM1",
27
+ "num_attention_heads": 2,
28
+ "num_experts_per_tok": 2,
29
+ "num_hidden_layers": 2,
30
+ "num_key_value_heads": 1,
31
+ "num_local_experts": 8,
32
+ "output_router_logits": false,
33
+ "postnorm": true,
34
+ "rms_norm_eps": 1e-05,
35
+ "rope_theta": 10000000,
36
+ "rotary_dim": 16,
37
+ "router_aux_loss_coef": 0.001,
38
+ "router_jitter_noise": 0.0,
39
+ "shared_intermediate_size": 0,
40
+ "shared_moe_mode": "sigmoid",
41
+ "sliding_window": null,
42
+ "tie_word_embeddings": true,
43
+ "torch_dtype": "bfloat16",
44
+ "transformers_version": "4.51.3",
45
+ "use_cache": true,
46
+ "vocab_size": 200064
47
+ }
generation_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "transformers_version": "4.51.3"
4
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6581a14a0cd32f179fec72b1066e97d80ea5ee170199d4ea5de11725807b1fa
3
+ size 26470640
special_tokens_map.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<beginning_of_sentence>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<end_of_sentence>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "unk_token": {
17
+ "content": "<end_of_document>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a158429317db5b1720d40da8c461142444eb5098a4e1a1182dbd9f50bc32da6
3
+ size 15519354
tokenizer_config.json ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "200000": {
5
+ "content": "<pad>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "200001": {
13
+ "content": "<fim_prefix>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "200002": {
21
+ "content": "<fim_middle>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "200003": {
29
+ "content": "<fim_suffix>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "200004": {
37
+ "content": "<fim_pad>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "200005": {
45
+ "content": "<reponame>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "200006": {
53
+ "content": "<filename>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "200007": {
61
+ "content": "<gh_stars>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "200008": {
69
+ "content": "<issue_start>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "200009": {
77
+ "content": "<issue_comment>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "200010": {
85
+ "content": "<issue_closed>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "200011": {
93
+ "content": "<jupyter_start>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "200012": {
101
+ "content": "<jupyter_text>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "200013": {
109
+ "content": "<jupyter_code>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "200014": {
117
+ "content": "<jupyter_output>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": true
123
+ },
124
+ "200015": {
125
+ "content": "<empty_output>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": true
131
+ },
132
+ "200016": {
133
+ "content": "<commit_before>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": true
139
+ },
140
+ "200017": {
141
+ "content": "<commit_msg>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": true
147
+ },
148
+ "200018": {
149
+ "content": "<commit_after>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": true
155
+ },
156
+ "200019": {
157
+ "content": "<beginning_of_sentence>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": true
163
+ },
164
+ "200020": {
165
+ "content": "<end_of_sentence>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": true
171
+ },
172
+ "200021": {
173
+ "content": "<end_of_document>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": true
179
+ },
180
+ "200022": {
181
+ "content": "<function_call>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": true
187
+ },
188
+ "200023": {
189
+ "content": "<code_interpreter>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": true
195
+ },
196
+ "200024": {
197
+ "content": "<speech>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": true
203
+ },
204
+ "200025": {
205
+ "content": "<image>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": true
211
+ },
212
+ "200026": {
213
+ "content": "<video>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "200027": {
221
+ "content": "<start_of_speech>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "200028": {
229
+ "content": "<end_of_speech>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "200029": {
237
+ "content": "<start_of_image>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "200030": {
245
+ "content": "<end_of_image>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "200031": {
253
+ "content": "<start_of_video>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "200032": {
261
+ "content": "<end_of_video>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ },
268
+ "200033": {
269
+ "content": "<vision_pad>",
270
+ "lstrip": false,
271
+ "normalized": false,
272
+ "rstrip": false,
273
+ "single_word": false,
274
+ "special": true
275
+ },
276
+ "200034": {
277
+ "content": "<begin_of_document>",
278
+ "lstrip": false,
279
+ "normalized": false,
280
+ "rstrip": false,
281
+ "single_word": false,
282
+ "special": true
283
+ },
284
+ "200035": {
285
+ "content": "<jupyter_error>",
286
+ "lstrip": false,
287
+ "normalized": false,
288
+ "rstrip": false,
289
+ "single_word": false,
290
+ "special": true
291
+ }
292
+ },
293
+ "bos_token": "<beginning_of_sentence>",
294
+ "chat_template": "{{ '<begin_of_document>' -}}{% set ns = namespace(system_prompt='') -%}{% for message in messages -%}{% if message['role'] == 'system' -%}{% set ns.system_prompt = ns.system_prompt + message['content'][0]['text'] -%}{% endif -%}{%- endfor -%}{% if ns.system_prompt != '' -%}{{ '<beginning_of_sentence>system ai_setting=assistant\n' + ns.system_prompt + '<end_of_sentence>\n' -}}{%- endif -%}{% if tools -%}{{ '<beginning_of_sentence>system tool_setting=tools\nYou are provided with these tools:\n<tools>\n' -}}{% for tool in tools -%}{{ tool | tojson ~ '\n' -}}{%- endfor -%}{{ '</tools>\n\nIf you need to call tools, please respond with <tool_calls></tool_calls> XML tags, and provide tool-name and json-object of arguments, following the format below:\n<tool_calls>\n{''name'': <tool-name-1>, ''arguments'': <args-json-object-1>}\n...\n</tool_calls><end_of_sentence>\n' -}}{%- endif -%}{% for message in messages -%}{% if message['role'] == 'user' -%}{{ '<beginning_of_sentence>user name=user\n' + message['content'][0]['text'] + '<end_of_sentence>\n' -}}{% elif message['role'] == 'assistant' -%}{{ '<beginning_of_sentence>ai name=assistant\n' -}}{% for content in message['content'] | selectattr('type', 'equalto', 'text') -%}{{ content['text'] -}}{%- endfor -%}{{ '<end_of_sentence>\n' -}}{% elif message['role'] == 'tool' -%}{{ '<beginning_of_sentence>tool name=tools\n' }} {%- for content in message['content'] -%}{{- 'tool name: ' + content['name'] + '\n' + 'tool result: ' + content['text'] + '\n\n' -}} {%- endfor -%}{{- '<end_of_sentence>\n' -}}{% endif -%}{%- endfor -%}{% if add_generation_prompt -%}{{ '<beginning_of_sentence>ai name=assistant\n' -}}{%- endif -%}",
295
+ "clean_up_tokenization_spaces": false,
296
+ "eos_token": "<end_of_sentence>",
297
+ "extra_special_tokens": {},
298
+ "model_max_length": 40960000,
299
+ "tokenizer_class": "GPT2Tokenizer",
300
+ "unk_token": "<end_of_document>"
301
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff