finding1 commited on
Commit
945f767
·
verified ·
1 Parent(s): de04534

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .DS_Store +0 -0
  2. README.md +17 -0
  3. chat_template.jinja +138 -0
  4. config.json +272 -0
  5. configuration_longcat_flash.py +216 -0
  6. generation_config.json +7 -0
  7. model-00001-of-00085.safetensors +3 -0
  8. model-00002-of-00085.safetensors +3 -0
  9. model-00003-of-00085.safetensors +3 -0
  10. model-00004-of-00085.safetensors +3 -0
  11. model-00005-of-00085.safetensors +3 -0
  12. model-00006-of-00085.safetensors +3 -0
  13. model-00007-of-00085.safetensors +3 -0
  14. model-00008-of-00085.safetensors +3 -0
  15. model-00009-of-00085.safetensors +3 -0
  16. model-00010-of-00085.safetensors +3 -0
  17. model-00011-of-00085.safetensors +3 -0
  18. model-00012-of-00085.safetensors +3 -0
  19. model-00013-of-00085.safetensors +3 -0
  20. model-00014-of-00085.safetensors +3 -0
  21. model-00015-of-00085.safetensors +3 -0
  22. model-00016-of-00085.safetensors +3 -0
  23. model-00017-of-00085.safetensors +3 -0
  24. model-00018-of-00085.safetensors +3 -0
  25. model-00019-of-00085.safetensors +3 -0
  26. model-00020-of-00085.safetensors +3 -0
  27. model-00021-of-00085.safetensors +3 -0
  28. model-00022-of-00085.safetensors +3 -0
  29. model-00023-of-00085.safetensors +3 -0
  30. model-00024-of-00085.safetensors +3 -0
  31. model-00025-of-00085.safetensors +3 -0
  32. model-00026-of-00085.safetensors +3 -0
  33. model-00027-of-00085.safetensors +3 -0
  34. model-00028-of-00085.safetensors +3 -0
  35. model-00029-of-00085.safetensors +3 -0
  36. model-00030-of-00085.safetensors +3 -0
  37. model-00031-of-00085.safetensors +3 -0
  38. model-00032-of-00085.safetensors +3 -0
  39. model-00033-of-00085.safetensors +3 -0
  40. model-00034-of-00085.safetensors +3 -0
  41. model-00035-of-00085.safetensors +3 -0
  42. model-00036-of-00085.safetensors +3 -0
  43. model-00037-of-00085.safetensors +3 -0
  44. model-00038-of-00085.safetensors +3 -0
  45. model-00039-of-00085.safetensors +3 -0
  46. model-00040-of-00085.safetensors +3 -0
  47. model-00041-of-00085.safetensors +3 -0
  48. model-00042-of-00085.safetensors +3 -0
  49. model-00043-of-00085.safetensors +3 -0
  50. model-00044-of-00085.safetensors +3 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
