AlazarM commited on
Commit
600ffd6
·
verified ·
1 Parent(s): 55cfbb6

Add files using upload-large-folder tool

Browse files
README.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - zh
5
+ license: mit
6
+ library_name: mlx
7
+ tags:
8
+ - mlx
9
+ - longcat
10
+ - lsa
11
+ - moe
12
+ - ngram-embedding
13
+ base_model: meituan-longcat/LongCat-Flash-Lite-Sparse
14
+ pipeline_tag: text-generation
15
+ ---
16
+
17
+ # LongCat-Flash-Lite-Sparse-8bit (MLX)
18
+
19
+ 8-bit MLX quantization of [meituan-longcat/LongCat-Flash-Lite-Sparse](https://huggingface.co/meituan-longcat/LongCat-Flash-Lite-Sparse) (69B-A3B, `LongcatCausalLM`).
20
+
21
+ To our knowledge this is the **first working implementation of LongCat-Flash-Lite-Sparse in any framework** — no upstream serving stack (mlx-lm, vLLM, SGLang, llama.cpp) supports the `oe_embed_*` variant yet.
22
+
23
+ Near-lossless 8-bit (~68 GB of weights), for a 128 GB Mac. Smaller-footprint variants: [6-bit](https://huggingface.co/AlazarM/LongCat-Flash-Lite-Sparse-6bit) (~54 GB, 96 GB Macs) and [4-bit](https://huggingface.co/AlazarM/LongCat-Flash-Lite-Sparse-4bit) (~36 GB, 64 GB Macs).
24
+
25
+ ## What's in this checkpoint
26
+ LongCat-Flash-Lite-Sparse adds three things vanilla LongCat-Flash lacks:
27
+ - **LongCat Sparse Attention (LSA)** — a DeepSeek-style lightning indexer over MLA, with streaming-aware indexing (fixed sink + local window) and cross-layer index reuse. Native long context.
28
+ - **Zero-computation (identity) experts** in the ScMoE decoder (256 routed + 128 identity, top-12).
29
+ - **N-gram ("oe") input embedding** — ~46% of the parameters, fused into the token embedding.
30
+
31
+ ## The n-gram fix
32
+ The `oe` embedding hash and tables are identical to the published n-gram references (the *Scaling Embeddings* paper, mlx-lm, SGLang, llama.cpp, Meituan's dense modeling). The one difference in `LongcatCausalLM` is the **fusion**: it keeps the word embedding at **full scale** —
33
+ `word + Σ projections / (1 + num_embedders)` — rather than the dense form `(word + Σ projections) / (1 + num_embedders)`. Dividing the word by `1 + num_embedders` garbles generation; this build applies the correct fusion.
34
+
35
+ ## Usage
36
+ Requires mlx-vlm with `longcat_flash_sparse` support ([PR #2063](https://github.com/Blaizzy/mlx-vlm/pull/2063)):
37
+
38
+ ```bash
39
+ pip install git+https://github.com/Lazarus-931/mlx-vlm@add-longcat-flash
40
+ ```
41
+ ```python
42
+ from mlx_vlm import load, generate
43
+ model, processor = load("AlazarM/LongCat-Flash-Lite-Sparse-8bit", trust_remote_code=True)
44
+ tok = processor.tokenizer
45
+ text = tok.apply_chat_template(
46
+ [{"role": "user", "content": "What is the capital of France?"}],
47
+ tokenize=False, add_generation_prompt=True,
48
+ )
49
+ print(generate(model, processor, text, max_tokens=64, temperature=0.0))
50
+ # -> The capital of France is Paris.
51
+ ```
52
+
53
+ ## Throughput (M5 Max, 128 GB, batch 1, greedy)
54
+
55
+ Decode tok/s across the published quantizations:
56
+
57
+ | ctx | 4-bit | 6-bit | 8-bit |
58
+ |--:|--:|--:|--:|
59
+ | 512 | 112 | 87 | 80 |
60
+ | 2048 | 85 | 72 | 65 |
61
+ | 8192 | 83 | 71 | 65 |
62
+ | 32768 | 73 | 64 | 60 |
63
+
64
+ Batch-1 decode is partly weight-bandwidth-bound, so **lower precision is faster** (~30% spread 4→8-bit); LSA keeps all three nearly flat as context grows. Peak memory across 512→32k: 4-bit ~39–45 GB, 6-bit ~56–63 GB, **8-bit ~74–80 GB**. The extra precision trades speed + memory for quality — since only ~3B params are active per token, quant error has little room to hide, so the 8-bit quality gain is meaningful.
65
+
66
+ ## License
67
+ MIT, inherited from the base model.
chat_template.jinja ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set tool_choice = tool_choice | default('auto') -%}
2
+ {%- set enable_thinking = enable_thinking | default(none) -%}
3
+ {%- set save_history_reasoning_content = save_history_reasoning_content | default(false) -%}
4
+ {%- set ns = namespace(final_messages = [], tool_types = [], last_query_index = -1) -%}
5
+ {%- for message in messages -%}
6
+ {%- set role = message.get('role') -%}
7
+ {%- set c = message.get('content') -%}
8
+ {%- if c is string -%}
9
+ {%- set ns.final_messages = ns.final_messages + [message] -%}
10
+ {%- elif c is iterable and c is not mapping -%}
11
+ {%- set parts = namespace(text=[], thinking=[], tool_calls=[], tool_results=[]) -%}
12
+ {%- for item in c -%}
13
+ {%- if item['type'] == 'text' -%}
14
+ {%- set parts.text = parts.text + [item['text']] -%}
15
+ {%- elif item['type'] == 'thinking' -%}
16
+ {%- if item['thinking'] -%}
17
+ {%- set parts.thinking = parts.thinking + [item['thinking']] -%}
18
+ {%- endif -%}
19
+ {%- elif item['type'] == 'tool_use' -%}
20
+ {%- set parts.tool_calls = parts.tool_calls + [{
21
+ 'id': item['id'],
22
+ 'type': 'function',
23
+ 'function': {
24
+ 'name': item['name'],
25
+ 'arguments': item['input']
26
+ }
27
+ }] -%}
28
+ {%- elif item['type'] == 'tool_result' -%}
29
+ {%- set parts.tool_results = parts.tool_results + [{
30
+ 'role': 'tool',
31
+ 'name': item.get('name', ''),
32
+ 'tool_call_id': item['tool_use_id'],
33
+ 'content': item['content']
34
+ }] -%}
35
+ {%- endif -%}
36
+ {%- endfor -%}
37
+ {%- set ns.final_messages = ns.final_messages + parts.tool_results -%}
38
+ {%- if not (parts.tool_results | length > 0 and parts.text | length == 0 and role == 'user') -%}
39
+ {%- set ns.final_messages = ns.final_messages + [{
40
+ 'role': role,
41
+ 'content': parts.text | join(''),
42
+ 'reasoning_content': parts.thinking | join(''),
43
+ 'tool_calls': parts.tool_calls
44
+ }] -%}
45
+ {%- endif -%}
46
+ {%- else -%}
47
+ {%- set ns.final_messages = ns.final_messages + [message] -%}
48
+ {%- endif -%}
49
+ {%- endfor -%}
50
+ {%- set messages = ns.final_messages -%}
51
+
52
+ {%- for idx in range(messages|length) -%}
53
+ {%- set msg = messages[idx] -%}
54
+ {%- if msg.role == 'user' -%}
55
+ {%- set ns.last_query_index = idx -%}
56
+ {%- endif -%}
57
+ {%- endfor -%}
58
+
59
+ {%- if tools and tool_choice != 'none' -%}
60
+ {{- "<longcat_tool_declare>\n" -}}
61
+ {{- "# Tools\n" -}}
62
+ {{- "You have access to the following tools:\n\n" -}}
63
+ {%- for tool in tools -%}
64
+ {%- if tool.type not in ns.tool_types -%}
65
+ {%- set ns.tool_types = ns.tool_types + [tool.type] -%}
66
+ {{- "## Tool namespace: " ~ tool.type ~ "\n\n" -}}
67
+ {%- endif -%}
68
+ {%- if tool.type == 'code_interpreter' -%}
69
+ {%- 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.\nCode sandbox environment (network isolated) Any external network requests or online API calls are prohibited.\nIf online functionality is needed, please use other permitted tools.\nCode 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:\n- Importing network libraries such as requests, httplib, etc.\n- Any form of HTTP requests.\n- External API calls.\n- Network port operations. Example: ```python\nimport pandas as pd\npd.DataFrame({'A':[1,2]})\n```"},"timeout":{"type":"number","description":"The maximum execution time of the code, in seconds. Default is 60.0."}}},"required":["code"]}} -%}
70
+ {%- endif -%}
71
+ {{- "### Tool name: " + tool.function.name + "\n" -}}
72
+ {{- "Description: " + tool.function.description + "\n\n" -}}
73
+ {{- "InputSchema: " + tool.function.parameters | tojson(ensure_ascii=False) + "\n\n" -}}
74
+ {%- endfor -%}
75
+ {{- '**Note**: For each function call, output the function name and arguments within the following XML format:\n<longcat_tool_call>{function-name}\n<longcat_arg_key>{arg-key-1}</longcat_arg_key>\n<longcat_arg_value>{arg-value-1}</longcat_arg_value>\n<longcat_arg_key>{arg-key-2}</longcat_arg_key>\n<longcat_arg_value>{arg-value-2}</longcat_arg_value>\n...\n</longcat_tool_call>\n' -}}
76
+ {{- "</longcat_tool_declare>"-}}
77
+ {%- endif -%}
78
+
79
+ {%- for msg in messages -%}
80
+ {%- if msg.role == "system" -%}
81
+ {{- "<longcat_system>" + msg.content -}}
82
+ {%- elif msg.role == "user" -%}
83
+ {{- "<longcat_user>" -}}
84
+ {%- if msg["files"] -%}
85
+ {{- '<longcat_files>\n' ~ msg.files | tojson(indent=2) ~ '\n</longcat_files>' -}}
86
+ {%- endif -%}
87
+ {{- msg.content -}}
88
+ {%- if save_history_reasoning_content and enable_thinking is not none -%}
89
+ {%- if loop.last or messages[loop.index0 + 1].role != 'assistant' -%}
90
+ {# pass #}
91
+ {%- else -%}
92
+ {%- if enable_thinking == true -%}
93
+ {{- " /think_on" -}}
94
+ {%- if thinking_budget -%}
95
+ {%- if thinking_budget < 1024 -%}
96
+ {%- set thinking_budget = 1024 -%}
97
+ {%- endif -%}
98
+ {{- "\nthinking_budget: < " ~ thinking_budget ~ "." -}}
99
+ {%- endif -%}
100
+ {{- " " -}}
101
+ {%- elif enable_thinking == false -%}
102
+ {{- " /think_off " -}}
103
+ {%- endif -%}
104
+ {%- endif -%}
105
+ {%- elif loop.index0 >= ns.last_query_index and enable_thinking is not none -%}
106
+ {%- if loop.last or messages[loop.index0 + 1].role != 'assistant' -%}
107
+ {# pass #}
108
+ {%- else -%}
109
+ {%- if enable_thinking == true -%}
110
+ {{- " /think_on" -}}
111
+ {%- if thinking_budget -%}
112
+ {%- if thinking_budget < 1024 -%}
113
+ {%- set thinking_budget = 1024 -%}
114
+ {%- endif -%}
115
+ {{- "\nthinking_budget: < " ~ thinking_budget ~ "." -}}
116
+ {%- endif -%}
117
+ {{- " " -}}
118
+ {%- elif enable_thinking == false -%}
119
+ {{- " /think_off " -}}
120
+ {%- endif -%}
121
+ {%- endif -%}
122
+ {%- endif -%}
123
+ {%- elif msg.role == "assistant" -%}
124
+ {{- "<longcat_assistant>" -}}
125
+ {%- if save_history_reasoning_content == true or loop.index0 > ns.last_query_index -%}
126
+ {%- if enable_thinking == true -%}
127
+ {%- if msg.reasoning_content -%}
128
+ {%- set reasoning_content = msg.reasoning_content | trim -%}
129
+ {{- "<longcat_think>\n" ~ reasoning_content ~ "\n</longcat_think>\n" -}}
130
+ {%- else -%}
131
+ {{- "<longcat_think>\n\n</longcat_think>\n" -}}
132
+ {%- endif -%}
133
+ {%- elif enable_thinking == false -%}
134
+ {{- "<longcat_think>\n\n</longcat_think>\n" -}}
135
+ {%- endif -%}
136
+ {%- endif -%}
137
+ {%- if msg.content -%}
138
+ {{- msg.content -}}
139
+ {%- endif -%}
140
+ {%- if msg.tool_calls -%}
141
+ {%- for tool_call in msg.tool_calls -%}
142
+ {{- "<longcat_tool_call>" ~ tool_call.function.name ~ "\n" -}}
143
+ {%- set _args = tool_call.function.arguments -%}
144
+ {%- for k, v in _args.items() -%}
145
+ {{- "<longcat_arg_key>" ~ k ~ "</longcat_arg_key>\n" -}}
146
+ {{- "<longcat_arg_value>" ~ (v if v is string else v | tojson(ensure_ascii=False)) ~ "</longcat_arg_value>\n" -}}
147
+ {% endfor -%}
148
+ {{- "</longcat_tool_call>\n" -}}
149
+ {%- endfor -%}
150
+ {%- endif -%}
151
+ {{- "</longcat_s>" -}}
152
+ {%- elif msg.role == "tool" -%}
153
+ {%- if messages[loop.index0 - 1].role != "tool" -%}
154
+ {{- "<longcat_observation>" -}}
155
+ {%- endif -%}
156
+ {{- "<longcat_tool_response>" ~ msg.name ~ "\n" ~ msg.content ~ "</longcat_tool_response>" -}}
157
+ {%- if loop.index0 == messages|length - 1 -%}
158
+ {# pass #}
159
+ {%- elif (save_history_reasoning_content or loop.index0 > ns.last_query_index) and messages[loop.index0 + 1].role != "tool" -%}
160
+ {%- if enable_thinking == true -%}
161
+ {{- " /think_on" -}}
162
+ {%- if thinking_budget -%}
163
+ {%- if thinking_budget < 1024 -%}
164
+ {%- set thinking_budget = 1024 -%}
165
+ {%- endif -%}
166
+ {{- "\nthinking_budget: < " ~ thinking_budget ~ "." -}}
167
+ {%- endif -%}
168
+ {{- " " -}}
169
+ {%- elif enable_thinking == false -%}
170
+ {{- " /think_off " -}}
171
+ {%- endif -%}
172
+ {%- endif -%}
173
+ {%- endif -%}
174
+ {%- endfor -%}
175
+ {%- if add_generation_prompt -%}
176
+ {%- if enable_thinking == true -%}
177
+ {{- " /think_on" -}}
178
+ {%- if thinking_budget -%}
179
+ {%- if thinking_budget < 1024 -%}
180
+ {%- set thinking_budget = 1024 -%}
181
+ {%- endif -%}
182
+ {{- "\nthinking_budget: < " ~ thinking_budget ~ "." -}}
183
+ {%- endif -%}
184
+ {{- " <longcat_assistant><longcat_think>\n" -}}
185
+ {%- elif enable_thinking == false -%}
186
+ {{- " /think_off <longcat_assistant><longcat_think>\n\n</longcat_think>\n" -}}
187
+ {%- else -%}
188
+ {{- "<longcat_assistant>" -}}
189
+ {%- endif -%}
190
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LongcatCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "attention_method": "LSA",
8
+ "bos_token_id": 1,
9
+ "cli_factor": 2,
10
+ "dsa_mtp_cli": true,
11
+ "eos_token_id": 2,
12
+ "expert_ffn_hidden_size": 1024,
13
+ "ffn_hidden_size": 6144,
14
+ "generation_config": {
15
+ "_from_model_config": true,
16
+ "bos_token_id": 1,
17
+ "eos_token_id": 2,
18
+ "pad_token_id": 3,
19
+ "transformers_version": "4.57.6",
20
+ "repetition_penalty": 1.06,
21
+ "temperature": 0.7,
22
+ "top_p": 0.95,
23
+ "top_k": 4
24
+ },
25
+ "hidden_size": 3072,
26
+ "index_head_dim": 128,
27
+ "index_init_tokens": 16,
28
+ "index_k_norm_type": "rms",
29
+ "index_local_tokens": 1024,
30
+ "index_n_heads": 16,
31
+ "index_topk": 2048,
32
+ "indexer_rope_interleave": true,
33
+ "kv_lora_rank": 512,
34
+ "max_position_embeddings": 983040,
35
+ "mla_scale_kv_lora": true,
36
+ "mla_scale_q_lora": true,
37
+ "model_type": "longcat_flash_sparse",
38
+ "moe_impl": "mix",
39
+ "moe_switch_token_num": 1024,
40
+ "moe_topk": 12,
41
+ "mtp_disable_over_tokenizer": false,
42
+ "mtp_num_layers": 3,
43
+ "mtp_replicate_modules": true,
44
+ "n_routed_experts": 256,
45
+ "num_attention_heads": 32,
46
+ "num_layers": 14,
47
+ "oe_neighbor_num": 4,
48
+ "oe_split_num": 4,
49
+ "oe_vocab_size_ratio": 78,
50
+ "q_lora_rank": 1536,
51
+ "qk_nope_head_dim": 128,
52
+ "qk_rope_head_dim": 64,
53
+ "quantization": {
54
+ "group_size": 64,
55
+ "bits": 8,
56
+ "mode": "affine",
57
+ "language_model.model.layers.0.mlp.router.classifier": {
58
+ "group_size": 64,
59
+ "bits": 8
60
+ },
61
+ "language_model.model.layers.1.mlp.router.classifier": {
62
+ "group_size": 64,
63
+ "bits": 8
64
+ },
65
+ "language_model.model.layers.2.mlp.router.classifier": {
66
+ "group_size": 64,
67
+ "bits": 8
68
+ },
69
+ "language_model.model.layers.3.mlp.router.classifier": {
70
+ "group_size": 64,
71
+ "bits": 8
72
+ },
73
+ "language_model.model.layers.4.mlp.router.classifier": {
74
+ "group_size": 64,
75
+ "bits": 8
76
+ },
77
+ "language_model.model.layers.5.mlp.router.classifier": {
78
+ "group_size": 64,
79
+ "bits": 8
80
+ },
81
+ "language_model.model.layers.6.mlp.router.classifier": {
82
+ "group_size": 64,
83
+ "bits": 8
84
+ },
85
+ "language_model.model.layers.7.mlp.router.classifier": {
86
+ "group_size": 64,
87
+ "bits": 8
88
+ },
89
+ "language_model.model.layers.8.mlp.router.classifier": {
90
+ "group_size": 64,
91
+ "bits": 8
92
+ },
93
+ "language_model.model.layers.9.mlp.router.classifier": {
94
+ "group_size": 64,
95
+ "bits": 8
96
+ },
97
+ "language_model.model.layers.10.mlp.router.classifier": {
98
+ "group_size": 64,
99
+ "bits": 8
100
+ },
101
+ "language_model.model.layers.11.mlp.router.classifier": {
102
+ "group_size": 64,
103
+ "bits": 8
104
+ },
105
+ "language_model.model.layers.12.mlp.router.classifier": {
106
+ "group_size": 64,
107
+ "bits": 8
108
+ },
109
+ "language_model.model.layers.13.mlp.router.classifier": {
110
+ "group_size": 64,
111
+ "bits": 8
112
+ }
113
+ },
114
+ "quantization_config": {
115
+ "group_size": 64,
116
+ "bits": 8,
117
+ "mode": "affine",
118
+ "language_model.model.layers.0.mlp.router.classifier": {
119
+ "group_size": 64,
120
+ "bits": 8
121
+ },
122
+ "language_model.model.layers.1.mlp.router.classifier": {
123
+ "group_size": 64,
124
+ "bits": 8
125
+ },
126
+ "language_model.model.layers.2.mlp.router.classifier": {
127
+ "group_size": 64,
128
+ "bits": 8
129
+ },
130
+ "language_model.model.layers.3.mlp.router.classifier": {
131
+ "group_size": 64,
132
+ "bits": 8
133
+ },
134
+ "language_model.model.layers.4.mlp.router.classifier": {
135
+ "group_size": 64,
136
+ "bits": 8
137
+ },
138
+ "language_model.model.layers.5.mlp.router.classifier": {
139
+ "group_size": 64,
140
+ "bits": 8
141
+ },
142
+ "language_model.model.layers.6.mlp.router.classifier": {
143
+ "group_size": 64,
144
+ "bits": 8
145
+ },
146
+ "language_model.model.layers.7.mlp.router.classifier": {
147
+ "group_size": 64,
148
+ "bits": 8
149
+ },
150
+ "language_model.model.layers.8.mlp.router.classifier": {
151
+ "group_size": 64,
152
+ "bits": 8
153
+ },
154
+ "language_model.model.layers.9.mlp.router.classifier": {
155
+ "group_size": 64,
156
+ "bits": 8
157
+ },
158
+ "language_model.model.layers.10.mlp.router.classifier": {
159
+ "group_size": 64,
160
+ "bits": 8
161
+ },
162
+ "language_model.model.layers.11.mlp.router.classifier": {
163
+ "group_size": 64,
164
+ "bits": 8
165
+ },
166
+ "language_model.model.layers.12.mlp.router.classifier": {
167
+ "group_size": 64,
168
+ "bits": 8
169
+ },
170
+ "language_model.model.layers.13.mlp.router.classifier": {
171
+ "group_size": 64,
172
+ "bits": 8
173
+ }
174
+ },
175
+ "rms_norm_eps": 1e-05,
176
+ "rope_scaling": {
177
+ "original_max_position_embeddings": 8192,
178
+ "rope_type": "deepseek_yarn",
179
+ "factor": 120,
180
+ "beta_fast": 32,
181
+ "beta_slow": 1,
182
+ "mscale": 1,
183
+ "mscale_all_dim": 1
184
+ },
185
+ "rope_theta": 1000000.0,
186
+ "routed_scaling_factor": 6.0,
187
+ "temperature": 0.7,
188
+ "top_k": 4,
189
+ "top_p": 0.95,
190
+ "use_cache": true,
191
+ "use_mla": 1,
192
+ "v_head_dim": 128,
193
+ "vision_config": {},
194
+ "vocab_size": 131072,
195
+ "zero_expert_num": 128,
196
+ "zero_expert_type": "identity"
197
+ }
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
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.57.6",
7
+ "repetition_penalty": 1.06,
8
+ "temperature": 0.7,
9
+ "top_p": 0.95,
10
+ "top_k": 4
11
+ }
model-00001-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6a343d0047046cdbb03c1d779d10b49c85eb52a4bc0302458c6bde09038a6dc
3
+ size 3208643681
model-00002-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5c0a3b1b208a99440969a993d570a7916fbfda6d96793f4781004e9132941b53
3
+ size 2780824802
model-00003-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeada7fcf13d66d4d303e434337604f36b5ad6802ad479d08668ece7b8f0d446
3
+ size 2780825346
model-00004-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29578fbf63cdcff4a4ab9e1327cabf32ebcf616a6243880d6e1eaf7b8124245a
3
+ size 2780825890
model-00005-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f58ede6880737af017bcfd456030793da6070475257abbcbfec3a75d5be79b9d
3
+ size 2780826434
model-00006-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce1161958a228e540c7ac6eed6f349136d5a3ca83f4a0ebdae4152b09e8bcec6
3
+ size 2780826978
model-00007-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ab17461f949447a6d9fd4d09c96df31dadd5ec155a7474d838d21f9438bae96
3
+ size 2780827522
model-00008-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3f6129301d095ffd73dc3573a0d5af3bb54f25953ef7de4354f594a0abf8ec6
3
+ size 2780828066
model-00009-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:396248bf557e54b10c70ff744e273a10eafd2482835772b76631e957a0164089
3
+ size 2780828610
model-00010-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cd922dbeb21af6b059ec4621c02f4a6be5fa3961885ee44f2faeb97663ec957
3
+ size 2780829154
model-00011-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:864b136931e791b33cb09b20ca7661a2cdd0637c40fdfc136c953241f5d67472
3
+ size 2780829701
model-00012-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9252f6da8f9c9a63d0f148e5c4c20b55eea1048d3e9319d7c4f88c9afd48c82b
3
+ size 5364119198
model-00013-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c255f50854f488f9e2de1a8bcc00a6bde69bcc4e9bd0a88f8d9336a9a016a402
3
+ size 4661854142
model-00014-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b36eb64bdc93a2526c8ee67581e4639462413968fdc0e03d7eb8dc9762f3d19
3
+ size 4668200376
model-00015-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47bb2631f1f97b73a5798664f0ff060e78347309636ba5b64508d7d8668875b0
3
+ size 4668200318
model-00016-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65ff208951585f0a49b7bacfd60d40b9322ddf9d45e6a0882ab048c727fe035e
3
+ size 5368678359
model-00017-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c50b3b144b76adacc1154b9585316d5f708a9390447b6c3bb874a984cb12210
3
+ size 4628356804
model-00018-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:758b864faa7956b3c8c3f7a467e1c2ac7f25afc11ed08bff536f151263ad1d96
3
+ size 4668200492
model-00019-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6cbfbb9ff731af32d6bf4cb4c183badff2c094fbd630e19acdcbb5b52808be5
3
+ size 4668200495
model-00020-of-00020.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1a872f9e0be3b3ee9d4336baefa02f6d3e93489b944d8f79b9d800a27e94910
3
+ size 3189745038
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<longcat_s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</longcat_s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<longcat_pad>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<longcat_unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenization_llama.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+
21
+ """Tokenization classes for LLaMA."""
22
+ import os
23
+ from shutil import copyfile
24
+ from typing import Any, Dict, List, Optional, Tuple
25
+
26
+ import sentencepiece as spm
27
+
28
+ from transformers.tokenization_utils import PreTrainedTokenizer
29
+ from transformers.utils import logging
30
+
31
+
32
+ logger = logging.get_logger(__name__)
33
+
34
+ VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
35
+
36
+ PRETRAINED_VOCAB_FILES_MAP = {}
37
+
38
+
39
+ class LlamaTokenizer(PreTrainedTokenizer):
40
+ """
41
+ Construct a Llama tokenizer. Based on byte-level Byte-Pair-Encoding.
42
+
43
+ Args:
44
+ vocab_file (`str`):
45
+ Path to the vocabulary file.
46
+ """
47
+
48
+ vocab_files_names = VOCAB_FILES_NAMES
49
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
50
+ model_input_names = ["input_ids", "attention_mask"]
51
+
52
+ def __init__(
53
+ self,
54
+ vocab_file,
55
+ unk_token="<unk>",
56
+ bos_token="<s>",
57
+ eos_token="</s>",
58
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
59
+ add_bos_token=True,
60
+ add_eos_token=False,
61
+ decode_with_prefix_space=False,
62
+ **kwargs,
63
+ ):
64
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
65
+ super().__init__(bos_token=bos_token, eos_token=eos_token, unk_token=unk_token, **kwargs)
66
+ self.vocab_file = vocab_file
67
+ self.add_bos_token = add_bos_token
68
+ self.add_eos_token = add_eos_token
69
+ self.decode_with_prefix_space = decode_with_prefix_space
70
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
71
+ self.sp_model.Load(vocab_file)
72
+ self._no_prefix_space_tokens = None
73
+
74
+ """ Initialisation"""
75
+
76
+ @property
77
+ def no_prefix_space_tokens(self):
78
+ if self._no_prefix_space_tokens is None:
79
+ vocab = self.convert_ids_to_tokens(list(range(self.vocab_size)))
80
+ self._no_prefix_space_tokens = {i for i, tok in enumerate(vocab) if not tok.startswith("▁")}
81
+ return self._no_prefix_space_tokens
82
+
83
+ @property
84
+ def vocab_size(self):
85
+ """Returns vocab size"""
86
+ return self.sp_model.get_piece_size()
87
+
88
+ @property
89
+ def bos_token_id(self) -> Optional[int]:
90
+ return self.sp_model.bos_id()
91
+
92
+ @property
93
+ def eos_token_id(self) -> Optional[int]:
94
+ return self.sp_model.eos_id()
95
+
96
+ def get_vocab(self):
97
+ """Returns vocab as a dict"""
98
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
99
+ vocab.update(self.added_tokens_encoder)
100
+ return vocab
101
+
102
+ def _tokenize(self, text):
103
+ """Returns a tokenized string."""
104
+ return self.sp_model.encode(text, out_type=str)
105
+
106
+ def _convert_token_to_id(self, token):
107
+ """Converts a token (str) in an id using the vocab."""
108
+ return self.sp_model.piece_to_id(token)
109
+
110
+ def _convert_id_to_token(self, index):
111
+ """Converts an index (integer) in a token (str) using the vocab."""
112
+ token = self.sp_model.IdToPiece(index)
113
+ return token
114
+
115
+ def _maybe_add_prefix_space(self, tokens, decoded):
116
+ if tokens and tokens[0] not in self.no_prefix_space_tokens:
117
+ return " " + decoded
118
+ else:
119
+ return decoded
120
+
121
+ def convert_tokens_to_string(self, tokens):
122
+ """Converts a sequence of tokens (string) in a single string."""
123
+ current_sub_tokens = []
124
+ out_string = ""
125
+ prev_is_special = False
126
+ for token in tokens:
127
+ # make sure that special tokens are not decoded using sentencepiece model
128
+ if token in self.all_special_tokens:
129
+ if not prev_is_special:
130
+ out_string += " "
131
+ out_string += self.sp_model.decode(current_sub_tokens) + token
132
+ prev_is_special = True
133
+ current_sub_tokens = []
134
+ else:
135
+ current_sub_tokens.append(token)
136
+ prev_is_special = False
137
+ out_string += self.sp_model.decode(current_sub_tokens)
138
+ out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string)
139
+ return out_string
140
+
141
+ def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
142
+ """
143
+ Save the vocabulary and special tokens file to a directory.
144
+
145
+ Args:
146
+ save_directory (`str`):
147
+ The directory in which to save the vocabulary.
148
+
149
+ Returns:
150
+ `Tuple(str)`: Paths to the files saved.
151
+ """
152
+ if not os.path.isdir(save_directory):
153
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
154
+ return
155
+ out_vocab_file = os.path.join(
156
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
157
+ )
158
+
159
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
160
+ copyfile(self.vocab_file, out_vocab_file)
161
+ elif not os.path.isfile(self.vocab_file):
162
+ with open(out_vocab_file, "wb") as fi:
163
+ content_spiece_model = self.sp_model.serialized_model_proto()
164
+ fi.write(content_spiece_model)
165
+
166
+ return (out_vocab_file,)
167
+
168
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
169
+ if self.add_bos_token:
170
+ bos_token_ids = [self.bos_token_id]
171
+ else:
172
+ bos_token_ids = []
173
+
174
+ output = bos_token_ids + token_ids_0
175
+
176
+ if token_ids_1 is not None:
177
+ output = output + token_ids_1
178
+
179
+ if self.add_eos_token:
180
+ output = output + [self.eos_token_id]
181
+
182
+ return output
183
+
184
+ def get_special_tokens_mask(
185
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
186
+ ) -> List[int]:
187
+ """
188
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
189
+ special tokens using the tokenizer `prepare_for_model` method.
190
+
191
+ Args:
192
+ token_ids_0 (`List[int]`):
193
+ List of IDs.
194
+ token_ids_1 (`List[int]`, *optional*):
195
+ Optional second list of IDs for sequence pairs.
196
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
197
+ Whether or not the token list is already formatted with special tokens for the model.
198
+
199
+ Returns:
200
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
201
+ """
202
+ if already_has_special_tokens:
203
+ return super().get_special_tokens_mask(
204
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
205
+ )
206
+
207
+ if token_ids_1 is None:
208
+ return [1] + ([0] * len(token_ids_0)) + [1]
209
+ return [1] + ([0] * len(token_ids_0)) + [1, 1] + ([0] * len(token_ids_1)) + [1]
210
+
211
+ def create_token_type_ids_from_sequences(
212
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
213
+ ) -> List[int]:
214
+ """
215
+ Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make
216
+ use of token type ids, therefore a list of zeros is returned.
217
+
218
+ Args:
219
+ token_ids_0 (`List[int]`):
220
+ List of IDs.
221
+ token_ids_1 (`List[int]`, *optional*):
222
+ Optional second list of IDs for sequence pairs.
223
+
224
+ Returns:
225
+ `List[int]`: List of zeros.
226
+ """
227
+ eos = [self.eos_token_id]
228
+
229
+ if token_ids_1 is None:
230
+ return len(token_ids_0 + eos) * [0]
231
+ return len(token_ids_0 + eos + token_ids_1 + eos) * [0]
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<longcat_s>",
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "</longcat_s>",
7
+ "is_local": true,
8
+ "local_files_only": false,
9
+ "model_max_length": 131072,
10
+ "pad_token": "<longcat_pad>",
11
+ "sp_model_kwargs": {},
12
+ "tokenizer_class": "TokenizersBackend",
13
+ "unk_token": "<longcat_unk>"
14
+ }