README.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: mlx
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - transformers
7
+ - mlx
8
+ base_model: meituan-longcat/LongCat-Flash-Chat
9
+ ---
10
+
11
+ This model [finding1/LongCat-Flash-Chat-MLX-5.5bpw](https://huggingface.co/finding1/LongCat-Flash-Chat-MLX-5.5bpw) was
12
+ converted to MLX format from [meituan-longcat/LongCat-Flash-Chat](https://huggingface.co/meituan-longcat/LongCat-Flash-Chat)
13
+ using mlx-lm version **0.27.1** by running
14
+ `mlx_lm.convert --quantize --q-bits 5 --mlx-path MLX-8.5bpw --hf-path meituan-longcat/LongCat-Flash-Chat`
15
+ until it crashed with a `KeyError`;
16
+ [adding `"model_type": "longcat_flash",` to the downloaded `config.json`](https://github.com/ml-explore/mlx-lm/issues/433#issuecomment-3262138687),
17
+ then running the command again.
chat_template.jinja ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set tool_choice = tool_choice | default('auto') %}
2
+ {%- set ns = namespace(rounds = 0, tool_types = [], last_query_index = -1) %}
3
+
4
+ {%- if tools and tool_choice != 'none' %}
5
+ {{- "# Tools
6
+ " }}
7
+ {{- "You have access to the following tools:
8
+
9
+ " }}
10
+ {%- for tool in tools %}
11
+ {%- if tool.type in ['code_interpreter', 'function'] %}
12
+ {%- if tool.type not in ns.tool_types %}
13
+ {%- set ns.tool_types = ns.tool_types + [tool.type] %}
14
+ {{- "## Tool namespace: " ~ tool.type ~ "
15
+
16
+ " }}
17
+ {%- endif %}
18
+ {%- if tool.type == 'code_interpreter' %}
19
+ {%- set tool = {"type":"code_interpreter","function":{"name":"code_interpreter_preview","description":"The code will be executed in a stateful Jupyter notebook sandbox environment, only supports local computation, data processing, and file operations.
20
+ Code sandbox environment (network isolated) Any external network requests or online API calls are prohibited.
21
+ If online functionality is needed, please use other permitted tools.
22
+ Code will respond with the output of the execution or time out after 60.0 seconds. ","parameters":{"type":"object","properties":{"language":{"type":"string","description":"The programming language of the code to be executed. Available values: python (Default), java, go, js, ts, c, c++."},"code":{"type":"string","description":"Python code to be executed must not include the following:
23
+ - Importing network libraries such as requests, httplib, etc.
24
+ - Any form of HTTP requests.
25
+ - External API calls.
26
+ - Network port operations. Example: ```python
27
+ import pandas as pd
28
+ pd.DataFrame({'A':[1,2]})
29
+ ```"},"timeout":{"type":"number","description":"The maximum execution time of the code, in seconds. Default is 60.0."}}},"required":["code"]}} %}
30
+ {%- endif %}
31
+ {{- "### Tool name: " + tool.function.name + "
32
+
33
+ " }}
34
+ {{- "Description: " + tool.function.description + "
35
+
36
+ " }}
37
+ {{- "InputSchema:
38
+ " + tool.function.parameters | tojson(indent=2) + "
39
+
40
+ " }}
41
+ {%- endif %}
42
+ {%- endfor %}
43
+ {{- '**Note**: For each function call, return a json object with function name and arguments within <longcat_tool_call></longcat_tool_call> XML tags as follows:
44
+ <longcat_tool_call>
45
+ {"name": <function-name>, "arguments": <args-dict>}
46
+ </longcat_tool_call>
47
+ ' }}
48
+ {{- 'When multiple functions need to be called simultaneously, each function call should be wrapped in its own <longcat_tool_call> tag and placed consecutively. For example:
49
+ <longcat_tool_call>
50
+ {"name": <function-name>, "arguments": <args-dict>}
51
+ </longcat_tool_call><longcat_tool_call>
52
+ {"name": <function-name>, "arguments": <args-dict>}
53
+ </longcat_tool_call>
54
+
55
+ ' }}
56
+ {{- "# Messages
57
+ " }}
58
+
59
+ {%- for idx in range(messages|length - 1) %}
60
+ {%- set msg = messages[idx] %}
61
+ {%- if msg.role == 'assistant' and not msg.tool_calls %}
62
+ {%- set ns.last_query_index = idx %}
63
+ {%- endif %}
64
+ {%- endfor%}
65
+ {%- endif %}
66
+
67
+ {%- for msg in messages %}
68
+ {%- if msg.role == "system" %}
69
+ {{- "SYSTEM:" + msg.content }}
70
+ {%- elif msg.role == "user" %}
71
+ {%- if loop.first %}
72
+ {{- "[Round " ~ (ns.rounds) ~ "] USER:" }}
73
+ {%- else %}
74
+ {{- " [Round " ~ (ns.rounds) ~ "] USER:"}}
75
+ {%- endif %}
76
+ {%- set ns.rounds = ns.rounds + 1 %}
77
+ {%- if msg["files"] %}
78
+ {{- '<longcat_files>
79
+ ' ~ msg.files | tojson(indent=2) ~ '
80
+ </longcat_files>' }}
81
+ {%- endif %}
82
+ {{- msg.content }}
83
+ {%- elif msg.role == "assistant" %}
84
+ {{- " ASSISTANT:" }}
85
+ {%- if enable_thinking == true and msg.reasoning_content and ns.tool_types != [] and loop.index0 > ns.last_query_index %}
86
+ {{- "
87
+ <longcat_think>
88
+ " ~ msg.reasoning_content ~ "
89
+ </longcat_think>
90
+ " }}
91
+ {%- endif %}
92
+ {%- if msg.content%}
93
+ {{- msg.content }}
94
+ {%- endif %}
95
+ {%- if msg.tool_calls %}
96
+ {%- for tool_call in msg.tool_calls -%}
97
+ {{- "<longcat_tool_call>
98
+ " -}}
99
+ {%- if tool_call.function.arguments is string -%}
100
+ {"name": "{{ tool_call.function.name}}", "arguments": {{tool_call.function.arguments}}}
101
+ {%- else -%}
102
+ {"name": "{{ tool_call.function.name}}", "arguments": {{tool_call.function.arguments | tojson}}}
103
+ {%- endif -%}
104
+ {{- "
105
+ </longcat_tool_call>" }}
106
+ {%- endfor %}
107
+ {%- endif %}
108
+ {{- "</longcat_s>" -}}
109
+ {%- elif msg.role == "tool" %}
110
+ {{- " TOOL:" -}}
111
+ {%- if msg.name -%}
112
+ {"name": {{msg.name | tojson}}, "content": {{msg.content | tojson}}}
113
+ {%- else -%}
114
+ {"content": {{msg.content | tojson}}}
115
+ {%- endif -%}
116
+ {%- endif %}
117
+ {%- endfor %}
118
+ {%- if add_generation_prompt %}
119
+ {%- if enable_thinking == true %}
120
+ {{- " /think_on" }}
121
+ {%- if thinking_budget %}
122
+ {%- if thinking_budget < 1024 %}
123
+ {%- set thinking_budget = 1024 %}
124
+ {%- endif%}
125
+ {{- "
126
+ thinking_budget: < " ~ thinking_budget ~ "."}}
127
+ {%- endif %}
128
+ {{- " ASSISTANT:<longcat_think>
129
+ "}}
130
+ {%- elif enable_thinking == false %}
131
+ {{- " /think_off ASSISTANT:<longcat_think>
132
+
133
+ </longcat_think>
134
+ " }}
135
+ {%- else %}
136
+ {{- " ASSISTANT:" }}
137
+ {%- endif %}
138
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LongcatFlashForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "attention_method": "MLA",
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_longcat_flash.LongcatFlashConfig",
10
+ "AutoModel": "modeling_longcat_flash.LongcatFlashModel",
11
+ "AutoModelForCausalLM": "modeling_longcat_flash.LongcatFlashForCausalLM"
12
+ },
13
+ "bos_token_id": 1,
14
+ "eos_token_id": 2,
15
+ "expert_ffn_hidden_size": 2048,
16
+ "ffn_hidden_size": 12288,
17
+ "hidden_size": 6144,
18
+ "kv_lora_rank": 512,
19
+ "max_position_embeddings": 131072,
20
+ "mla_scale_kv_lora": true,
21
+ "mla_scale_q_lora": true,
22
+ "model_type": "longcat_flash",
23
+ "moe_topk": 12,
24
+ "n_routed_experts": 512,
25
+ "num_attention_heads": 64,
26
+ "num_layers": 28,
27
+ "q_lora_rank": 1536,
28
+ "qk_nope_head_dim": 128,
29
+ "qk_rope_head_dim": 64,
30
+ "quantization": {
31
+ "group_size": 64,
32
+ "bits": 5,
33
+ "mode": "affine",
34
+ "model.layers.0.mlp.router.classifier": {
35
+ "group_size": 64,
36
+ "bits": 8
37
+ },
38
+ "model.layers.1.mlp.router.classifier": {
39
+ "group_size": 64,
40
+ "bits": 8
41
+ },
42
+ "model.layers.2.mlp.router.classifier": {
43
+ "group_size": 64,
44
+ "bits": 8
45
+ },
46
+ "model.layers.3.mlp.router.classifier": {
47
+ "group_size": 64,
48
+ "bits": 8
49
+ },
50
+ "model.layers.4.mlp.router.classifier": {
51
+ "group_size": 64,
52
+ "bits": 8
53
+ },
54
+ "model.layers.5.mlp.router.classifier": {
55
+ "group_size": 64,
56
+ "bits": 8
57
+ },
58
+ "model.layers.6.mlp.router.classifier": {
59
+ "group_size": 64,
60
+ "bits": 8
61
+ },
62
+ "model.layers.7.mlp.router.classifier": {
63
+ "group_size": 64,
64
+ "bits": 8
65
+ },
66
+ "model.layers.8.mlp.router.classifier": {
67
+ "group_size": 64,
68
+ "bits": 8
69
+ },
70
+ "model.layers.9.mlp.router.classifier": {
71
+ "group_size": 64,
72
+ "bits": 8
73
+ },
74
+ "model.layers.10.mlp.router.classifier": {
75
+ "group_size": 64,
76
+ "bits": 8
77
+ },
78
+ "model.layers.11.mlp.router.classifier": {
79
+ "group_size": 64,
80
+ "bits": 8
81
+ },
82
+ "model.layers.12.mlp.router.classifier": {
83
+ "group_size": 64,
84
+ "bits": 8
85
+ },
86
+ "model.layers.13.mlp.router.classifier": {
87
+ "group_size": 64,
88
+ "bits": 8
89
+ },
90
+ "model.layers.14.mlp.router.classifier": {
91
+ "group_size": 64,
92
+ "bits": 8
93
+ },
94
+ "model.layers.15.mlp.router.classifier": {
95
+ "group_size": 64,
96
+ "bits": 8
97
+ },
98
+ "model.layers.16.mlp.router.classifier": {
99
+ "group_size": 64,
100
+ "bits": 8
101
+ },
102
+ "model.layers.17.mlp.router.classifier": {
103
+ "group_size": 64,
104
+ "bits": 8
105
+ },
106
+ "model.layers.18.mlp.router.classifier": {
107
+ "group_size": 64,
108
+ "bits": 8
109
+ },
110
+ "model.layers.19.mlp.router.classifier": {
111
+ "group_size": 64,
112
+ "bits": 8
113
+ },
114
+ "model.layers.20.mlp.router.classifier": {
115
+ "group_size": 64,
116
+ "bits": 8
117
+ },
118
+ "model.layers.21.mlp.router.classifier": {
119
+ "group_size": 64,
120
+ "bits": 8
121
+ },
122
+ "model.layers.22.mlp.router.classifier": {
123
+ "group_size": 64,
124
+ "bits": 8
125
+ },
126
+ "model.layers.23.mlp.router.classifier": {
127
+ "group_size": 64,
128
+ "bits": 8
129
+ },
130
+ "model.layers.24.mlp.router.classifier": {
131
+ "group_size": 64,
132
+ "bits": 8
133
+ },
134
+ "model.layers.25.mlp.router.classifier": {
135
+ "group_size": 64,
136
+ "bits": 8
137
+ },
138
+ "model.layers.26.mlp.router.classifier": {
139
+ "group_size": 64,
140
+ "bits": 8
141
+ },
142
+ "model.layers.27.mlp.router.classifier": {
143
+ "group_size": 64,
144
+ "bits": 8
145
+ }
146
+ },
147
+ "quantization_config": {
148
+ "group_size": 64,
149
+ "bits": 5,
150
+ "mode": "affine",
151
+ "model.layers.0.mlp.router.classifier": {
152
+ "group_size": 64,
153
+ "bits": 8
154
+ },
155
+ "model.layers.1.mlp.router.classifier": {
156
+ "group_size": 64,
157
+ "bits": 8
158
+ },
159
+ "model.layers.2.mlp.router.classifier": {
160
+ "group_size": 64,
161
+ "bits": 8
162
+ },
163
+ "model.layers.3.mlp.router.classifier": {
164
+ "group_size": 64,
165
+ "bits": 8
166
+ },
167
+ "model.layers.4.mlp.router.classifier": {
168
+ "group_size": 64,
169
+ "bits": 8
170
+ },
171
+ "model.layers.5.mlp.router.classifier": {
172
+ "group_size": 64,
173
+ "bits": 8
174
+ },
175
+ "model.layers.6.mlp.router.classifier": {
176
+ "group_size": 64,
177
+ "bits": 8
178
+ },
179
+ "model.layers.7.mlp.router.classifier": {
180
+ "group_size": 64,
181
+ "bits": 8
182
+ },
183
+ "model.layers.8.mlp.router.classifier": {
184
+ "group_size": 64,
185
+ "bits": 8
186
+ },
187
+ "model.layers.9.mlp.router.classifier": {
188
+ "group_size": 64,
189
+ "bits": 8
190
+ },
191
+ "model.layers.10.mlp.router.classifier": {
192
+ "group_size": 64,
193
+ "bits": 8
194
+ },
195
+ "model.layers.11.mlp.router.classifier": {
196
+ "group_size": 64,
197
+ "bits": 8
198
+ },
199
+ "model.layers.12.mlp.router.classifier": {
200
+ "group_size": 64,
201
+ "bits": 8
202
+ },
203
+ "model.layers.13.mlp.router.classifier": {
204
+ "group_size": 64,
205
+ "bits": 8
206
+ },
207
+ "model.layers.14.mlp.router.classifier": {
208
+ "group_size": 64,
209
+ "bits": 8
210
+ },
211
+ "model.layers.15.mlp.router.classifier": {
212
+ "group_size": 64,
213
+ "bits": 8
214
+ },
215
+ "model.layers.16.mlp.router.classifier": {
216
+ "group_size": 64,
217
+ "bits": 8
218
+ },
219
+ "model.layers.17.mlp.router.classifier": {
220
+ "group_size": 64,
221
+ "bits": 8
222
+ },
223
+ "model.layers.18.mlp.router.classifier": {
224
+ "group_size": 64,
225
+ "bits": 8
226
+ },
227
+ "model.layers.19.mlp.router.classifier": {
228
+ "group_size": 64,
229
+ "bits": 8
230
+ },
231
+ "model.layers.20.mlp.router.classifier": {
232
+ "group_size": 64,
233
+ "bits": 8
234
+ },
235
+ "model.layers.21.mlp.router.classifier": {
236
+ "group_size": 64,
237
+ "bits": 8
238
+ },
239
+ "model.layers.22.mlp.router.classifier": {
240
+ "group_size": 64,
241
+ "bits": 8
242
+ },
243
+ "model.layers.23.mlp.router.classifier": {
244
+ "group_size": 64,
245
+ "bits": 8
246
+ },
247
+ "model.layers.24.mlp.router.classifier": {
248
+ "group_size": 64,
249
+ "bits": 8
250
+ },
251
+ "model.layers.25.mlp.router.classifier": {
252
+ "group_size": 64,
253
+ "bits": 8
254
+ },
255
+ "model.layers.26.mlp.router.classifier": {
256
+ "group_size": 64,
257
+ "bits": 8
258
+ },
259
+ "model.layers.27.mlp.router.classifier": {
260
+ "group_size": 64,
261
+ "bits": 8
262
+ }
263
+ },
264
+ "rms_norm_eps": 1e-05,
265
+ "rope_theta": 10000000.0,
266
+ "routed_scaling_factor": 6.0,
267
+ "use_cache": true,
268
+ "v_head_dim": 128,
269
+ "vocab_size": 131072,
270
+ "zero_expert_num": 256,
271
+ "zero_expert_type": "identity"
272
+ }
configuration_longcat_flash.py ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """LongcatFlash model configuration"""
3
+
4
+ from transformers.configuration_utils import PretrainedConfig
5
+ from transformers.modeling_rope_utils import rope_config_validation
6
+
7
+
8
+ LONGCAT_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
9
+
10
+
11
+ class LongcatFlashConfig(PretrainedConfig):
12
+ r"""
13
+ This is the configuration class to store the configuration of a [`LongcatFlashModel`]. It is used to instantiate an LongcatFlash
14
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
15
+ defaults will yield a similar configuration to that of the LongcatFlash.
16
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
17
+ documentation from [`PretrainedConfig`] for more information.
18
+
19
+
20
+ Args:
21
+ vocab_size (`int`, *optional*, defaults to 131072):
22
+ Vocabulary size of the Deep model. Defines the number of different tokens that can be represented by the
23
+ `inputs_ids` passed when calling [`LongcatFlashModel`]
24
+ hidden_size (`int`, *optional*, defaults to 7168):
25
+ Dimension of the hidden representations.
26
+ ffn_hidden_size (`int`, *optional*, defaults to 18432):
27
+ Dimension of the MLP representations.
28
+ expert_ffn_hidden_size (`int`, *optional*, defaults to 2048):
29
+ Dimension of the MoE representations.
30
+ num_layers (`int`, *optional*, defaults to 61):
31
+ Number of hidden layers in the Transformer decoder.
32
+ num_attention_heads (`int`, *optional*, defaults to 128):
33
+ Number of attention heads for each attention layer in the Transformer decoder.
34
+ num_key_value_heads (`int`, *optional*, defaults to 128):
35
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
36
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
37
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
38
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
39
+ by meanpooling all the original heads within that group. For more details checkout [this
40
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
41
+ `num_attention_heads`.
42
+ n_routed_experts (`int`, *optional*, defaults to 256):
43
+ Number of routed experts.
44
+ routed_scaling_factor (`float`, *optional*, defaults to 2.5):
45
+ Scaling factor or routed experts.
46
+ kv_lora_rank (`int`, *optional*, defaults to 512):
47
+ Rank of the LoRA matrices for key and value projections.
48
+ q_lora_rank (`int`, *optional*, defaults to 1536):
49
+ Rank of the LoRA matrices for query projections.
50
+ qk_rope_head_dim (`int`, *optional*, defaults to 64):
51
+ Dimension of the query/key heads that use rotary position embeddings.
52
+ v_head_dim (`int`, *optional*, defaults to 128):
53
+ Dimension of the value heads.
54
+ qk_nope_head_dim (`int`, *optional*, defaults to 128):
55
+ Dimension of the query/key heads that don't use rotary position embeddings.
56
+ norm_topk_prob (`bool`, *optional*, defaults to `True`):
57
+ Whether to normalize the weights of the routed experts.
58
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
59
+ The non-linear activation function (function or string) in the decoder.
60
+ max_position_embeddings (`int`, *optional*, defaults to 4096):
61
+ The maximum sequence length that this model might ever be used with.
62
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
63
+ The epsilon used by the rms normalization layers.
64
+ use_cache (`bool`, *optional*, defaults to `True`):
65
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
66
+ relevant if `config.is_decoder=True`.
67
+ pad_token_id (`int`, *optional*):
68
+ Padding token id.
69
+ bos_token_id (`int`, *optional*, defaults to 0):
70
+ Beginning of stream token id.
71
+ eos_token_id (`int`, *optional*, defaults to 1):
72
+ End of stream token id.
73
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
74
+ Whether to tie weight embeddings
75
+ rope_theta (`float`, *optional*, defaults to 10000.0):
76
+ The base period of the RoPE embeddings.
77
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
78
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
79
+ attention_dropout (`float`, *optional*, defaults to 0.0):
80
+ The dropout ratio for the attention probabilities.
81
+ attention_method (`str`, *optional*, defaults to `"MLA"`):
82
+ The attention method to use.
83
+ initializer_range (`float`, *optional*, defaults to 0.006):
84
+ The initializer range for the model.
85
+ router_bias (`bool`, *optional*, defaults to `False`):
86
+ Whether to use a bias in the router.
87
+ zero_expert_num (`int`, *optional*, defaults to `None`):
88
+ The number of zero experts to use.
89
+ zero_expert_type (`str`, *optional*, defaults to `None`):
90
+ The type of zero expert to use.
91
+
92
+ ```python
93
+ >>> from transformers import LongcatFlashModel, LongcatFlashConfig
94
+
95
+ >>> # Initializing a LongcatFlash style configuration
96
+ >>> configuration = LongcatFlashConfig()
97
+
98
+ >>> # Accessing the model configuration
99
+ >>> configuration = model.config
100
+ ```"""
101
+
102
+ model_type = "longcat_flash"
103
+ keys_to_ignore_at_inference = ["past_key_values"]
104
+ base_model_tp_plan = {
105
+ "layers.*.self_attn.k_proj": "colwise",
106
+ "layers.*.self_attn.v_proj": "colwise",
107
+ "layers.*.self_attn.o_proj": "rowwise",
108
+ "layers.*.mlp.experts.*.gate_proj": "local_colwise",
109
+ "layers.*.mlp.experts.*.up_proj": "local_colwise",
110
+ "layers.*.mlp.experts.*.down_proj": "local_rowwise",
111
+ "layers.*.mlps.*.gate_proj": "local_colwise",
112
+ "layers.*.mlps.*.up_proj": "local_colwise",
113
+ "layers.*.mlps.*.down_proj": "local_rowwise",
114
+ }
115
+ base_model_pp_plan = {
116
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
117
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
118
+ "norm": (["hidden_states"], ["hidden_states"]),
119
+ }
120
+
121
+ def __init__(
122
+ self,
123
+ vocab_size=131072,
124
+ hidden_size=7168,
125
+ ffn_hidden_size=18432,
126
+ expert_ffn_hidden_size=2048,
127
+ num_layers=61,
128
+ num_attention_heads=128,
129
+ num_key_value_heads=None,
130
+ n_routed_experts=256,
131
+ routed_scaling_factor=1,
132
+ kv_lora_rank=512,
133
+ q_lora_rank=1536,
134
+ qk_rope_head_dim=64,
135
+ v_head_dim=128,
136
+ qk_nope_head_dim=128,
137
+ mla_scale_q_lora=True,
138
+ mla_scale_kv_lora=True,
139
+ moe_topk=8,
140
+ norm_topk_prob=False,
141
+ hidden_act="silu",
142
+ max_position_embeddings=4096,
143
+ rms_norm_eps=1e-6,
144
+ use_cache=True,
145
+ pad_token_id=None,
146
+ bos_token_id=0,
147
+ eos_token_id=1,
148
+ tie_word_embeddings=False,
149
+ rope_theta=10000.0,
150
+ attention_bias=False,
151
+ attention_dropout=0.0,
152
+ attention_method='MLA',
153
+ initializer_range=0.006,
154
+ router_bias=False,
155
+ zero_expert_num=None,
156
+ zero_expert_type=None,
157
+ **kwargs,
158
+ ):
159
+ self.vocab_size = vocab_size
160
+ self.max_position_embeddings = max_position_embeddings
161
+ self.hidden_size = hidden_size
162
+ self.ffn_hidden_size = ffn_hidden_size
163
+ self.expert_ffn_hidden_size = expert_ffn_hidden_size
164
+ self.num_layers = num_layers
165
+ self.num_attention_heads = num_attention_heads
166
+ self.n_routed_experts = n_routed_experts
167
+ self.routed_scaling_factor = routed_scaling_factor
168
+ self.kv_lora_rank = kv_lora_rank
169
+ self.q_lora_rank = q_lora_rank
170
+ self.qk_rope_head_dim = qk_rope_head_dim
171
+ self.v_head_dim = v_head_dim
172
+ self.qk_nope_head_dim = qk_nope_head_dim
173
+ self.qk_head_dim = qk_nope_head_dim + qk_rope_head_dim
174
+ self.moe_topk = moe_topk
175
+ self.norm_topk_prob = norm_topk_prob
176
+ self.mla_scale_q_lora = mla_scale_q_lora
177
+ self.mla_scale_kv_lora = mla_scale_kv_lora
178
+ self.attention_method = attention_method
179
+ self.initializer_range = initializer_range
180
+ self.router_bias = router_bias
181
+ self.zero_expert_num = zero_expert_num
182
+ self.zero_expert_type = zero_expert_type
183
+
184
+ if self.attention_method == "MLA":
185
+ self.head_dim = qk_rope_head_dim
186
+ else:
187
+ ValueError('attention_method should be one of ["MLA"]')
188
+
189
+
190
+ if num_key_value_heads is None:
191
+ num_key_value_heads = num_attention_heads
192
+
193
+ self.num_key_value_heads = num_key_value_heads
194
+ self.hidden_act = hidden_act
195
+ self.rms_norm_eps = rms_norm_eps
196
+ self.use_cache = use_cache
197
+ self.rope_theta = rope_theta
198
+ self.attention_bias = attention_bias
199
+ self.attention_dropout = attention_dropout
200
+
201
+ rope_config_validation(self)
202
+
203
+ super().__init__(
204
+ pad_token_id=pad_token_id,
205
+ bos_token_id=bos_token_id,
206
+ eos_token_id=eos_token_id,
207
+ tie_word_embeddings=tie_word_embeddings,
208
+ **kwargs,
209
+ )
210
+
211
+ @property
212
+ def num_hidden_layers(self):
213
+ return self.num_layers
214
+
215
+
216
+ __all__ = ["LongcatFlashConfig"]
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 3,
6
+ "transformers_version": "4.55.0"
7
+ }
model-00001-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:686da8791145ba82cb3e60158eda0f690cb88d7fcc2dd571d5e614baf17e1bc0
3
+ size 4982833873
model-00002-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:972b4be672b881f5172fa546dfbf36dd748228888e146774bfd5e4f89213f633
3
+ size 4429185427
model-00003-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4671be71cb1afbddaa40abe8eb34ed78f80816fc2620445f8939eff017f48cfe
3
+ size 4870523118
model-00004-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ed2285e92b5bda5c005dfa4a5cc8f65d34867852989e3048604c9b43996d78e
3
+ size 4429185433
model-00005-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:add36338563d089251d50f1debf0880d0b702d9451e0ead759158a01614efe61
3
+ size 4429185427
model-00006-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5eb02edd015ead840e64255daf096887116cb73b711f3cc1ba29d2f39ffaa559
3
+ size 4870523134
model-00007-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fa6aaa8e7613d8860a9cf4025fe5bb70493236bad32fe3c23b75872ec9a5f5a
3
+ size 4429185433
model-00008-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e63529f96436a06245bb7850ec63fb6104fd6049767df9228a7dc399866bb8a
3
+ size 4429185427
model-00009-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2afb85377f3d76804626b0afa56f4c4910c05a617ab609f78f45c10632bb9219
3
+ size 4870523102
model-00010-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56408f987c0bab3108f71660c550e2135895c67860e0e9ed012f323f71c8f979
3
+ size 4429185433
model-00011-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d7aaf63fab521c746fa00623592c8d6ee2f3f2e27b9b85be11d2f462a8ea979
3
+ size 4429185427
model-00012-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f3d8f063f7926575f539fe41fffa51d78bee8383d0e326da13f0262b3627782f
3
+ size 4870523134
model-00013-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16514ae49100746e4a2d6d282c323d2068a74d74bfa3e061744f7068f212f2d7
3
+ size 4429185433
model-00014-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f1dbe5dd3e816ad853ef42209e70c93446ebcc8df433e5e3512d48ef4c1b442
3
+ size 4429185427
model-00015-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5def97c2a8dfd370c3fd4ee8810be7d1cc23b13917915c208b548e4c0da44d9a
3
+ size 4870523124
model-00016-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a78e5b9fa0addaa036a181108f924a2ff2d1c21e3d3736c0575fc4ee92ae8611
3
+ size 4429185433
model-00017-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5c8d72dec11b4883213088d13742dd4951f726a4adb92138492d9122be1bb085
3
+ size 4429185427
model-00018-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4319a2152a8adb68f3423b4a472554069ca50eeda40cd1bc97e4055598899741
3
+ size 4870523122
model-00019-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28382f1e42a534dbc208f243374211973293b58d4275e9b6f0bae0c6003dfea3
3
+ size 4429185433
model-00020-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca5c87022a8e4a6b76f66d18525c7ca120691e3f232e57bd27197fbb7c895626
3
+ size 4429185427
model-00021-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f8fcbcbdf91a193309655c664b9b8133ee6bc0a7c95daa0b35ff9ef3e71c630
3
+ size 4870523160
model-00022-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42078c61b5d2171b80c371a3c0121b2f4289185225081a8de20644a9593bc86a
3
+ size 4429185433
model-00023-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:213d1db8a10013b778880d572da09d84f999304d5ce7d7eb6e4ca7e978ab3fc6
3
+ size 4429185427
model-00024-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b65ea40b028ef8dab8e7e6fba7a638c4c2ba2c6bcd93286d505dfcd96d58aeda
3
+ size 4870523130
model-00025-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cc1e71f00377512009fc340f9d9c0410eef34625cc4f0fb1d8d39af995c65301
3
+ size 4429185433
model-00026-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b7e1f46560f71bdb3472120dd69f577bbcba3c457e44005c2293c1e7605a5ad
3
+ size 4429185427
model-00027-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e90b71a80bf35ad2e55d3e1b3441a2a20751b3613bae67554356592cc20acd8
3
+ size 4870523106
model-00028-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ce1381073be1b372b231572527eb4f2fe294b9b97b482797d3a566eb5f76f54
3
+ size 4429185433
model-00029-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:50deb062d16565873202cfb8a0d6a1f819ef8b61d402e16e5d4133acc8e93034
3
+ size 4429185427
model-00030-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce970ed66c8b85af1e1eeba1c1f2145e453b237901f2ab8626aaa241c0148a3f
3
+ size 4870523128
model-00031-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0451132a1783b096076dc8ba51b3e06d18fd9b217842de3e5c5647c11ff0d93b
3
+ size 4429185436
model-00032-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa31062615ef88d7532f3a7342c818946aa26a8c567158c34601dce00dee8c87
3
+ size 4429185430
model-00033-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33b97362bd0cde8d3208bdd2e622d26eb0deb3ffce4582d3d1bac7b88cbdbb06
3
+ size 4870523265
model-00034-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ed91549e70382475f6c1038b6a08e492d6a8c0cae2d64a8aa94af3843390fd3
3
+ size 4429185436
model-00035-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51b21a96df69482c02a42d0a9e632c7cc80d65484d468df8ba37b702c21f434d
3
+ size 4429185430
model-00036-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db282c7c4d5cf4bd5f76bbd45a462118f7977f380cb941a79f63be6d35c6676c
3
+ size 4870523213
model-00037-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e068b3108d11849ab41883beac8b9a5e069648f127975c91809e26da4d3f0bdc
3
+ size 4429185436
model-00038-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a5cf2b9f2642ea63a3ad2531850628f35e98506ee9e6bee489ccf204d6936ce
3
+ size 4429185430
model-00039-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c906905d4337f30f7a6b6d8c82e33369045369a184cda01db2197fdfc9d4347
3
+ size 4870523163
model-00040-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6616f0a433580f12e85f6c24023077b515a6a076b6498060a6073a4e30d7c7f9
3
+ size 4429185436
model-00041-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fdbf5620fb091176a7e0c05d76ca82740a5ceb6b11186a7d0773d0c93dd6a9df
3
+ size 4429185430
model-00042-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:566ff1861cfad6832b702774d381965b3c70d4cdc5554a077085ce10454ede9e
3
+ size 4870523155
model-00043-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e723c92d28145254f3e964be6a60f25fa8eb497e9a02531252c757b3f6fb0a1a
3
+ size 4429185436
model-00044-of-00085.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58fcf48f43ed595d16c0cb932f1c129bed18e2a8bbe3ba9b7e6f72313db8852e
3
+ size 4429185430