catplusplus commited on
Commit
2143e89
·
verified ·
1 Parent(s): bee69e1

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
+ model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NON-COMMERCIAL LICENSE
2
+
3
+ Non-commercial use permitted based on MIT-style terms; commercial use requires prior written authorization.
4
+
5
+ Copyright (c) 2026 MiniMax
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software for non-commercial purposes, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or provide copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ 2. If the Software (or any derivative works thereof) is used for any Commercial Use, you shall prominently display "Built with MiniMax M2.7" on a related website, user interface, blogpost, about page or product documentation.
12
+
13
+ 3. Any Commercial Use of the Software or any derivative work thereof is prohibited without obtaining a separate, prior written authorization from MiniMax. To request such authorization, please contact api@minimax.io with the subject line "M2.7 licensing".
14
+
15
+ 4. "Commercial Use" means any use of the Software or any derivative work thereof that is primarily intended for commercial advantage or monetary compensation, which includes, without limitation: (i) offering products or services to third parties for a fee, which utilize, incorporate, or rely on the Software or its derivatives, (ii) the commercial use of APIs provided by or for the Software or its derivatives, including to support or enable commercial products, services, or operations, whether in a cloud-based, hosted, or other similar environment, and (iii) the deployment or provision of the Software or its derivatives that have been subjected to post-training, fine-tuning, instruction-tuning, or any other form of modification, for any commercial purpose.
16
+
17
+ 5. Permitted Free Uses. The following uses are expressly permitted free of charge: (a) personal use, including self-hosted deployment for coding, development of applications, agents, tools, integrations, research, experimentation, or other personal purposes; (b) use by non-profit organizations, academic institutions, and researchers for non-commercial research or educational purposes; (c) modification of the Software solely for the uses described in (a) or (b) above.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ ## Appendix: Prohibited Uses
22
+
23
+ You agree you will not use, or allow others to use, the Software or any derivatives of the Software to:
24
+
25
+ 1. Generate or disseminate content prohibited by applicable laws or regulations.
26
+ 2. Assist with, engage in or otherwise support any military purpose.
27
+ 3. Exploit, harm, or attempt to exploit or harm minors.
28
+ 4. Generate or disseminate false or misleading information with the intent to cause harm.
29
+ 5. Promote discrimination, hate speech, or harmful behavior against individuals or groups based on race or ethnic origin, religion, disability, age, nationality and national origin, veteran status, sexual orientation, gender or gender identity, caste, immigration status, or any other characteristic that is associated with systemic discrimination or marginalization.
README.md CHANGED
@@ -1,3 +1,229 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: MiniMaxAI/MiniMax-M2.7
3
+ base_model_relation: quantized
4
+ library_name: transformers
5
+ pipeline_tag: text-generation
6
+ license: other
7
+ license_name: minimax-m2.7-license
8
+ license_link: LICENSE
9
+ language:
10
+ - en
11
+ tags:
12
+ - moe
13
+ - mixture-of-experts
14
+ - quantization
15
+ - nvfp4
16
+ - fp4
17
+ - fp8
18
+ - reap
19
+ - pruned
20
+ - minimax
21
+ - minimax-m2
22
+ - blackwell
23
+ - dgx-spark
24
+ - vllm
25
+ ---
26
+
27
+ # MiniMax-M2.7-REAP-172B-A10B-NVFP4
28
+
29
+ This is a my second attempt on this model, which I hope to use as a local coder for long range tasks on an NVIDIA Thor dev kit. I tried to find the best reference sources for calibrated weights and expert pruning and see a significant improvement in chat and coding from the first take. One remaining problem, that could be due to REAP as NVFP4 source seems high quality / has proper KV cache scale, is model getting confused with pathnames, like changing case, dropping path components or inserting spaces. I added the following instructions to Kilo code that fixed these issues:
30
+
31
+ You are an AI coding assistant. Help user write high quality, modular, clean code. Pay special attention to pathnames - make sure you preserve case, do not drop path components or insert spaces and other extra characters.
32
+
33
+ I will now try to use model for real life tasks and monitor for issues correctable or non correctable by prompts. If you prefer a little smaller un-REAPed model that is less likely to have regressions, you can try my [`catplusplus/Qwen3.5-122B-A10B-heretic-v2-NVFP4`](https://huggingface.co/catplusplus/Qwen3.5-122B-A10B-heretic-v2-NVFP4)
34
+
35
+
36
+ A **REAP-pruned** variant of MiniMax-M2.7 with **NVFP4-quantized** expert
37
+ weights and **FP8 KV-cache** scales. The original 256-expert-per-layer MoE
38
+ has been reduced to **192 experts per layer (25% compression)** using the same
39
+ pruning mask as
40
+ [saricles/MiniMax-M2.5-REAP-172B-A10B-NVFP4-GB10](https://huggingface.co/saricles/MiniMax-M2.5-REAP-172B-A10B-NVFP4-GB10).
41
+
42
+ - **NVFP4 weights source**: [`NinjaBoffin/MiniMax-M2.7-NVFP4`](https://huggingface.co/NinjaBoffin/MiniMax-M2.7-NVFP4)
43
+ - **Pruning reference**: [`saricles/MiniMax-M2.7-REAP-172B-A10B-NVFP4-GB10`](https://huggingface.co/saricles/MiniMax-M2.7-REAP-172B-A10B-NVFP4-GB10)
44
+ - **Architecture**: 62 transformer layers, 192 experts/layer, top-8 routing,
45
+ hidden size 3072, 48 attention heads, 8 KV heads
46
+ - **Total parameters**: ~172 B (A10B — ~10 B activated per token)
47
+
48
+ ## Quantization Details
49
+
50
+ | Component | Format | Notes |
51
+ |---|---|---|
52
+ | Expert FFN weights (`w1`/`w2`/`w3`) | **NVFP4** | 4-bit float, group_size=16, per-group + global scales |
53
+ | Attention projections (`q/k/v/o_proj`) | **bfloat16** | Excluded from quantization |
54
+ | Gate weights (`block_sparse_moe.gate`) | **bfloat16** | Excluded from quantization |
55
+ | KV cache | **FP8** | Per-layer `k_scale`/`v_scale` tensors |
56
+
57
+ Each expert stores three scale tensors per weight matrix: `input_scale`
58
+ (per-tensor activation scale), `weight_scale` (per-group weight scale), and
59
+ `weight_scale_2` (global weight scale). The FP8 KV cache uses
60
+ `k_proj.k_scale` and `v_proj.v_scale` which vLLM remaps to its internal
61
+ attention scale slots.
62
+
63
+ ## How This Was Made
64
+
65
+ ### Pruning Mask Extraction
66
+
67
+ The REAP expert pruning removes 64 out of 256 experts per layer (different
68
+ experts per layer — not a uniform pattern). We extracted the pruning mask by
69
+ comparing router matrices between the original 256-expert NVFP4 model and the
70
+ already-pruned 192-expert reference model:
71
+
72
+ 1. **Router comparison**: For each of the 62 layers, the 256-row original
73
+ gate weight matrix is matched against the 192-row pruned gate weight matrix
74
+ using the **Hungarian algorithm on cosine distance**.
75
+
76
+ 2. **Mask generation**: Experts in the original that don't match any row in
77
+ the pruned model are marked as deleted (64 per layer). The per-layer mask
78
+ is saved to [`extras/deleted_experts.json`](extras/deleted_experts.json).
79
+
80
+ 3. **Expert deletion**: The identified experts are removed from all NVFP4 weight
81
+ and scale tensors, gate weights are row-sliced, and remaining experts are
82
+ renumbered 0–191. Asymmetric KV-cache zero-point tensors (`k_bias`/`v_bias`)
83
+ are stripped since vLLM does not use them; the symmetric `k_scale`/`v_scale`
84
+ tensors are preserved.
85
+
86
+ The full script lives at [`extras/delete_experts.py`](extras/delete_experts.py)
87
+ and can also apply a saved mask to any compatible model.
88
+
89
+ ## Usage with vLLM
90
+
91
+ This model requires a vLLM build with NVFP4 and FP8 KV-cache support (Blackwell
92
+ / GB10 or later) and the `minimax_m2` model backend.
93
+
94
+ ```bash
95
+ vllm serve /path/to/MiniMax-M2.7-REAP-172B-A10B-NVFP4 \
96
+ --served-model-name Nikola \
97
+ --port 9000 \
98
+ --enable-auto-tool-choice \
99
+ --tool-call-parser minimax_m2 \
100
+ --reasoning-parser minimax_m2_optthink \
101
+ --reasoning-parser-plugin extras/minimax_m2_optthink_reasoning_parser.py \
102
+ --chat-template extras/chat_template.jinja \
103
+ --enable-prefix-caching \
104
+ --attention-backend FLASHINFER \
105
+ --enable-chunked-prefill \
106
+ --gpu-memory-utilization 0.95 \
107
+ --max-num-seqs 4
108
+ ```
109
+
110
+ See [`extras/inference_minimax.sh`](extras/inference_minimax.sh) for the full
111
+ launch script used on DGX Spark / GB10.
112
+
113
+ ## `extras/` Directory
114
+
115
+ ### [`inference_minimax.sh`](extras/inference_minimax.sh)
116
+
117
+ vLLM server launcher for DGX Spark / GB10. Runs inside a custom
118
+ `unglitched_vllm` container via `dockless`. By default loads the parent model
119
+ directory (where this script lives); pass a path to override:
120
+
121
+ ```bash
122
+ ./extras/inference_minimax.sh # serves ../MiniMax-M2.7-REAP-172B-A10B-NVFP4
123
+ ./extras/inference_minimax.sh /path/to/model # custom path
124
+ ```
125
+
126
+ Notable flags used:
127
+ - `VLLM_USE_FLASHINFER_MOE_FP4=0` — disables FlashInfer MoE FP4 kernel (uses
128
+ the fallback NVFP4 GEMM path which is more stable on GB10)
129
+ - `--async-scheduling --enable-chunked-prefill` — latency-oriented scheduling
130
+ - `--cudagraph-capture-sizes 1 2 4` — captures CUDA graphs for typical batch
131
+ sizes
132
+
133
+ ### [`chat_template.jinja`](extras/chat_template.jinja)
134
+
135
+ Custom Jinja2 chat template that supports **optional chain-of-thought
136
+ reasoning**. Pass `enable_thinking=False` in `chat_template_kwargs` to
137
+ suppress `<think>` blocks:
138
+
139
+ ```python
140
+ # OpenAI client — disable thinking
141
+ client.chat.completions.create(
142
+ model="Nikola",
143
+ messages=[{"role": "user", "content": "..."}],
144
+ extra_body={"chat_template_kwargs": {"enable_thinking": False}},
145
+ )
146
+ ```
147
+
148
+ When `enable_thinking=True` (the default), the model produces a `<think>…</think>`
149
+ block before its answer which the reasoning parser extracts into the
150
+ `reasoning_content` field of the response.
151
+
152
+ ### [`minimax_m2_optthink_reasoning_parser.py`](extras/minimax_m2_optthink_reasoning_parser.py)
153
+
154
+ vLLM reasoning parser registered as `minimax_m2_optthink`. Handles MiniMax
155
+ M2's convention where the model emits only a closing `</think>` token (no
156
+ opening tag) — all content before `</think>` is treated as reasoning and
157
+ placed in `reasoning_content`; everything after is the assistant reply.
158
+
159
+ When `enable_thinking=False` was passed in `chat_template_kwargs`, the parser
160
+ skips extraction entirely so no thinking tokens appear in the output.
161
+
162
+ Load at runtime via `--reasoning-parser-plugin` — **no installation needed**:
163
+
164
+ ```bash
165
+ --reasoning-parser minimax_m2_optthink \
166
+ --reasoning-parser-plugin /path/to/extras/minimax_m2_optthink_reasoning_parser.py
167
+ ```
168
+
169
+ ### [`deleted_experts.json`](extras/deleted_experts.json)
170
+
171
+ Pre-computed pruning mask: a JSON mapping each of the 62 layer indices to the
172
+ list of 64 expert indices (0–255) deleted from that layer. Can be passed
173
+ directly to `delete_experts.py` via `--deleted-experts-file` to skip the
174
+ Hungarian-matching step.
175
+
176
+ ### [`delete_experts.py`](extras/delete_experts.py)
177
+
178
+ Utility script to apply expert deletion to a compatible model. Two modes:
179
+
180
+ **Find pruning mask by comparison then apply:**
181
+ ```bash
182
+ python extras/delete_experts.py \
183
+ /path/to/MiniMax-M2.7-NVFP4 \
184
+ /path/to/output \
185
+ --num-original-experts 256 \
186
+ --num-retained-experts 192 \
187
+ --compare-with /path/to/MiniMax-M2.7-REAP-172B-A10B-NVFP4-GB10 \
188
+ --save-deleted-experts extras/deleted_experts.json
189
+ ```
190
+
191
+ **Apply a saved mask directly:**
192
+ ```bash
193
+ python extras/delete_experts.py \
194
+ /path/to/MiniMax-M2.7-NVFP4 \
195
+ /path/to/output \
196
+ --num-original-experts 256 \
197
+ --num-retained-experts 192 \
198
+ --deleted-experts-file extras/deleted_experts.json
199
+ ```
200
+
201
+ ### [`unglitched_vllm`](extras/unglitched_vllm) & [`force_swap.cpp`](extras/force_swap.cpp)
202
+
203
+ Custom vLLM build script and GPU memory swap utility for DGX Spark.
204
+ `force_swap.cpp` implements a small helper that forces GPU pages to swap to
205
+ system memory, useful for fitting the model on a single GB10 node.
206
+
207
+ ## License
208
+
209
+ This model inherits the
210
+ [MiniMax M2.7 Non-Commercial License](LICENSE).
211
+ See [LICENSE](LICENSE) for full terms.
212
+
213
+ ## Citation
214
+
215
+ ```bibtex
216
+ @misc{minimax-m2-7,
217
+ title={MiniMax-M2.7},
218
+ author={MiniMax},
219
+ url={https://huggingface.co/MiniMaxAI/MiniMax-M2.7}
220
+ }
221
+
222
+ @misc{minimax-m2-7-reap-nvfp4,
223
+ title={MiniMax-M2.7-REAP-172B-A10B-NVFP4},
224
+ author={Oleg K.},
225
+ note={NVFP4 weights from NinjaBoffin/MiniMax-M2.7-NVFP4; pruning mask
226
+ from saricles/MiniMax-M2.5-REAP-172B-A10B-NVFP4-GB10},
227
+ year={2026}
228
+ }
229
+ ```
added_tokens.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</minimax:tool_call>": 200053,
3
+ "</think>": 200051,
4
+ "<add_file>": 200036,
5
+ "<code_context>": 200043,
6
+ "<code_interpreter>": 200023,
7
+ "<commit_after>": 200018,
8
+ "<commit_before>": 200016,
9
+ "<commit_message>": 200040,
10
+ "<commit_msg>": 200017,
11
+ "<delete_file>": 200037,
12
+ "<edit_file>": 200039,
13
+ "<empty_output>": 200015,
14
+ "<empty_source_file>": 200041,
15
+ "<file_content>": 200044,
16
+ "<file_sep>": 200049,
17
+ "<filename>": 200006,
18
+ "<filepath>": 200048,
19
+ "<fim_middle>": 200002,
20
+ "<fim_pad>": 200004,
21
+ "<fim_prefix>": 200001,
22
+ "<fim_suffix>": 200003,
23
+ "<function_call>": 200022,
24
+ "<gh_stars>": 200007,
25
+ "<issue_closed>": 200010,
26
+ "<issue_comment>": 200009,
27
+ "<issue_start>": 200008,
28
+ "<jupyter_code>": 200013,
29
+ "<jupyter_error>": 200035,
30
+ "<jupyter_output>": 200014,
31
+ "<jupyter_start>": 200011,
32
+ "<jupyter_text>": 200012,
33
+ "<minimax:tool_call>": 200052,
34
+ "<pr_start>": 200046,
35
+ "<rename_file>": 200038,
36
+ "<repo_struct>": 200042,
37
+ "<reponame>": 200005,
38
+ "<review_comment>": 200047,
39
+ "<source_files>": 200045,
40
+ "<think>": 200050,
41
+ "[e~[": 200020,
42
+ "]!d~[": 200021,
43
+ "]!p~[": 200000,
44
+ "]<]end of image[>[": 200030,
45
+ "]<]end of speech[>[": 200028,
46
+ "]<]end of video[>[": 200032,
47
+ "]<]image[>[": 200025,
48
+ "]<]speech[>[": 200024,
49
+ "]<]start of image[>[": 200029,
50
+ "]<]start of speech[>[": 200027,
51
+ "]<]start of video[>[": 200031,
52
+ "]<]video[>[": 200026,
53
+ "]<]vision pad[>[": 200033,
54
+ "]~!b[": 200034,
55
+ "]~b]": 200019
56
+ }
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,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "MiniMaxM2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "attn_type_list": [
7
+ 1,
8
+ 1,
9
+ 1,
10
+ 1,
11
+ 1,
12
+ 1,
13
+ 1,
14
+ 1,
15
+ 1,
16
+ 1,
17
+ 1,
18
+ 1,
19
+ 1,
20
+ 1,
21
+ 1,
22
+ 1,
23
+ 1,
24
+ 1,
25
+ 1,
26
+ 1,
27
+ 1,
28
+ 1,
29
+ 1,
30
+ 1,
31
+ 1,
32
+ 1,
33
+ 1,
34
+ 1,
35
+ 1,
36
+ 1,
37
+ 1,
38
+ 1,
39
+ 1,
40
+ 1,
41
+ 1,
42
+ 1,
43
+ 1,
44
+ 1,
45
+ 1,
46
+ 1,
47
+ 1,
48
+ 1,
49
+ 1,
50
+ 1,
51
+ 1,
52
+ 1,
53
+ 1,
54
+ 1,
55
+ 1,
56
+ 1,
57
+ 1,
58
+ 1,
59
+ 1,
60
+ 1,
61
+ 1,
62
+ 1,
63
+ 1,
64
+ 1,
65
+ 1,
66
+ 1,
67
+ 1,
68
+ 1
69
+ ],
70
+ "auto_map": {
71
+ "AutoConfig": "configuration_minimax_m2.MiniMaxM2Config",
72
+ "AutoModelForCausalLM": "modeling_minimax_m2.MiniMaxM2ForCausalLM"
73
+ },
74
+ "bos_token_id": 1,
75
+ "dtype": "bfloat16",
76
+ "eos_token_id": 2,
77
+ "head_dim": 128,
78
+ "hidden_act": "silu",
79
+ "hidden_size": 3072,
80
+ "initializer_range": 0.02,
81
+ "intermediate_size": 1536,
82
+ "max_position_embeddings": 196608,
83
+ "model_type": "minimax_m2",
84
+ "mtp_transformer_layers": 1,
85
+ "num_attention_heads": 48,
86
+ "num_experts_per_tok": 8,
87
+ "num_hidden_layers": 62,
88
+ "num_key_value_heads": 8,
89
+ "num_local_experts": 192,
90
+ "num_mtp_modules": 3,
91
+ "output_router_logits": false,
92
+ "partial_rotary_factor": 0.5,
93
+ "qk_norm_type": "per_layer",
94
+ "quantization_config": {
95
+ "config_groups": {
96
+ "group_0": {
97
+ "input_activations": {
98
+ "dynamic": false,
99
+ "num_bits": 4,
100
+ "type": "float",
101
+ "group_size": 16
102
+ },
103
+ "weights": {
104
+ "dynamic": false,
105
+ "num_bits": 4,
106
+ "type": "float",
107
+ "group_size": 16
108
+ },
109
+ "targets": [
110
+ "Linear"
111
+ ]
112
+ }
113
+ },
114
+ "ignore": [
115
+ "lm_head",
116
+ "model.layers.0.block_sparse_moe.gate",
117
+ "model.layers.0.self_attn*",
118
+ "model.layers.1.block_sparse_moe.gate",
119
+ "model.layers.1.self_attn*",
120
+ "model.layers.10.block_sparse_moe.gate",
121
+ "model.layers.10.self_attn*",
122
+ "model.layers.11.block_sparse_moe.gate",
123
+ "model.layers.11.self_attn*",
124
+ "model.layers.12.block_sparse_moe.gate",
125
+ "model.layers.12.self_attn*",
126
+ "model.layers.13.block_sparse_moe.gate",
127
+ "model.layers.13.self_attn*",
128
+ "model.layers.14.block_sparse_moe.gate",
129
+ "model.layers.14.self_attn*",
130
+ "model.layers.15.block_sparse_moe.gate",
131
+ "model.layers.15.self_attn*",
132
+ "model.layers.16.block_sparse_moe.gate",
133
+ "model.layers.16.self_attn*",
134
+ "model.layers.17.block_sparse_moe.gate",
135
+ "model.layers.17.self_attn*",
136
+ "model.layers.18.block_sparse_moe.gate",
137
+ "model.layers.18.self_attn*",
138
+ "model.layers.19.block_sparse_moe.gate",
139
+ "model.layers.19.self_attn*",
140
+ "model.layers.2.block_sparse_moe.gate",
141
+ "model.layers.2.self_attn*",
142
+ "model.layers.20.block_sparse_moe.gate",
143
+ "model.layers.20.self_attn*",
144
+ "model.layers.21.block_sparse_moe.gate",
145
+ "model.layers.21.self_attn*",
146
+ "model.layers.22.block_sparse_moe.gate",
147
+ "model.layers.22.self_attn*",
148
+ "model.layers.23.block_sparse_moe.gate",
149
+ "model.layers.23.self_attn*",
150
+ "model.layers.24.block_sparse_moe.gate",
151
+ "model.layers.24.self_attn*",
152
+ "model.layers.25.block_sparse_moe.gate",
153
+ "model.layers.25.self_attn*",
154
+ "model.layers.26.block_sparse_moe.gate",
155
+ "model.layers.26.self_attn*",
156
+ "model.layers.27.block_sparse_moe.gate",
157
+ "model.layers.27.self_attn*",
158
+ "model.layers.28.block_sparse_moe.gate",
159
+ "model.layers.28.self_attn*",
160
+ "model.layers.29.block_sparse_moe.gate",
161
+ "model.layers.29.self_attn*",
162
+ "model.layers.3.block_sparse_moe.gate",
163
+ "model.layers.3.self_attn*",
164
+ "model.layers.30.block_sparse_moe.gate",
165
+ "model.layers.30.self_attn*",
166
+ "model.layers.31.block_sparse_moe.gate",
167
+ "model.layers.31.self_attn*",
168
+ "model.layers.32.block_sparse_moe.gate",
169
+ "model.layers.32.self_attn*",
170
+ "model.layers.33.block_sparse_moe.gate",
171
+ "model.layers.33.self_attn*",
172
+ "model.layers.34.block_sparse_moe.gate",
173
+ "model.layers.34.self_attn*",
174
+ "model.layers.35.block_sparse_moe.gate",
175
+ "model.layers.35.self_attn*",
176
+ "model.layers.36.block_sparse_moe.gate",
177
+ "model.layers.36.self_attn*",
178
+ "model.layers.37.block_sparse_moe.gate",
179
+ "model.layers.37.self_attn*",
180
+ "model.layers.38.block_sparse_moe.gate",
181
+ "model.layers.38.self_attn*",
182
+ "model.layers.39.block_sparse_moe.gate",
183
+ "model.layers.39.self_attn*",
184
+ "model.layers.4.block_sparse_moe.gate",
185
+ "model.layers.4.self_attn*",
186
+ "model.layers.40.block_sparse_moe.gate",
187
+ "model.layers.40.self_attn*",
188
+ "model.layers.41.block_sparse_moe.gate",
189
+ "model.layers.41.self_attn*",
190
+ "model.layers.42.block_sparse_moe.gate",
191
+ "model.layers.42.self_attn*",
192
+ "model.layers.43.block_sparse_moe.gate",
193
+ "model.layers.43.self_attn*",
194
+ "model.layers.44.block_sparse_moe.gate",
195
+ "model.layers.44.self_attn*",
196
+ "model.layers.45.block_sparse_moe.gate",
197
+ "model.layers.45.self_attn*",
198
+ "model.layers.46.block_sparse_moe.gate",
199
+ "model.layers.46.self_attn*",
200
+ "model.layers.47.block_sparse_moe.gate",
201
+ "model.layers.47.self_attn*",
202
+ "model.layers.48.block_sparse_moe.gate",
203
+ "model.layers.48.self_attn*",
204
+ "model.layers.49.block_sparse_moe.gate",
205
+ "model.layers.49.self_attn*",
206
+ "model.layers.5.block_sparse_moe.gate",
207
+ "model.layers.5.self_attn*",
208
+ "model.layers.50.block_sparse_moe.gate",
209
+ "model.layers.50.self_attn*",
210
+ "model.layers.51.block_sparse_moe.gate",
211
+ "model.layers.51.self_attn*",
212
+ "model.layers.52.block_sparse_moe.gate",
213
+ "model.layers.52.self_attn*",
214
+ "model.layers.53.block_sparse_moe.gate",
215
+ "model.layers.53.self_attn*",
216
+ "model.layers.54.block_sparse_moe.gate",
217
+ "model.layers.54.self_attn*",
218
+ "model.layers.55.block_sparse_moe.gate",
219
+ "model.layers.55.self_attn*",
220
+ "model.layers.56.block_sparse_moe.gate",
221
+ "model.layers.56.self_attn*",
222
+ "model.layers.57.block_sparse_moe.gate",
223
+ "model.layers.57.self_attn*",
224
+ "model.layers.58.block_sparse_moe.gate",
225
+ "model.layers.58.self_attn*",
226
+ "model.layers.59.block_sparse_moe.gate",
227
+ "model.layers.59.self_attn*",
228
+ "model.layers.6.block_sparse_moe.gate",
229
+ "model.layers.6.self_attn*",
230
+ "model.layers.60.block_sparse_moe.gate",
231
+ "model.layers.60.self_attn*",
232
+ "model.layers.61.block_sparse_moe.gate",
233
+ "model.layers.61.self_attn*",
234
+ "model.layers.7.block_sparse_moe.gate",
235
+ "model.layers.7.self_attn*",
236
+ "model.layers.8.block_sparse_moe.gate",
237
+ "model.layers.8.self_attn*",
238
+ "model.layers.9.block_sparse_moe.gate",
239
+ "model.layers.9.self_attn*"
240
+ ],
241
+ "quant_algo": "NVFP4",
242
+ "kv_cache_scheme": {
243
+ "dynamic": false,
244
+ "num_bits": 8,
245
+ "type": "float"
246
+ },
247
+ "producer": {
248
+ "name": "modelopt",
249
+ "version": "0.43.0rc2.dev105+g0b42c143d"
250
+ },
251
+ "quant_method": "modelopt"
252
+ },
253
+ "rms_norm_eps": 1e-06,
254
+ "rope_theta": 5000000,
255
+ "rotary_dim": 64,
256
+ "router_aux_loss_coef": 0.001,
257
+ "router_jitter_noise": 0.0,
258
+ "scoring_func": "sigmoid",
259
+ "shared_intermediate_size": 0,
260
+ "sliding_window": null,
261
+ "tie_word_embeddings": false,
262
+ "transformers_version": "4.57.6",
263
+ "use_cache": true,
264
+ "use_mtp": true,
265
+ "use_qk_norm": true,
266
+ "use_routing_bias": true,
267
+ "vocab_size": 200064
268
+ }
configuration_minimax_m2.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
2
+ # This file was automatically generated from src/transformers/models/minimax_m2/modular_minimax_m2.py.
3
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
4
+ # the file from the modular. If any change should be done, please apply the change to the
5
+ # modular_minimax_m2.py file directly. One of our CI enforces this.
6
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7
+ # coding=utf-8
8
+ # Copyright 2025 the HuggingFace Team. All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+
23
+ from transformers.configuration_utils import PretrainedConfig
24
+
25
+
26
+ class MiniMaxM2Config(PretrainedConfig):
27
+ r"""
28
+ This is the configuration class to store the configuration of a [`MiniMaxM2Model`]. It is used to instantiate an
29
+ MiniMaxM2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
30
+ with the defaults will yield a similar configuration to that of the MiniMaxM2-7B-v0.1 or MiniMaxM2-7B-Instruct-v0.1.
31
+
32
+ [minimax_m2ai/MiniMaxM2-8x7B](https://huggingface.co/minimax_m2ai/MiniMaxM2-8x7B)
33
+ [minimax_m2ai/MiniMaxM2-7B-Instruct-v0.1](https://huggingface.co/minimax_m2ai/MiniMaxM2-7B-Instruct-v0.1)
34
+
35
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
36
+ documentation from [`PretrainedConfig`] for more information.
37
+
38
+
39
+ Args:
40
+ vocab_size (`int`, *optional*, defaults to 32000):
41
+ Vocabulary size of the MiniMaxM2 model. Defines the number of different tokens that can be represented by the
42
+ `inputs_ids` passed when calling [`MiniMaxM2Model`]
43
+ hidden_size (`int`, *optional*, defaults to 4096):
44
+ Dimension of the hidden representations.
45
+ intermediate_size (`int`, *optional*, defaults to 14336):
46
+ Dimension of the MLP representations.
47
+ num_hidden_layers (`int`, *optional*, defaults to 32):
48
+ Number of hidden layers in the Transformer encoder.
49
+ num_attention_heads (`int`, *optional*, defaults to 32):
50
+ Number of attention heads for each attention layer in the Transformer encoder.
51
+ num_key_value_heads (`int`, *optional*, defaults to 8):
52
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
53
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
54
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
55
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
56
+ by meanpooling all the original heads within that group. For more details, check out [this
57
+ paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to `8`.
58
+ head_dim (`int`, *optional*, defaults to `hidden_size // num_attention_heads`):
59
+ The attention head dimension.
60
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
61
+ The non-linear activation function (function or string) in the decoder.
62
+ max_position_embeddings (`int`, *optional*, defaults to `4096*32`):
63
+ The maximum sequence length that this model might ever be used with. MiniMaxM2's sliding window attention
64
+ allows sequence of up to 4096*32 tokens.
65
+ initializer_range (`float`, *optional*, defaults to 0.02):
66
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
67
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
68
+ The epsilon used by the rms normalization layers.
69
+ use_cache (`bool`, *optional*, defaults to `True`):
70
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
71
+ relevant if `config.is_decoder=True`.
72
+ pad_token_id (`int`, *optional*):
73
+ The id of the padding token.
74
+ bos_token_id (`int`, *optional*, defaults to 1):
75
+ The id of the "beginning-of-sequence" token.
76
+ eos_token_id (`int`, *optional*, defaults to 2):
77
+ The id of the "end-of-sequence" token.
78
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
79
+ Whether the model's input and output word embeddings should be tied.
80
+ rope_theta (`float`, *optional*, defaults to 1000000.0):
81
+ The base period of the RoPE embeddings.
82
+ sliding_window (`int`, *optional*):
83
+ Sliding window attention window size. If not specified, will default to `4096`.
84
+ attention_dropout (`float`, *optional*, defaults to 0.0):
85
+ The dropout ratio for the attention probabilities.
86
+ num_experts_per_tok (`int`, *optional*, defaults to 2):
87
+ The number of experts to route per-token, can be also interpreted as the `top-k` routing
88
+ parameter
89
+ num_local_experts (`int`, *optional*, defaults to 8):
90
+ Number of experts per Sparse MLP layer.
91
+ output_router_logits (`bool`, *optional*, defaults to `False`):
92
+ Whether or not the router logits should be returned by the model. Enabling this will also
93
+ allow the model to output the auxiliary loss. See [here]() for more details
94
+ router_aux_loss_coef (`float`, *optional*, defaults to 0.001):
95
+ The aux loss factor for the total loss.
96
+ router_jitter_noise (`float`, *optional*, defaults to 0.0):
97
+ Amount of noise to add to the router.
98
+
99
+ ```python
100
+ >>> from transformers import MiniMaxM2Model, MiniMaxM2Config
101
+
102
+ >>> # Initializing a MiniMaxM2 7B style configuration
103
+ >>> configuration = MiniMaxM2Config()
104
+
105
+ >>> # Initializing a model from the MiniMaxM2 7B style configuration
106
+ >>> model = MiniMaxM2Model(configuration)
107
+
108
+ >>> # Accessing the model configuration
109
+ >>> configuration = model.config
110
+ ```"""
111
+
112
+ model_type = "minimax_m2"
113
+ keys_to_ignore_at_inference = ["past_key_values"]
114
+ base_model_tp_plan = {
115
+ "layers.*.self_attn.q_proj": "colwise",
116
+ "layers.*.self_attn.k_proj": "colwise",
117
+ "layers.*.self_attn.v_proj": "colwise",
118
+ "layers.*.self_attn.o_proj": "rowwise",
119
+ "layers.*.block_sparse_moe.gate": "colwise_rep", # we need to replicate here to correctly route experts
120
+ "layers.*.block_sparse_moe.experts.*.w1": "colwise",
121
+ "layers.*.block_sparse_moe.experts.*.w2": "rowwise",
122
+ "layers.*.block_sparse_moe.experts.*.w3": "colwise",
123
+ }
124
+ base_model_pp_plan = {
125
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
126
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
127
+ "norm": (["hidden_states"], ["hidden_states"]),
128
+ }
129
+
130
+ def __init__(
131
+ self,
132
+ vocab_size=32000,
133
+ hidden_size=4096,
134
+ intermediate_size=14336,
135
+ num_hidden_layers=32,
136
+ num_attention_heads=32,
137
+ num_key_value_heads=8,
138
+ head_dim=None,
139
+ hidden_act="silu",
140
+ max_position_embeddings=4096 * 32,
141
+ initializer_range=0.02,
142
+ rms_norm_eps=1e-5,
143
+ use_cache=True,
144
+ pad_token_id=None,
145
+ bos_token_id=1,
146
+ eos_token_id=2,
147
+ tie_word_embeddings=False,
148
+ rope_theta=1e6,
149
+ sliding_window=None,
150
+ attention_dropout=0.0,
151
+ num_experts_per_tok=2,
152
+ num_local_experts=8,
153
+ output_router_logits=False,
154
+ router_aux_loss_coef=0.001,
155
+ router_jitter_noise=0.0,
156
+ **kwargs,
157
+ ):
158
+ self.vocab_size = vocab_size
159
+ self.max_position_embeddings = max_position_embeddings
160
+ self.hidden_size = hidden_size
161
+ self.intermediate_size = intermediate_size
162
+ self.num_hidden_layers = num_hidden_layers
163
+ self.num_attention_heads = num_attention_heads
164
+ self.sliding_window = sliding_window
165
+
166
+ # for backward compatibility
167
+ if num_key_value_heads is None:
168
+ num_key_value_heads = num_attention_heads
169
+
170
+ self.num_key_value_heads = num_key_value_heads
171
+ self.hidden_act = hidden_act
172
+ self.initializer_range = initializer_range
173
+ self.rms_norm_eps = rms_norm_eps
174
+ self.use_cache = use_cache
175
+ self.rope_theta = rope_theta
176
+ self.attention_dropout = attention_dropout
177
+ self.head_dim = head_dim
178
+
179
+ self.num_experts_per_tok = num_experts_per_tok
180
+ self.num_local_experts = num_local_experts
181
+ self.output_router_logits = output_router_logits
182
+ self.router_aux_loss_coef = router_aux_loss_coef
183
+ self.router_jitter_noise = router_jitter_noise
184
+
185
+ self.use_qk_norm = kwargs.pop("use_qk_norm", False)
186
+ self.rotary_dim = kwargs.pop("rotary_dim", self.head_dim)
187
+ self.partial_rotary_factor = kwargs.pop("partial_rotary_factor", 1)
188
+ if self.head_dim is not None:
189
+ self.partial_rotary_factor = self.rotary_dim / self.head_dim
190
+
191
+ super().__init__(
192
+ pad_token_id=pad_token_id,
193
+ bos_token_id=bos_token_id,
194
+ eos_token_id=eos_token_id,
195
+ tie_word_embeddings=tie_word_embeddings,
196
+ **kwargs,
197
+ )
198
+
199
+
200
+ __all__ = ["MiniMaxM2Config"]
extras/__pycache__/minimax_m2_optthink_reasoning_parser.cpython-312.pyc ADDED
Binary file (4.58 kB). View file
 
extras/chat_template.jinja ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.5 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
+ {%- if enable_thinking is defined and enable_thinking is false %}
159
+ {{- ']~b]ai' ~ '\n' ~ '<think>\n</think>\n\n' }}
160
+ {%- else %}
161
+ {{- ']~b]ai' ~ '\n' ~ '<think>' ~ '\n' }}
162
+ {%- endif %}
163
+ {%- endif -%}
extras/delete_experts.py ADDED
@@ -0,0 +1,409 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Script to delete experts from a MoE model layer by layer.
4
+ Processes one safetensor file at a time.
5
+
6
+ Can either:
7
+ 1. Use a pre-computed deleted_experts.json file
8
+ 2. Analyze original vs pruned model to find deleted experts first
9
+ """
10
+
11
+ import argparse
12
+ import gc
13
+ import json
14
+ import re
15
+ import shutil
16
+ from pathlib import Path
17
+ from typing import Optional
18
+
19
+ import numpy as np
20
+ import torch
21
+ from safetensors import safe_open
22
+ from safetensors.torch import save_file
23
+ from scipy.optimize import linear_sum_assignment
24
+
25
+
26
+ def load_deleted_experts(deleted_file: Path) -> dict[int, list[int]]:
27
+ """Load the deleted experts mapping from JSON file."""
28
+ with open(deleted_file, "r") as f:
29
+ data = json.load(f)
30
+ return {int(k): v for k, v in data["deleted_experts_per_layer"].items()}
31
+
32
+
33
+ def find_deleted_experts(
34
+ original_model_path: Path,
35
+ pruned_model_path: Path,
36
+ num_original_experts: int,
37
+ num_pruned_experts: int,
38
+ hidden_dim: int = 3072,
39
+ ) -> dict[int, list[int]]:
40
+ """
41
+ Find deleted experts by comparing router matrices between original and pruned models.
42
+ Uses Hungarian algorithm for optimal matching based on cosine distance.
43
+
44
+ Returns a dict mapping layer_num -> list of deleted expert indices.
45
+ """
46
+ deleted_experts = {}
47
+ num_layers = 62 # MiniMax-M2.x models have 62 layers
48
+
49
+ for layer_num in range(num_layers):
50
+ router_key = f"model.layers.{layer_num}.block_sparse_moe.gate.weight"
51
+
52
+ # Load router from original model
53
+ orig_router = None
54
+ for sf_file in sorted(original_model_path.glob("model-*.safetensors")):
55
+ with safe_open(sf_file, framework="pt") as f:
56
+ if router_key in f.keys():
57
+ orig_router = f.get_tensor(router_key)
58
+ break
59
+
60
+ # Load router from pruned model
61
+ prune_router = None
62
+ for sf_file in sorted(pruned_model_path.glob("model-*.safetensors")):
63
+ with safe_open(sf_file, framework="pt") as f:
64
+ if router_key in f.keys():
65
+ prune_router = f.get_tensor(router_key)
66
+ break
67
+
68
+ if orig_router is None or prune_router is None:
69
+ print(f" Layer {layer_num}: Router not found, skipping")
70
+ continue
71
+
72
+ # Convert bfloat16 if needed
73
+ if orig_router.dtype == torch.bfloat16:
74
+ orig_router = orig_router.to(torch.float32)
75
+ if prune_router.dtype == torch.bfloat16:
76
+ prune_router = prune_router.to(torch.float32)
77
+
78
+ # L2 normalize rows for cosine distance
79
+ orig_np = orig_router.numpy()
80
+ prune_np = prune_router.numpy()
81
+
82
+ orig_norm = orig_np / (np.linalg.norm(orig_np, axis=1, keepdims=True) + 1e-10)
83
+ prune_norm = prune_np / (np.linalg.norm(prune_np, axis=1, keepdims=True) + 1e-10)
84
+
85
+ # Cosine distance matrix
86
+ distance_matrix = 1 - np.dot(orig_norm, prune_norm.T)
87
+
88
+ # Hungarian algorithm
89
+ row_ind, col_ind = linear_sum_assignment(distance_matrix)
90
+
91
+ # Find unmatched (deleted) experts
92
+ matched_original = set(row_ind)
93
+ all_original = set(range(num_original_experts))
94
+ deleted = sorted(all_original - matched_original)
95
+
96
+ deleted_experts[layer_num] = deleted
97
+
98
+ if layer_num in [0, 1, 2, 10, 20, 30, 40, 50, 61]:
99
+ print(f" Layer {layer_num}: {len(deleted)} deleted experts")
100
+
101
+ return deleted_experts
102
+
103
+
104
+ def get_retained_experts(num_original: int, deleted: list[int]) -> list[int]:
105
+ """Get the list of retained expert indices (sorted)."""
106
+ all_experts = set(range(num_original))
107
+ deleted_set = set(deleted)
108
+ return sorted(all_experts - deleted_set)
109
+
110
+
111
+ def get_layer_for_tensor(tensor_name: str) -> Optional[int]:
112
+ """Get layer number for a tensor name."""
113
+ parts = tensor_name.split(".")
114
+ for i, part in enumerate(parts):
115
+ if part == "layers" and i + 1 < len(parts):
116
+ try:
117
+ return int(parts[i + 1])
118
+ except ValueError:
119
+ pass
120
+ return None
121
+
122
+
123
+ def is_expert_tensor(key: str) -> bool:
124
+ """
125
+ Check if a tensor key belongs to a specific numbered expert.
126
+ Uses regex to match .experts.<N>. pattern robustly, covering NVFP4
127
+ sub-tensors like w1.weight, w1.weight_scale, w1.weight_scale_2,
128
+ w1.input_scale, etc.
129
+ """
130
+ return bool(re.search(r'\.experts\.\d+\.', key))
131
+
132
+
133
+ # Keys to strip: asymmetric KV-cache quantization zero-points that vLLM
134
+ # doesn't support (only scale factors are used).
135
+ _STRIP_SUFFIXES = (".k_bias", ".v_bias")
136
+
137
+
138
+ def should_strip_tensor(key: str) -> bool:
139
+ """Return True for tensors that should be omitted from the output model."""
140
+ return any(key.endswith(sfx) for sfx in _STRIP_SUFFIXES)
141
+
142
+
143
+ def process_tensor(
144
+ key: str,
145
+ tensor: torch.Tensor,
146
+ deleted_experts: dict[int, list[int]],
147
+ num_original_experts: int,
148
+ ) -> tuple[str, torch.Tensor] | None:
149
+ """
150
+ Process a single tensor. Returns (new_key, new_tensor) or None to skip.
151
+ """
152
+ # Strip unsupported KV quantization zero-points.
153
+ if should_strip_tensor(key):
154
+ return None
155
+
156
+ layer_num = get_layer_for_tensor(key)
157
+
158
+ # Non-layer or non-MoE tensors pass through unchanged.
159
+ if layer_num is None or "block_sparse_moe" not in key:
160
+ return (key, tensor)
161
+
162
+ if is_expert_tensor(key):
163
+ # Expert weight/scale tensor – delete or renumber.
164
+ parts = key.split(".")
165
+ for i, part in enumerate(parts):
166
+ if part == "experts" and i + 1 < len(parts):
167
+ expert_idx = int(parts[i + 1])
168
+ deleted = deleted_experts.get(layer_num, [])
169
+ retained = get_retained_experts(num_original_experts, deleted)
170
+ if expert_idx not in retained:
171
+ return None # Deleted expert – drop tensor.
172
+ # Renumber to sequential 0-based index.
173
+ new_expert_idx = retained.index(expert_idx)
174
+ new_key_parts = parts.copy()
175
+ new_key_parts[i + 1] = str(new_expert_idx)
176
+ new_key = ".".join(new_key_parts)
177
+ return (new_key, tensor)
178
+ # Shouldn't happen, but fall through unchanged.
179
+ return (key, tensor)
180
+
181
+ elif "gate.weight" in key:
182
+ deleted = deleted_experts.get(layer_num, [])
183
+ retained = get_retained_experts(num_original_experts, deleted)
184
+ indices = torch.tensor(retained, dtype=torch.long)
185
+ new_tensor = tensor[indices].clone()
186
+ print(f" gate.weight layer {layer_num}: {tuple(tensor.shape)} → {tuple(new_tensor.shape)}")
187
+ return (key, new_tensor)
188
+
189
+ elif "e_score_correction_bias" in key:
190
+ deleted = deleted_experts.get(layer_num, [])
191
+ retained = get_retained_experts(num_original_experts, deleted)
192
+ indices = torch.tensor(retained, dtype=torch.long)
193
+ return (key, tensor[indices].clone())
194
+
195
+ else:
196
+ return (key, tensor)
197
+
198
+
199
+ def process_file(
200
+ input_path: Path,
201
+ output_path: Path,
202
+ deleted_experts: dict[int, list[int]],
203
+ num_original_experts: int,
204
+ ) -> tuple[int, int, int]:
205
+ """
206
+ Process one safetensor file.
207
+ Returns (kept, deleted, stripped) tensor counts.
208
+ """
209
+ tensors = {}
210
+ kept = deleted_count = stripped = 0
211
+
212
+ with safe_open(input_path, framework="pt") as f:
213
+ all_keys = list(f.keys())
214
+
215
+ # Report stripped keys upfront for this file.
216
+ stripped_keys = [k for k in all_keys if should_strip_tensor(k)]
217
+ if stripped_keys:
218
+ print(f" Stripping {len(stripped_keys)} KV-bias tensors: {stripped_keys[:4]}{'…' if len(stripped_keys) > 4 else ''}")
219
+
220
+ with safe_open(input_path, framework="pt") as f:
221
+ for key in all_keys:
222
+ tensor = f.get_tensor(key)
223
+ result = process_tensor(key, tensor, deleted_experts, num_original_experts)
224
+ if result is not None:
225
+ new_key, new_tensor = result
226
+ tensors[new_key] = new_tensor
227
+ kept += 1
228
+ else:
229
+ if should_strip_tensor(key):
230
+ stripped += 1
231
+ else:
232
+ deleted_count += 1
233
+
234
+ save_file(tensors, output_path)
235
+ del tensors
236
+ gc.collect()
237
+
238
+ return kept, deleted_count, stripped
239
+
240
+
241
+ def get_file_to_tensors(model_path: Path) -> dict[str, list[str]]:
242
+ """Get mapping from filename to list of tensor names."""
243
+ index_path = model_path / "model.safetensors.index.json"
244
+ with open(index_path, "r") as f:
245
+ index_data = json.load(f)
246
+ weight_map = index_data["weight_map"]
247
+ file_to_tensors: dict[str, list[str]] = {}
248
+ for key, file_name in weight_map.items():
249
+ if file_name not in file_to_tensors:
250
+ file_to_tensors[file_name] = []
251
+ file_to_tensors[file_name].append(key)
252
+ return file_to_tensors
253
+
254
+
255
+ def main():
256
+ parser = argparse.ArgumentParser(
257
+ description="Delete experts from MoE model. "
258
+ "Either provide --deleted-experts-file or use --compare-with to find deleted experts."
259
+ )
260
+ parser.add_argument("input_model", type=Path, help="Input model path (256 experts)")
261
+ parser.add_argument("output_model", type=Path, help="Output model path")
262
+ parser.add_argument("--num-original-experts", type=int, default=256)
263
+ parser.add_argument("--num-retained-experts", type=int, default=192)
264
+ parser.add_argument("--deleted-experts-file", type=Path,
265
+ help="JSON with pre-computed deleted experts (optional)")
266
+ parser.add_argument("--compare-with", type=Path,
267
+ help="Pruned model path (192 experts) to compare and find deleted experts")
268
+ parser.add_argument("--save-deleted-experts", type=Path,
269
+ help="Save found deleted experts to JSON file (for --compare-with mode)")
270
+
271
+ args = parser.parse_args()
272
+
273
+ # Either load from file or find via comparison
274
+ if args.deleted_experts_file:
275
+ print("Loading deleted experts from file...")
276
+ deleted_experts = load_deleted_experts(args.deleted_experts_file)
277
+ print(f" {len(deleted_experts)} layers")
278
+ # Sanity-check: verify expected deletions per layer.
279
+ counts = {l: len(v) for l, v in deleted_experts.items()}
280
+ expected = args.num_original_experts - args.num_retained_experts
281
+ bad = {l: c for l, c in counts.items() if c != expected}
282
+ if bad:
283
+ print(f" WARNING: {len(bad)} layers have unexpected deletion count "
284
+ f"(expected {expected}): {dict(list(bad.items())[:5])}")
285
+ elif args.compare_with:
286
+ print("Finding deleted experts by comparing models...")
287
+ print(f" Original: {args.input_model}")
288
+ print(f" Pruned: {args.compare_with}")
289
+ deleted_experts = find_deleted_experts(
290
+ args.input_model,
291
+ args.compare_with,
292
+ args.num_original_experts,
293
+ args.num_retained_experts,
294
+ )
295
+ print(f" Found deleted experts for {len(deleted_experts)} layers")
296
+
297
+ if args.save_deleted_experts:
298
+ print(f"\nSaving deleted experts to {args.save_deleted_experts}...")
299
+ data = {"deleted_experts_per_layer": {str(k): v for k, v in deleted_experts.items()}}
300
+ with open(args.save_deleted_experts, "w") as f:
301
+ json.dump(data, f, indent=2)
302
+ else:
303
+ parser.error("Either --deleted-experts-file or --compare-with is required")
304
+
305
+ # Create output dir
306
+ args.output_model.mkdir(parents=True, exist_ok=True)
307
+
308
+ # Copy non-safetensor files
309
+ print("\nCopying config/tokenizer files...")
310
+ for fname in ["config.json", "configuration_minimax_m2.py", "tokenizer.json",
311
+ "tokenizer_config.json", "vocab.json", "merges.txt",
312
+ "special_tokens_map.json", "added_tokens.json",
313
+ "generation_config.json", "chat_template.jinja", ".gitattributes",
314
+ "hf_quant_config.json", "modeling_minimax_m2.py"]:
315
+ src = args.input_model / fname
316
+ if src.exists():
317
+ shutil.copy2(src, args.output_model / fname)
318
+ print(f" {fname}")
319
+
320
+ # Update config: set num_local_experts to the retained count.
321
+ print("\nUpdating config...")
322
+ with open(args.input_model / "config.json") as f:
323
+ config = json.load(f)
324
+ config["num_local_experts"] = args.num_retained_experts
325
+ with open(args.output_model / "config.json", "w") as f:
326
+ json.dump(config, f, indent=2)
327
+ print(f" num_local_experts = {args.num_retained_experts}")
328
+
329
+ # Process safetensors
330
+ print("\nProcessing safetensor files...")
331
+ file_to_tensors = get_file_to_tensors(args.input_model)
332
+
333
+ total_kept = total_deleted = total_stripped = 0
334
+ for file_name in sorted(file_to_tensors.keys()):
335
+ input_path = args.input_model / file_name
336
+ output_path = args.output_model / file_name
337
+ print(f" {file_name}...")
338
+ kept, deleted_count, stripped = process_file(
339
+ input_path, output_path, deleted_experts, args.num_original_experts
340
+ )
341
+ print(f" kept={kept} deleted={deleted_count} stripped={stripped}")
342
+ total_kept += kept
343
+ total_deleted += deleted_count
344
+ total_stripped += stripped
345
+ gc.collect()
346
+
347
+ print(f"\nTotal: kept={total_kept} deleted={total_deleted} stripped={total_stripped}")
348
+
349
+ # Update index.
350
+ # Bug fixes vs original:
351
+ # 1. Use `layer_num is not None` instead of truthy `layer_num` (layer 0 == 0 is falsy).
352
+ # 2. Use a `handled` flag so deleted experts are not re-added via the for-else clause.
353
+ # 3. Use is_expert_tensor() regex instead of ".w" heuristic.
354
+ print("\nUpdating model index...")
355
+ with open(args.input_model / "model.safetensors.index.json") as f:
356
+ index_data = json.load(f)
357
+
358
+ weight_map = index_data["weight_map"]
359
+ new_weight_map: dict[str, str] = {}
360
+ idx_skipped = idx_stripped = idx_renamed = 0
361
+
362
+ for key, file_name in weight_map.items():
363
+ # Drop stripped tensors (KV bias).
364
+ if should_strip_tensor(key):
365
+ idx_stripped += 1
366
+ continue
367
+
368
+ layer_num = get_layer_for_tensor(key)
369
+
370
+ # FIX 1: use `is not None` so layer 0 (== 0, falsy) is handled correctly.
371
+ if layer_num is not None and "block_sparse_moe" in key and is_expert_tensor(key):
372
+ parts = key.split(".")
373
+ handled = False
374
+ for i, part in enumerate(parts):
375
+ if part == "experts" and i + 1 < len(parts):
376
+ expert_idx = int(parts[i + 1])
377
+ deleted = deleted_experts.get(layer_num, [])
378
+ retained = get_retained_experts(args.num_original_experts, deleted)
379
+ if expert_idx not in retained:
380
+ # FIX 2: mark as handled and break so we don't fall
381
+ # through to the for-else and re-add the old key.
382
+ idx_skipped += 1
383
+ handled = True
384
+ break
385
+ new_expert_idx = retained.index(expert_idx)
386
+ new_key_parts = parts.copy()
387
+ new_key_parts[i + 1] = str(new_expert_idx)
388
+ new_key = ".".join(new_key_parts)
389
+ new_weight_map[new_key] = file_name
390
+ idx_renamed += 1
391
+ handled = True
392
+ break
393
+ if not handled:
394
+ # No expert index found in key (shouldn't happen), keep as-is.
395
+ new_weight_map[key] = file_name
396
+ else:
397
+ new_weight_map[key] = file_name
398
+
399
+ index_data["weight_map"] = new_weight_map
400
+ with open(args.output_model / "model.safetensors.index.json", "w") as f:
401
+ json.dump(index_data, f, indent=2)
402
+
403
+ print(f" {len(new_weight_map)} index entries "
404
+ f"(renamed={idx_renamed} skipped={idx_skipped} stripped={idx_stripped})")
405
+ print("\n✓ Done!")
406
+
407
+
408
+ if __name__ == "__main__":
409
+ main()
extras/deleted_experts.json ADDED
@@ -0,0 +1,4096 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "deleted_experts_per_layer": {
3
+ "0": [
4
+ 12,
5
+ 16,
6
+ 19,
7
+ 20,
8
+ 25,
9
+ 30,
10
+ 42,
11
+ 48,
12
+ 52,
13
+ 55,
14
+ 56,
15
+ 57,
16
+ 59,
17
+ 62,
18
+ 63,
19
+ 64,
20
+ 68,
21
+ 69,
22
+ 73,
23
+ 79,
24
+ 85,
25
+ 87,
26
+ 88,
27
+ 91,
28
+ 94,
29
+ 101,
30
+ 103,
31
+ 110,
32
+ 114,
33
+ 115,
34
+ 126,
35
+ 127,
36
+ 128,
37
+ 131,
38
+ 136,
39
+ 140,
40
+ 147,
41
+ 149,
42
+ 150,
43
+ 153,
44
+ 154,
45
+ 182,
46
+ 194,
47
+ 195,
48
+ 196,
49
+ 198,
50
+ 200,
51
+ 204,
52
+ 208,
53
+ 213,
54
+ 215,
55
+ 217,
56
+ 218,
57
+ 222,
58
+ 225,
59
+ 226,
60
+ 227,
61
+ 231,
62
+ 235,
63
+ 238,
64
+ 243,
65
+ 247,
66
+ 248,
67
+ 254
68
+ ],
69
+ "1": [
70
+ 7,
71
+ 9,
72
+ 11,
73
+ 13,
74
+ 14,
75
+ 17,
76
+ 24,
77
+ 25,
78
+ 26,
79
+ 27,
80
+ 31,
81
+ 33,
82
+ 36,
83
+ 48,
84
+ 49,
85
+ 52,
86
+ 56,
87
+ 57,
88
+ 60,
89
+ 62,
90
+ 72,
91
+ 73,
92
+ 75,
93
+ 78,
94
+ 82,
95
+ 84,
96
+ 85,
97
+ 94,
98
+ 97,
99
+ 100,
100
+ 105,
101
+ 108,
102
+ 109,
103
+ 110,
104
+ 119,
105
+ 121,
106
+ 131,
107
+ 133,
108
+ 140,
109
+ 142,
110
+ 143,
111
+ 146,
112
+ 149,
113
+ 158,
114
+ 165,
115
+ 167,
116
+ 175,
117
+ 179,
118
+ 182,
119
+ 184,
120
+ 187,
121
+ 190,
122
+ 192,
123
+ 201,
124
+ 206,
125
+ 207,
126
+ 217,
127
+ 218,
128
+ 227,
129
+ 232,
130
+ 233,
131
+ 243,
132
+ 245,
133
+ 247
134
+ ],
135
+ "2": [
136
+ 1,
137
+ 2,
138
+ 8,
139
+ 13,
140
+ 16,
141
+ 17,
142
+ 19,
143
+ 25,
144
+ 27,
145
+ 31,
146
+ 40,
147
+ 41,
148
+ 43,
149
+ 47,
150
+ 55,
151
+ 59,
152
+ 62,
153
+ 66,
154
+ 72,
155
+ 77,
156
+ 82,
157
+ 84,
158
+ 85,
159
+ 88,
160
+ 91,
161
+ 94,
162
+ 96,
163
+ 97,
164
+ 101,
165
+ 102,
166
+ 106,
167
+ 113,
168
+ 119,
169
+ 122,
170
+ 126,
171
+ 137,
172
+ 144,
173
+ 146,
174
+ 147,
175
+ 148,
176
+ 166,
177
+ 168,
178
+ 172,
179
+ 173,
180
+ 175,
181
+ 183,
182
+ 187,
183
+ 196,
184
+ 200,
185
+ 206,
186
+ 207,
187
+ 212,
188
+ 217,
189
+ 221,
190
+ 223,
191
+ 225,
192
+ 230,
193
+ 236,
194
+ 238,
195
+ 239,
196
+ 240,
197
+ 248,
198
+ 249,
199
+ 255
200
+ ],
201
+ "3": [
202
+ 2,
203
+ 9,
204
+ 10,
205
+ 14,
206
+ 21,
207
+ 30,
208
+ 32,
209
+ 38,
210
+ 48,
211
+ 50,
212
+ 53,
213
+ 55,
214
+ 59,
215
+ 62,
216
+ 69,
217
+ 74,
218
+ 84,
219
+ 85,
220
+ 88,
221
+ 94,
222
+ 96,
223
+ 97,
224
+ 99,
225
+ 100,
226
+ 104,
227
+ 107,
228
+ 110,
229
+ 117,
230
+ 122,
231
+ 123,
232
+ 140,
233
+ 143,
234
+ 146,
235
+ 151,
236
+ 161,
237
+ 162,
238
+ 163,
239
+ 164,
240
+ 168,
241
+ 172,
242
+ 173,
243
+ 177,
244
+ 179,
245
+ 183,
246
+ 186,
247
+ 190,
248
+ 193,
249
+ 198,
250
+ 201,
251
+ 210,
252
+ 214,
253
+ 216,
254
+ 218,
255
+ 221,
256
+ 229,
257
+ 230,
258
+ 231,
259
+ 233,
260
+ 236,
261
+ 241,
262
+ 243,
263
+ 245,
264
+ 249,
265
+ 252
266
+ ],
267
+ "4": [
268
+ 2,
269
+ 3,
270
+ 4,
271
+ 6,
272
+ 10,
273
+ 16,
274
+ 18,
275
+ 21,
276
+ 24,
277
+ 25,
278
+ 28,
279
+ 33,
280
+ 36,
281
+ 37,
282
+ 46,
283
+ 48,
284
+ 50,
285
+ 52,
286
+ 53,
287
+ 57,
288
+ 58,
289
+ 59,
290
+ 65,
291
+ 72,
292
+ 73,
293
+ 75,
294
+ 77,
295
+ 87,
296
+ 88,
297
+ 90,
298
+ 93,
299
+ 94,
300
+ 102,
301
+ 107,
302
+ 113,
303
+ 115,
304
+ 117,
305
+ 121,
306
+ 125,
307
+ 132,
308
+ 137,
309
+ 147,
310
+ 149,
311
+ 163,
312
+ 166,
313
+ 170,
314
+ 173,
315
+ 187,
316
+ 189,
317
+ 193,
318
+ 194,
319
+ 203,
320
+ 204,
321
+ 209,
322
+ 211,
323
+ 212,
324
+ 214,
325
+ 215,
326
+ 228,
327
+ 235,
328
+ 239,
329
+ 246,
330
+ 247,
331
+ 254
332
+ ],
333
+ "5": [
334
+ 6,
335
+ 14,
336
+ 19,
337
+ 25,
338
+ 26,
339
+ 27,
340
+ 29,
341
+ 32,
342
+ 33,
343
+ 35,
344
+ 38,
345
+ 39,
346
+ 47,
347
+ 55,
348
+ 57,
349
+ 60,
350
+ 67,
351
+ 68,
352
+ 70,
353
+ 71,
354
+ 73,
355
+ 81,
356
+ 84,
357
+ 92,
358
+ 95,
359
+ 99,
360
+ 106,
361
+ 110,
362
+ 114,
363
+ 116,
364
+ 117,
365
+ 119,
366
+ 120,
367
+ 124,
368
+ 129,
369
+ 135,
370
+ 136,
371
+ 139,
372
+ 142,
373
+ 146,
374
+ 150,
375
+ 154,
376
+ 156,
377
+ 161,
378
+ 165,
379
+ 168,
380
+ 172,
381
+ 181,
382
+ 185,
383
+ 186,
384
+ 190,
385
+ 195,
386
+ 196,
387
+ 197,
388
+ 213,
389
+ 224,
390
+ 226,
391
+ 227,
392
+ 230,
393
+ 231,
394
+ 236,
395
+ 238,
396
+ 239,
397
+ 241
398
+ ],
399
+ "6": [
400
+ 10,
401
+ 11,
402
+ 13,
403
+ 14,
404
+ 16,
405
+ 18,
406
+ 20,
407
+ 22,
408
+ 26,
409
+ 27,
410
+ 31,
411
+ 32,
412
+ 45,
413
+ 57,
414
+ 63,
415
+ 70,
416
+ 76,
417
+ 77,
418
+ 81,
419
+ 88,
420
+ 94,
421
+ 98,
422
+ 101,
423
+ 109,
424
+ 110,
425
+ 116,
426
+ 119,
427
+ 120,
428
+ 122,
429
+ 132,
430
+ 137,
431
+ 142,
432
+ 143,
433
+ 144,
434
+ 146,
435
+ 149,
436
+ 153,
437
+ 154,
438
+ 159,
439
+ 161,
440
+ 164,
441
+ 179,
442
+ 181,
443
+ 182,
444
+ 184,
445
+ 193,
446
+ 195,
447
+ 196,
448
+ 197,
449
+ 200,
450
+ 202,
451
+ 205,
452
+ 214,
453
+ 221,
454
+ 222,
455
+ 225,
456
+ 226,
457
+ 227,
458
+ 228,
459
+ 231,
460
+ 241,
461
+ 245,
462
+ 246,
463
+ 255
464
+ ],
465
+ "7": [
466
+ 5,
467
+ 12,
468
+ 14,
469
+ 21,
470
+ 22,
471
+ 24,
472
+ 25,
473
+ 26,
474
+ 37,
475
+ 38,
476
+ 39,
477
+ 46,
478
+ 54,
479
+ 56,
480
+ 66,
481
+ 67,
482
+ 73,
483
+ 75,
484
+ 77,
485
+ 81,
486
+ 87,
487
+ 88,
488
+ 93,
489
+ 94,
490
+ 103,
491
+ 112,
492
+ 116,
493
+ 119,
494
+ 121,
495
+ 138,
496
+ 144,
497
+ 145,
498
+ 146,
499
+ 153,
500
+ 156,
501
+ 165,
502
+ 172,
503
+ 174,
504
+ 178,
505
+ 182,
506
+ 187,
507
+ 191,
508
+ 192,
509
+ 193,
510
+ 200,
511
+ 201,
512
+ 214,
513
+ 216,
514
+ 218,
515
+ 220,
516
+ 226,
517
+ 227,
518
+ 231,
519
+ 235,
520
+ 237,
521
+ 239,
522
+ 241,
523
+ 243,
524
+ 246,
525
+ 247,
526
+ 248,
527
+ 250,
528
+ 254,
529
+ 255
530
+ ],
531
+ "8": [
532
+ 1,
533
+ 2,
534
+ 8,
535
+ 14,
536
+ 16,
537
+ 22,
538
+ 26,
539
+ 29,
540
+ 34,
541
+ 35,
542
+ 41,
543
+ 43,
544
+ 51,
545
+ 54,
546
+ 56,
547
+ 59,
548
+ 65,
549
+ 67,
550
+ 68,
551
+ 69,
552
+ 70,
553
+ 74,
554
+ 77,
555
+ 99,
556
+ 105,
557
+ 111,
558
+ 112,
559
+ 120,
560
+ 122,
561
+ 125,
562
+ 127,
563
+ 134,
564
+ 135,
565
+ 138,
566
+ 142,
567
+ 144,
568
+ 147,
569
+ 150,
570
+ 152,
571
+ 155,
572
+ 163,
573
+ 164,
574
+ 168,
575
+ 185,
576
+ 187,
577
+ 197,
578
+ 198,
579
+ 202,
580
+ 203,
581
+ 213,
582
+ 225,
583
+ 228,
584
+ 229,
585
+ 233,
586
+ 235,
587
+ 236,
588
+ 237,
589
+ 243,
590
+ 245,
591
+ 247,
592
+ 252,
593
+ 253,
594
+ 254,
595
+ 255
596
+ ],
597
+ "9": [
598
+ 3,
599
+ 5,
600
+ 19,
601
+ 20,
602
+ 23,
603
+ 24,
604
+ 25,
605
+ 31,
606
+ 34,
607
+ 36,
608
+ 38,
609
+ 40,
610
+ 45,
611
+ 51,
612
+ 54,
613
+ 57,
614
+ 62,
615
+ 72,
616
+ 82,
617
+ 88,
618
+ 101,
619
+ 109,
620
+ 110,
621
+ 115,
622
+ 116,
623
+ 117,
624
+ 118,
625
+ 123,
626
+ 124,
627
+ 133,
628
+ 137,
629
+ 140,
630
+ 151,
631
+ 155,
632
+ 160,
633
+ 162,
634
+ 163,
635
+ 164,
636
+ 165,
637
+ 167,
638
+ 180,
639
+ 181,
640
+ 182,
641
+ 185,
642
+ 195,
643
+ 199,
644
+ 202,
645
+ 208,
646
+ 213,
647
+ 215,
648
+ 217,
649
+ 219,
650
+ 220,
651
+ 226,
652
+ 227,
653
+ 230,
654
+ 233,
655
+ 234,
656
+ 235,
657
+ 238,
658
+ 242,
659
+ 250,
660
+ 251,
661
+ 255
662
+ ],
663
+ "10": [
664
+ 0,
665
+ 1,
666
+ 2,
667
+ 4,
668
+ 9,
669
+ 11,
670
+ 13,
671
+ 16,
672
+ 17,
673
+ 19,
674
+ 27,
675
+ 29,
676
+ 32,
677
+ 34,
678
+ 35,
679
+ 42,
680
+ 54,
681
+ 67,
682
+ 76,
683
+ 77,
684
+ 78,
685
+ 79,
686
+ 84,
687
+ 91,
688
+ 97,
689
+ 99,
690
+ 101,
691
+ 104,
692
+ 110,
693
+ 112,
694
+ 117,
695
+ 128,
696
+ 132,
697
+ 139,
698
+ 147,
699
+ 149,
700
+ 154,
701
+ 155,
702
+ 156,
703
+ 158,
704
+ 164,
705
+ 165,
706
+ 167,
707
+ 172,
708
+ 176,
709
+ 184,
710
+ 192,
711
+ 194,
712
+ 195,
713
+ 197,
714
+ 204,
715
+ 207,
716
+ 208,
717
+ 210,
718
+ 211,
719
+ 213,
720
+ 224,
721
+ 227,
722
+ 238,
723
+ 242,
724
+ 245,
725
+ 248,
726
+ 250,
727
+ 252
728
+ ],
729
+ "11": [
730
+ 1,
731
+ 2,
732
+ 5,
733
+ 27,
734
+ 29,
735
+ 36,
736
+ 40,
737
+ 51,
738
+ 62,
739
+ 63,
740
+ 64,
741
+ 70,
742
+ 71,
743
+ 72,
744
+ 77,
745
+ 80,
746
+ 83,
747
+ 86,
748
+ 96,
749
+ 104,
750
+ 111,
751
+ 117,
752
+ 119,
753
+ 123,
754
+ 125,
755
+ 130,
756
+ 138,
757
+ 145,
758
+ 149,
759
+ 153,
760
+ 155,
761
+ 157,
762
+ 160,
763
+ 167,
764
+ 172,
765
+ 174,
766
+ 175,
767
+ 176,
768
+ 177,
769
+ 179,
770
+ 184,
771
+ 189,
772
+ 194,
773
+ 196,
774
+ 205,
775
+ 206,
776
+ 210,
777
+ 212,
778
+ 213,
779
+ 214,
780
+ 215,
781
+ 220,
782
+ 225,
783
+ 226,
784
+ 229,
785
+ 232,
786
+ 234,
787
+ 235,
788
+ 236,
789
+ 238,
790
+ 245,
791
+ 246,
792
+ 253,
793
+ 255
794
+ ],
795
+ "12": [
796
+ 2,
797
+ 6,
798
+ 9,
799
+ 17,
800
+ 19,
801
+ 22,
802
+ 30,
803
+ 33,
804
+ 34,
805
+ 36,
806
+ 65,
807
+ 69,
808
+ 72,
809
+ 77,
810
+ 78,
811
+ 82,
812
+ 83,
813
+ 84,
814
+ 85,
815
+ 86,
816
+ 90,
817
+ 92,
818
+ 95,
819
+ 98,
820
+ 102,
821
+ 106,
822
+ 110,
823
+ 113,
824
+ 115,
825
+ 117,
826
+ 119,
827
+ 120,
828
+ 121,
829
+ 122,
830
+ 125,
831
+ 129,
832
+ 130,
833
+ 131,
834
+ 139,
835
+ 144,
836
+ 148,
837
+ 154,
838
+ 170,
839
+ 176,
840
+ 180,
841
+ 188,
842
+ 195,
843
+ 196,
844
+ 201,
845
+ 206,
846
+ 208,
847
+ 210,
848
+ 212,
849
+ 213,
850
+ 214,
851
+ 216,
852
+ 217,
853
+ 229,
854
+ 230,
855
+ 231,
856
+ 238,
857
+ 243,
858
+ 249,
859
+ 250
860
+ ],
861
+ "13": [
862
+ 0,
863
+ 1,
864
+ 6,
865
+ 8,
866
+ 9,
867
+ 13,
868
+ 16,
869
+ 18,
870
+ 19,
871
+ 23,
872
+ 25,
873
+ 26,
874
+ 33,
875
+ 37,
876
+ 43,
877
+ 46,
878
+ 49,
879
+ 51,
880
+ 55,
881
+ 56,
882
+ 60,
883
+ 61,
884
+ 63,
885
+ 66,
886
+ 67,
887
+ 68,
888
+ 81,
889
+ 83,
890
+ 88,
891
+ 89,
892
+ 92,
893
+ 94,
894
+ 95,
895
+ 96,
896
+ 103,
897
+ 106,
898
+ 110,
899
+ 123,
900
+ 124,
901
+ 127,
902
+ 138,
903
+ 139,
904
+ 148,
905
+ 151,
906
+ 153,
907
+ 156,
908
+ 160,
909
+ 178,
910
+ 180,
911
+ 190,
912
+ 192,
913
+ 195,
914
+ 196,
915
+ 200,
916
+ 211,
917
+ 218,
918
+ 220,
919
+ 221,
920
+ 224,
921
+ 233,
922
+ 236,
923
+ 251,
924
+ 253,
925
+ 255
926
+ ],
927
+ "14": [
928
+ 5,
929
+ 7,
930
+ 21,
931
+ 28,
932
+ 29,
933
+ 42,
934
+ 46,
935
+ 47,
936
+ 58,
937
+ 61,
938
+ 62,
939
+ 65,
940
+ 66,
941
+ 67,
942
+ 73,
943
+ 74,
944
+ 75,
945
+ 80,
946
+ 82,
947
+ 88,
948
+ 91,
949
+ 92,
950
+ 95,
951
+ 96,
952
+ 98,
953
+ 101,
954
+ 103,
955
+ 105,
956
+ 110,
957
+ 111,
958
+ 120,
959
+ 121,
960
+ 129,
961
+ 131,
962
+ 133,
963
+ 138,
964
+ 139,
965
+ 142,
966
+ 143,
967
+ 144,
968
+ 148,
969
+ 152,
970
+ 153,
971
+ 161,
972
+ 162,
973
+ 166,
974
+ 167,
975
+ 181,
976
+ 182,
977
+ 189,
978
+ 192,
979
+ 198,
980
+ 204,
981
+ 205,
982
+ 207,
983
+ 210,
984
+ 230,
985
+ 231,
986
+ 239,
987
+ 240,
988
+ 243,
989
+ 251,
990
+ 254,
991
+ 255
992
+ ],
993
+ "15": [
994
+ 8,
995
+ 10,
996
+ 14,
997
+ 16,
998
+ 20,
999
+ 24,
1000
+ 26,
1001
+ 28,
1002
+ 30,
1003
+ 32,
1004
+ 34,
1005
+ 36,
1006
+ 40,
1007
+ 42,
1008
+ 43,
1009
+ 48,
1010
+ 54,
1011
+ 55,
1012
+ 58,
1013
+ 67,
1014
+ 70,
1015
+ 71,
1016
+ 77,
1017
+ 78,
1018
+ 79,
1019
+ 93,
1020
+ 94,
1021
+ 99,
1022
+ 105,
1023
+ 107,
1024
+ 111,
1025
+ 112,
1026
+ 114,
1027
+ 115,
1028
+ 116,
1029
+ 118,
1030
+ 123,
1031
+ 128,
1032
+ 133,
1033
+ 135,
1034
+ 142,
1035
+ 143,
1036
+ 150,
1037
+ 156,
1038
+ 157,
1039
+ 160,
1040
+ 163,
1041
+ 165,
1042
+ 169,
1043
+ 195,
1044
+ 197,
1045
+ 199,
1046
+ 201,
1047
+ 207,
1048
+ 208,
1049
+ 216,
1050
+ 229,
1051
+ 231,
1052
+ 237,
1053
+ 239,
1054
+ 249,
1055
+ 250,
1056
+ 252,
1057
+ 255
1058
+ ],
1059
+ "16": [
1060
+ 10,
1061
+ 15,
1062
+ 21,
1063
+ 23,
1064
+ 26,
1065
+ 27,
1066
+ 29,
1067
+ 32,
1068
+ 35,
1069
+ 38,
1070
+ 42,
1071
+ 43,
1072
+ 46,
1073
+ 53,
1074
+ 54,
1075
+ 55,
1076
+ 56,
1077
+ 61,
1078
+ 63,
1079
+ 64,
1080
+ 71,
1081
+ 73,
1082
+ 74,
1083
+ 75,
1084
+ 83,
1085
+ 86,
1086
+ 87,
1087
+ 91,
1088
+ 99,
1089
+ 103,
1090
+ 109,
1091
+ 116,
1092
+ 121,
1093
+ 123,
1094
+ 126,
1095
+ 129,
1096
+ 136,
1097
+ 139,
1098
+ 142,
1099
+ 143,
1100
+ 151,
1101
+ 157,
1102
+ 165,
1103
+ 170,
1104
+ 171,
1105
+ 178,
1106
+ 188,
1107
+ 197,
1108
+ 200,
1109
+ 202,
1110
+ 204,
1111
+ 207,
1112
+ 213,
1113
+ 214,
1114
+ 217,
1115
+ 223,
1116
+ 225,
1117
+ 230,
1118
+ 240,
1119
+ 241,
1120
+ 244,
1121
+ 248,
1122
+ 249,
1123
+ 252
1124
+ ],
1125
+ "17": [
1126
+ 0,
1127
+ 4,
1128
+ 5,
1129
+ 9,
1130
+ 11,
1131
+ 12,
1132
+ 14,
1133
+ 15,
1134
+ 16,
1135
+ 19,
1136
+ 21,
1137
+ 29,
1138
+ 31,
1139
+ 43,
1140
+ 44,
1141
+ 49,
1142
+ 50,
1143
+ 55,
1144
+ 68,
1145
+ 74,
1146
+ 75,
1147
+ 76,
1148
+ 79,
1149
+ 80,
1150
+ 82,
1151
+ 83,
1152
+ 85,
1153
+ 94,
1154
+ 101,
1155
+ 104,
1156
+ 110,
1157
+ 112,
1158
+ 120,
1159
+ 121,
1160
+ 122,
1161
+ 123,
1162
+ 125,
1163
+ 143,
1164
+ 148,
1165
+ 163,
1166
+ 166,
1167
+ 168,
1168
+ 174,
1169
+ 184,
1170
+ 185,
1171
+ 188,
1172
+ 196,
1173
+ 202,
1174
+ 203,
1175
+ 208,
1176
+ 212,
1177
+ 213,
1178
+ 216,
1179
+ 217,
1180
+ 220,
1181
+ 222,
1182
+ 224,
1183
+ 227,
1184
+ 230,
1185
+ 235,
1186
+ 246,
1187
+ 249,
1188
+ 252,
1189
+ 254
1190
+ ],
1191
+ "18": [
1192
+ 0,
1193
+ 10,
1194
+ 11,
1195
+ 12,
1196
+ 15,
1197
+ 22,
1198
+ 23,
1199
+ 45,
1200
+ 47,
1201
+ 49,
1202
+ 50,
1203
+ 51,
1204
+ 52,
1205
+ 58,
1206
+ 59,
1207
+ 62,
1208
+ 66,
1209
+ 70,
1210
+ 76,
1211
+ 77,
1212
+ 84,
1213
+ 85,
1214
+ 94,
1215
+ 95,
1216
+ 97,
1217
+ 100,
1218
+ 102,
1219
+ 104,
1220
+ 106,
1221
+ 108,
1222
+ 115,
1223
+ 117,
1224
+ 120,
1225
+ 126,
1226
+ 137,
1227
+ 139,
1228
+ 141,
1229
+ 147,
1230
+ 149,
1231
+ 159,
1232
+ 160,
1233
+ 166,
1234
+ 169,
1235
+ 172,
1236
+ 180,
1237
+ 181,
1238
+ 196,
1239
+ 199,
1240
+ 201,
1241
+ 209,
1242
+ 218,
1243
+ 219,
1244
+ 221,
1245
+ 222,
1246
+ 229,
1247
+ 230,
1248
+ 234,
1249
+ 236,
1250
+ 240,
1251
+ 244,
1252
+ 246,
1253
+ 249,
1254
+ 252,
1255
+ 253
1256
+ ],
1257
+ "19": [
1258
+ 3,
1259
+ 4,
1260
+ 5,
1261
+ 6,
1262
+ 8,
1263
+ 11,
1264
+ 13,
1265
+ 15,
1266
+ 20,
1267
+ 32,
1268
+ 33,
1269
+ 36,
1270
+ 39,
1271
+ 41,
1272
+ 43,
1273
+ 47,
1274
+ 49,
1275
+ 51,
1276
+ 55,
1277
+ 56,
1278
+ 59,
1279
+ 77,
1280
+ 80,
1281
+ 82,
1282
+ 86,
1283
+ 90,
1284
+ 105,
1285
+ 106,
1286
+ 110,
1287
+ 112,
1288
+ 113,
1289
+ 118,
1290
+ 120,
1291
+ 121,
1292
+ 128,
1293
+ 129,
1294
+ 142,
1295
+ 152,
1296
+ 155,
1297
+ 157,
1298
+ 165,
1299
+ 166,
1300
+ 167,
1301
+ 171,
1302
+ 173,
1303
+ 176,
1304
+ 177,
1305
+ 192,
1306
+ 193,
1307
+ 199,
1308
+ 201,
1309
+ 202,
1310
+ 203,
1311
+ 212,
1312
+ 224,
1313
+ 225,
1314
+ 233,
1315
+ 234,
1316
+ 235,
1317
+ 236,
1318
+ 243,
1319
+ 244,
1320
+ 251,
1321
+ 252
1322
+ ],
1323
+ "20": [
1324
+ 0,
1325
+ 4,
1326
+ 5,
1327
+ 9,
1328
+ 10,
1329
+ 12,
1330
+ 13,
1331
+ 15,
1332
+ 18,
1333
+ 25,
1334
+ 27,
1335
+ 29,
1336
+ 31,
1337
+ 32,
1338
+ 33,
1339
+ 34,
1340
+ 38,
1341
+ 40,
1342
+ 49,
1343
+ 50,
1344
+ 53,
1345
+ 54,
1346
+ 60,
1347
+ 68,
1348
+ 72,
1349
+ 78,
1350
+ 84,
1351
+ 86,
1352
+ 87,
1353
+ 90,
1354
+ 94,
1355
+ 96,
1356
+ 99,
1357
+ 104,
1358
+ 110,
1359
+ 111,
1360
+ 126,
1361
+ 127,
1362
+ 129,
1363
+ 132,
1364
+ 136,
1365
+ 137,
1366
+ 141,
1367
+ 145,
1368
+ 147,
1369
+ 148,
1370
+ 149,
1371
+ 150,
1372
+ 161,
1373
+ 163,
1374
+ 181,
1375
+ 183,
1376
+ 196,
1377
+ 197,
1378
+ 198,
1379
+ 212,
1380
+ 213,
1381
+ 218,
1382
+ 229,
1383
+ 235,
1384
+ 238,
1385
+ 244,
1386
+ 247,
1387
+ 248
1388
+ ],
1389
+ "21": [
1390
+ 0,
1391
+ 4,
1392
+ 6,
1393
+ 8,
1394
+ 10,
1395
+ 28,
1396
+ 29,
1397
+ 32,
1398
+ 39,
1399
+ 44,
1400
+ 45,
1401
+ 47,
1402
+ 48,
1403
+ 49,
1404
+ 56,
1405
+ 60,
1406
+ 61,
1407
+ 67,
1408
+ 72,
1409
+ 73,
1410
+ 81,
1411
+ 82,
1412
+ 87,
1413
+ 89,
1414
+ 92,
1415
+ 93,
1416
+ 104,
1417
+ 113,
1418
+ 114,
1419
+ 115,
1420
+ 119,
1421
+ 126,
1422
+ 131,
1423
+ 132,
1424
+ 142,
1425
+ 146,
1426
+ 148,
1427
+ 155,
1428
+ 156,
1429
+ 157,
1430
+ 158,
1431
+ 160,
1432
+ 161,
1433
+ 162,
1434
+ 163,
1435
+ 179,
1436
+ 188,
1437
+ 194,
1438
+ 196,
1439
+ 198,
1440
+ 200,
1441
+ 204,
1442
+ 206,
1443
+ 207,
1444
+ 211,
1445
+ 215,
1446
+ 224,
1447
+ 230,
1448
+ 233,
1449
+ 237,
1450
+ 239,
1451
+ 241,
1452
+ 243,
1453
+ 251
1454
+ ],
1455
+ "22": [
1456
+ 4,
1457
+ 9,
1458
+ 10,
1459
+ 12,
1460
+ 16,
1461
+ 24,
1462
+ 25,
1463
+ 26,
1464
+ 29,
1465
+ 39,
1466
+ 47,
1467
+ 52,
1468
+ 56,
1469
+ 57,
1470
+ 70,
1471
+ 73,
1472
+ 77,
1473
+ 78,
1474
+ 82,
1475
+ 84,
1476
+ 86,
1477
+ 95,
1478
+ 96,
1479
+ 102,
1480
+ 103,
1481
+ 106,
1482
+ 107,
1483
+ 110,
1484
+ 112,
1485
+ 115,
1486
+ 130,
1487
+ 134,
1488
+ 140,
1489
+ 141,
1490
+ 147,
1491
+ 156,
1492
+ 158,
1493
+ 161,
1494
+ 164,
1495
+ 166,
1496
+ 171,
1497
+ 177,
1498
+ 183,
1499
+ 187,
1500
+ 188,
1501
+ 190,
1502
+ 191,
1503
+ 193,
1504
+ 196,
1505
+ 197,
1506
+ 199,
1507
+ 203,
1508
+ 208,
1509
+ 213,
1510
+ 217,
1511
+ 218,
1512
+ 225,
1513
+ 227,
1514
+ 233,
1515
+ 245,
1516
+ 246,
1517
+ 247,
1518
+ 248,
1519
+ 255
1520
+ ],
1521
+ "23": [
1522
+ 2,
1523
+ 5,
1524
+ 11,
1525
+ 17,
1526
+ 19,
1527
+ 26,
1528
+ 29,
1529
+ 34,
1530
+ 40,
1531
+ 42,
1532
+ 54,
1533
+ 55,
1534
+ 56,
1535
+ 60,
1536
+ 62,
1537
+ 67,
1538
+ 70,
1539
+ 72,
1540
+ 74,
1541
+ 79,
1542
+ 82,
1543
+ 85,
1544
+ 90,
1545
+ 92,
1546
+ 94,
1547
+ 96,
1548
+ 97,
1549
+ 98,
1550
+ 101,
1551
+ 103,
1552
+ 122,
1553
+ 126,
1554
+ 133,
1555
+ 134,
1556
+ 139,
1557
+ 140,
1558
+ 141,
1559
+ 142,
1560
+ 146,
1561
+ 150,
1562
+ 154,
1563
+ 157,
1564
+ 162,
1565
+ 167,
1566
+ 177,
1567
+ 178,
1568
+ 179,
1569
+ 182,
1570
+ 194,
1571
+ 199,
1572
+ 205,
1573
+ 208,
1574
+ 210,
1575
+ 211,
1576
+ 212,
1577
+ 217,
1578
+ 219,
1579
+ 224,
1580
+ 231,
1581
+ 233,
1582
+ 240,
1583
+ 241,
1584
+ 249,
1585
+ 251
1586
+ ],
1587
+ "24": [
1588
+ 2,
1589
+ 14,
1590
+ 20,
1591
+ 23,
1592
+ 29,
1593
+ 34,
1594
+ 35,
1595
+ 39,
1596
+ 42,
1597
+ 44,
1598
+ 53,
1599
+ 55,
1600
+ 56,
1601
+ 58,
1602
+ 61,
1603
+ 64,
1604
+ 65,
1605
+ 66,
1606
+ 67,
1607
+ 71,
1608
+ 73,
1609
+ 74,
1610
+ 75,
1611
+ 80,
1612
+ 84,
1613
+ 89,
1614
+ 98,
1615
+ 102,
1616
+ 120,
1617
+ 124,
1618
+ 132,
1619
+ 136,
1620
+ 141,
1621
+ 144,
1622
+ 146,
1623
+ 148,
1624
+ 149,
1625
+ 154,
1626
+ 162,
1627
+ 165,
1628
+ 168,
1629
+ 170,
1630
+ 172,
1631
+ 177,
1632
+ 179,
1633
+ 182,
1634
+ 183,
1635
+ 189,
1636
+ 191,
1637
+ 195,
1638
+ 196,
1639
+ 198,
1640
+ 202,
1641
+ 206,
1642
+ 211,
1643
+ 213,
1644
+ 218,
1645
+ 224,
1646
+ 232,
1647
+ 235,
1648
+ 236,
1649
+ 237,
1650
+ 240,
1651
+ 254
1652
+ ],
1653
+ "25": [
1654
+ 1,
1655
+ 2,
1656
+ 8,
1657
+ 11,
1658
+ 13,
1659
+ 17,
1660
+ 29,
1661
+ 33,
1662
+ 35,
1663
+ 37,
1664
+ 42,
1665
+ 49,
1666
+ 52,
1667
+ 58,
1668
+ 59,
1669
+ 60,
1670
+ 66,
1671
+ 80,
1672
+ 82,
1673
+ 84,
1674
+ 86,
1675
+ 87,
1676
+ 95,
1677
+ 101,
1678
+ 105,
1679
+ 107,
1680
+ 108,
1681
+ 115,
1682
+ 117,
1683
+ 121,
1684
+ 122,
1685
+ 130,
1686
+ 135,
1687
+ 136,
1688
+ 142,
1689
+ 149,
1690
+ 150,
1691
+ 151,
1692
+ 153,
1693
+ 154,
1694
+ 158,
1695
+ 159,
1696
+ 160,
1697
+ 162,
1698
+ 164,
1699
+ 169,
1700
+ 172,
1701
+ 181,
1702
+ 183,
1703
+ 188,
1704
+ 192,
1705
+ 197,
1706
+ 198,
1707
+ 209,
1708
+ 225,
1709
+ 227,
1710
+ 233,
1711
+ 234,
1712
+ 237,
1713
+ 238,
1714
+ 243,
1715
+ 250,
1716
+ 251,
1717
+ 253
1718
+ ],
1719
+ "26": [
1720
+ 4,
1721
+ 8,
1722
+ 9,
1723
+ 12,
1724
+ 13,
1725
+ 16,
1726
+ 28,
1727
+ 29,
1728
+ 34,
1729
+ 37,
1730
+ 47,
1731
+ 51,
1732
+ 52,
1733
+ 53,
1734
+ 55,
1735
+ 56,
1736
+ 58,
1737
+ 66,
1738
+ 71,
1739
+ 72,
1740
+ 74,
1741
+ 76,
1742
+ 78,
1743
+ 79,
1744
+ 81,
1745
+ 84,
1746
+ 85,
1747
+ 86,
1748
+ 90,
1749
+ 94,
1750
+ 95,
1751
+ 96,
1752
+ 98,
1753
+ 119,
1754
+ 129,
1755
+ 132,
1756
+ 135,
1757
+ 137,
1758
+ 144,
1759
+ 145,
1760
+ 149,
1761
+ 158,
1762
+ 159,
1763
+ 160,
1764
+ 164,
1765
+ 165,
1766
+ 170,
1767
+ 180,
1768
+ 184,
1769
+ 194,
1770
+ 202,
1771
+ 204,
1772
+ 208,
1773
+ 210,
1774
+ 227,
1775
+ 228,
1776
+ 232,
1777
+ 233,
1778
+ 234,
1779
+ 235,
1780
+ 237,
1781
+ 242,
1782
+ 243,
1783
+ 244
1784
+ ],
1785
+ "27": [
1786
+ 1,
1787
+ 11,
1788
+ 14,
1789
+ 20,
1790
+ 25,
1791
+ 26,
1792
+ 30,
1793
+ 31,
1794
+ 36,
1795
+ 41,
1796
+ 46,
1797
+ 48,
1798
+ 50,
1799
+ 52,
1800
+ 54,
1801
+ 58,
1802
+ 61,
1803
+ 64,
1804
+ 68,
1805
+ 71,
1806
+ 72,
1807
+ 76,
1808
+ 77,
1809
+ 82,
1810
+ 89,
1811
+ 92,
1812
+ 100,
1813
+ 101,
1814
+ 104,
1815
+ 108,
1816
+ 109,
1817
+ 117,
1818
+ 120,
1819
+ 122,
1820
+ 134,
1821
+ 139,
1822
+ 141,
1823
+ 144,
1824
+ 158,
1825
+ 162,
1826
+ 163,
1827
+ 166,
1828
+ 168,
1829
+ 173,
1830
+ 174,
1831
+ 176,
1832
+ 180,
1833
+ 184,
1834
+ 191,
1835
+ 192,
1836
+ 196,
1837
+ 198,
1838
+ 211,
1839
+ 217,
1840
+ 219,
1841
+ 220,
1842
+ 222,
1843
+ 226,
1844
+ 233,
1845
+ 237,
1846
+ 239,
1847
+ 244,
1848
+ 249,
1849
+ 251
1850
+ ],
1851
+ "28": [
1852
+ 1,
1853
+ 3,
1854
+ 4,
1855
+ 13,
1856
+ 15,
1857
+ 26,
1858
+ 29,
1859
+ 30,
1860
+ 35,
1861
+ 39,
1862
+ 41,
1863
+ 43,
1864
+ 47,
1865
+ 54,
1866
+ 55,
1867
+ 57,
1868
+ 62,
1869
+ 64,
1870
+ 76,
1871
+ 78,
1872
+ 83,
1873
+ 85,
1874
+ 87,
1875
+ 89,
1876
+ 92,
1877
+ 93,
1878
+ 97,
1879
+ 109,
1880
+ 127,
1881
+ 133,
1882
+ 134,
1883
+ 136,
1884
+ 137,
1885
+ 143,
1886
+ 145,
1887
+ 151,
1888
+ 155,
1889
+ 164,
1890
+ 165,
1891
+ 166,
1892
+ 168,
1893
+ 172,
1894
+ 173,
1895
+ 175,
1896
+ 176,
1897
+ 195,
1898
+ 198,
1899
+ 204,
1900
+ 207,
1901
+ 208,
1902
+ 216,
1903
+ 218,
1904
+ 219,
1905
+ 223,
1906
+ 224,
1907
+ 225,
1908
+ 231,
1909
+ 234,
1910
+ 235,
1911
+ 237,
1912
+ 238,
1913
+ 239,
1914
+ 243,
1915
+ 244
1916
+ ],
1917
+ "29": [
1918
+ 2,
1919
+ 3,
1920
+ 6,
1921
+ 17,
1922
+ 21,
1923
+ 27,
1924
+ 32,
1925
+ 35,
1926
+ 36,
1927
+ 40,
1928
+ 41,
1929
+ 44,
1930
+ 47,
1931
+ 49,
1932
+ 53,
1933
+ 56,
1934
+ 61,
1935
+ 62,
1936
+ 63,
1937
+ 65,
1938
+ 68,
1939
+ 70,
1940
+ 71,
1941
+ 73,
1942
+ 76,
1943
+ 80,
1944
+ 85,
1945
+ 93,
1946
+ 94,
1947
+ 102,
1948
+ 115,
1949
+ 119,
1950
+ 120,
1951
+ 121,
1952
+ 134,
1953
+ 135,
1954
+ 138,
1955
+ 145,
1956
+ 148,
1957
+ 151,
1958
+ 156,
1959
+ 171,
1960
+ 174,
1961
+ 175,
1962
+ 180,
1963
+ 189,
1964
+ 192,
1965
+ 200,
1966
+ 203,
1967
+ 206,
1968
+ 211,
1969
+ 214,
1970
+ 217,
1971
+ 223,
1972
+ 227,
1973
+ 229,
1974
+ 230,
1975
+ 233,
1976
+ 235,
1977
+ 236,
1978
+ 240,
1979
+ 248,
1980
+ 249,
1981
+ 251
1982
+ ],
1983
+ "30": [
1984
+ 0,
1985
+ 1,
1986
+ 2,
1987
+ 10,
1988
+ 11,
1989
+ 12,
1990
+ 13,
1991
+ 18,
1992
+ 20,
1993
+ 28,
1994
+ 30,
1995
+ 38,
1996
+ 41,
1997
+ 48,
1998
+ 52,
1999
+ 53,
2000
+ 56,
2001
+ 64,
2002
+ 65,
2003
+ 66,
2004
+ 69,
2005
+ 70,
2006
+ 73,
2007
+ 85,
2008
+ 96,
2009
+ 99,
2010
+ 102,
2011
+ 104,
2012
+ 112,
2013
+ 117,
2014
+ 120,
2015
+ 127,
2016
+ 129,
2017
+ 132,
2018
+ 133,
2019
+ 137,
2020
+ 140,
2021
+ 144,
2022
+ 146,
2023
+ 152,
2024
+ 160,
2025
+ 165,
2026
+ 175,
2027
+ 177,
2028
+ 179,
2029
+ 184,
2030
+ 188,
2031
+ 189,
2032
+ 197,
2033
+ 207,
2034
+ 211,
2035
+ 212,
2036
+ 215,
2037
+ 223,
2038
+ 224,
2039
+ 226,
2040
+ 228,
2041
+ 230,
2042
+ 231,
2043
+ 238,
2044
+ 241,
2045
+ 251,
2046
+ 252,
2047
+ 254
2048
+ ],
2049
+ "31": [
2050
+ 2,
2051
+ 3,
2052
+ 5,
2053
+ 17,
2054
+ 25,
2055
+ 27,
2056
+ 29,
2057
+ 30,
2058
+ 32,
2059
+ 33,
2060
+ 34,
2061
+ 35,
2062
+ 39,
2063
+ 40,
2064
+ 41,
2065
+ 46,
2066
+ 49,
2067
+ 50,
2068
+ 51,
2069
+ 61,
2070
+ 67,
2071
+ 70,
2072
+ 76,
2073
+ 79,
2074
+ 82,
2075
+ 84,
2076
+ 87,
2077
+ 90,
2078
+ 91,
2079
+ 92,
2080
+ 106,
2081
+ 109,
2082
+ 115,
2083
+ 117,
2084
+ 124,
2085
+ 125,
2086
+ 130,
2087
+ 133,
2088
+ 140,
2089
+ 142,
2090
+ 145,
2091
+ 146,
2092
+ 150,
2093
+ 154,
2094
+ 165,
2095
+ 169,
2096
+ 173,
2097
+ 177,
2098
+ 181,
2099
+ 192,
2100
+ 197,
2101
+ 198,
2102
+ 199,
2103
+ 200,
2104
+ 209,
2105
+ 213,
2106
+ 223,
2107
+ 225,
2108
+ 229,
2109
+ 235,
2110
+ 238,
2111
+ 240,
2112
+ 244,
2113
+ 250
2114
+ ],
2115
+ "32": [
2116
+ 5,
2117
+ 6,
2118
+ 8,
2119
+ 9,
2120
+ 11,
2121
+ 12,
2122
+ 13,
2123
+ 14,
2124
+ 19,
2125
+ 28,
2126
+ 30,
2127
+ 31,
2128
+ 37,
2129
+ 41,
2130
+ 46,
2131
+ 51,
2132
+ 54,
2133
+ 55,
2134
+ 58,
2135
+ 60,
2136
+ 64,
2137
+ 70,
2138
+ 71,
2139
+ 78,
2140
+ 81,
2141
+ 93,
2142
+ 94,
2143
+ 100,
2144
+ 101,
2145
+ 103,
2146
+ 112,
2147
+ 114,
2148
+ 118,
2149
+ 120,
2150
+ 123,
2151
+ 129,
2152
+ 130,
2153
+ 132,
2154
+ 135,
2155
+ 137,
2156
+ 143,
2157
+ 144,
2158
+ 153,
2159
+ 155,
2160
+ 166,
2161
+ 170,
2162
+ 171,
2163
+ 184,
2164
+ 185,
2165
+ 187,
2166
+ 189,
2167
+ 191,
2168
+ 194,
2169
+ 195,
2170
+ 196,
2171
+ 198,
2172
+ 201,
2173
+ 210,
2174
+ 215,
2175
+ 229,
2176
+ 237,
2177
+ 248,
2178
+ 251,
2179
+ 252
2180
+ ],
2181
+ "33": [
2182
+ 0,
2183
+ 4,
2184
+ 6,
2185
+ 11,
2186
+ 13,
2187
+ 16,
2188
+ 22,
2189
+ 26,
2190
+ 30,
2191
+ 37,
2192
+ 41,
2193
+ 43,
2194
+ 46,
2195
+ 50,
2196
+ 51,
2197
+ 58,
2198
+ 61,
2199
+ 64,
2200
+ 65,
2201
+ 66,
2202
+ 69,
2203
+ 75,
2204
+ 77,
2205
+ 78,
2206
+ 82,
2207
+ 84,
2208
+ 88,
2209
+ 108,
2210
+ 110,
2211
+ 113,
2212
+ 115,
2213
+ 119,
2214
+ 123,
2215
+ 125,
2216
+ 127,
2217
+ 132,
2218
+ 133,
2219
+ 140,
2220
+ 143,
2221
+ 145,
2222
+ 149,
2223
+ 153,
2224
+ 155,
2225
+ 157,
2226
+ 159,
2227
+ 161,
2228
+ 162,
2229
+ 168,
2230
+ 169,
2231
+ 172,
2232
+ 178,
2233
+ 180,
2234
+ 190,
2235
+ 197,
2236
+ 206,
2237
+ 214,
2238
+ 216,
2239
+ 224,
2240
+ 227,
2241
+ 228,
2242
+ 232,
2243
+ 247,
2244
+ 254,
2245
+ 255
2246
+ ],
2247
+ "34": [
2248
+ 6,
2249
+ 8,
2250
+ 9,
2251
+ 14,
2252
+ 15,
2253
+ 28,
2254
+ 31,
2255
+ 33,
2256
+ 37,
2257
+ 38,
2258
+ 41,
2259
+ 47,
2260
+ 51,
2261
+ 60,
2262
+ 65,
2263
+ 67,
2264
+ 71,
2265
+ 72,
2266
+ 74,
2267
+ 81,
2268
+ 85,
2269
+ 88,
2270
+ 100,
2271
+ 101,
2272
+ 106,
2273
+ 116,
2274
+ 117,
2275
+ 124,
2276
+ 126,
2277
+ 127,
2278
+ 131,
2279
+ 133,
2280
+ 135,
2281
+ 137,
2282
+ 139,
2283
+ 140,
2284
+ 150,
2285
+ 152,
2286
+ 165,
2287
+ 167,
2288
+ 170,
2289
+ 174,
2290
+ 179,
2291
+ 183,
2292
+ 188,
2293
+ 189,
2294
+ 191,
2295
+ 197,
2296
+ 198,
2297
+ 202,
2298
+ 203,
2299
+ 204,
2300
+ 213,
2301
+ 216,
2302
+ 221,
2303
+ 231,
2304
+ 238,
2305
+ 240,
2306
+ 248,
2307
+ 249,
2308
+ 250,
2309
+ 252,
2310
+ 253,
2311
+ 254
2312
+ ],
2313
+ "35": [
2314
+ 3,
2315
+ 6,
2316
+ 12,
2317
+ 17,
2318
+ 20,
2319
+ 23,
2320
+ 24,
2321
+ 30,
2322
+ 31,
2323
+ 38,
2324
+ 40,
2325
+ 41,
2326
+ 45,
2327
+ 49,
2328
+ 50,
2329
+ 56,
2330
+ 63,
2331
+ 67,
2332
+ 69,
2333
+ 73,
2334
+ 74,
2335
+ 77,
2336
+ 79,
2337
+ 85,
2338
+ 86,
2339
+ 89,
2340
+ 91,
2341
+ 93,
2342
+ 95,
2343
+ 100,
2344
+ 102,
2345
+ 106,
2346
+ 108,
2347
+ 113,
2348
+ 115,
2349
+ 125,
2350
+ 127,
2351
+ 134,
2352
+ 136,
2353
+ 140,
2354
+ 143,
2355
+ 148,
2356
+ 153,
2357
+ 159,
2358
+ 161,
2359
+ 163,
2360
+ 164,
2361
+ 169,
2362
+ 180,
2363
+ 181,
2364
+ 195,
2365
+ 196,
2366
+ 210,
2367
+ 211,
2368
+ 223,
2369
+ 224,
2370
+ 227,
2371
+ 231,
2372
+ 238,
2373
+ 241,
2374
+ 245,
2375
+ 248,
2376
+ 251,
2377
+ 255
2378
+ ],
2379
+ "36": [
2380
+ 4,
2381
+ 6,
2382
+ 11,
2383
+ 19,
2384
+ 26,
2385
+ 33,
2386
+ 42,
2387
+ 48,
2388
+ 51,
2389
+ 56,
2390
+ 57,
2391
+ 59,
2392
+ 60,
2393
+ 61,
2394
+ 64,
2395
+ 70,
2396
+ 74,
2397
+ 77,
2398
+ 83,
2399
+ 88,
2400
+ 92,
2401
+ 95,
2402
+ 100,
2403
+ 103,
2404
+ 108,
2405
+ 109,
2406
+ 111,
2407
+ 123,
2408
+ 131,
2409
+ 132,
2410
+ 141,
2411
+ 145,
2412
+ 146,
2413
+ 148,
2414
+ 149,
2415
+ 151,
2416
+ 153,
2417
+ 154,
2418
+ 155,
2419
+ 158,
2420
+ 161,
2421
+ 168,
2422
+ 169,
2423
+ 170,
2424
+ 171,
2425
+ 177,
2426
+ 184,
2427
+ 186,
2428
+ 188,
2429
+ 190,
2430
+ 197,
2431
+ 201,
2432
+ 202,
2433
+ 203,
2434
+ 209,
2435
+ 211,
2436
+ 212,
2437
+ 214,
2438
+ 215,
2439
+ 216,
2440
+ 228,
2441
+ 249,
2442
+ 252,
2443
+ 254
2444
+ ],
2445
+ "37": [
2446
+ 3,
2447
+ 5,
2448
+ 8,
2449
+ 11,
2450
+ 13,
2451
+ 14,
2452
+ 22,
2453
+ 24,
2454
+ 33,
2455
+ 36,
2456
+ 46,
2457
+ 51,
2458
+ 59,
2459
+ 60,
2460
+ 67,
2461
+ 70,
2462
+ 79,
2463
+ 82,
2464
+ 83,
2465
+ 85,
2466
+ 93,
2467
+ 95,
2468
+ 105,
2469
+ 111,
2470
+ 113,
2471
+ 117,
2472
+ 118,
2473
+ 125,
2474
+ 128,
2475
+ 133,
2476
+ 136,
2477
+ 141,
2478
+ 142,
2479
+ 143,
2480
+ 145,
2481
+ 151,
2482
+ 153,
2483
+ 154,
2484
+ 155,
2485
+ 161,
2486
+ 162,
2487
+ 163,
2488
+ 166,
2489
+ 171,
2490
+ 172,
2491
+ 180,
2492
+ 181,
2493
+ 184,
2494
+ 188,
2495
+ 189,
2496
+ 192,
2497
+ 197,
2498
+ 200,
2499
+ 212,
2500
+ 219,
2501
+ 220,
2502
+ 225,
2503
+ 227,
2504
+ 232,
2505
+ 237,
2506
+ 239,
2507
+ 246,
2508
+ 252,
2509
+ 254
2510
+ ],
2511
+ "38": [
2512
+ 0,
2513
+ 2,
2514
+ 6,
2515
+ 10,
2516
+ 15,
2517
+ 17,
2518
+ 22,
2519
+ 24,
2520
+ 28,
2521
+ 30,
2522
+ 37,
2523
+ 39,
2524
+ 41,
2525
+ 42,
2526
+ 47,
2527
+ 50,
2528
+ 51,
2529
+ 53,
2530
+ 60,
2531
+ 67,
2532
+ 68,
2533
+ 76,
2534
+ 78,
2535
+ 89,
2536
+ 91,
2537
+ 97,
2538
+ 98,
2539
+ 102,
2540
+ 105,
2541
+ 107,
2542
+ 108,
2543
+ 121,
2544
+ 123,
2545
+ 132,
2546
+ 138,
2547
+ 145,
2548
+ 147,
2549
+ 152,
2550
+ 153,
2551
+ 157,
2552
+ 159,
2553
+ 162,
2554
+ 164,
2555
+ 168,
2556
+ 178,
2557
+ 181,
2558
+ 183,
2559
+ 185,
2560
+ 187,
2561
+ 189,
2562
+ 199,
2563
+ 204,
2564
+ 207,
2565
+ 210,
2566
+ 214,
2567
+ 223,
2568
+ 225,
2569
+ 227,
2570
+ 228,
2571
+ 235,
2572
+ 239,
2573
+ 244,
2574
+ 245,
2575
+ 249
2576
+ ],
2577
+ "39": [
2578
+ 1,
2579
+ 7,
2580
+ 9,
2581
+ 10,
2582
+ 12,
2583
+ 13,
2584
+ 14,
2585
+ 16,
2586
+ 17,
2587
+ 19,
2588
+ 21,
2589
+ 22,
2590
+ 26,
2591
+ 32,
2592
+ 33,
2593
+ 37,
2594
+ 46,
2595
+ 58,
2596
+ 61,
2597
+ 62,
2598
+ 70,
2599
+ 71,
2600
+ 80,
2601
+ 86,
2602
+ 88,
2603
+ 102,
2604
+ 103,
2605
+ 104,
2606
+ 112,
2607
+ 114,
2608
+ 123,
2609
+ 125,
2610
+ 126,
2611
+ 127,
2612
+ 139,
2613
+ 141,
2614
+ 142,
2615
+ 146,
2616
+ 148,
2617
+ 153,
2618
+ 155,
2619
+ 161,
2620
+ 162,
2621
+ 168,
2622
+ 169,
2623
+ 177,
2624
+ 183,
2625
+ 184,
2626
+ 190,
2627
+ 196,
2628
+ 198,
2629
+ 199,
2630
+ 203,
2631
+ 206,
2632
+ 210,
2633
+ 212,
2634
+ 214,
2635
+ 221,
2636
+ 225,
2637
+ 230,
2638
+ 244,
2639
+ 247,
2640
+ 250,
2641
+ 253
2642
+ ],
2643
+ "40": [
2644
+ 2,
2645
+ 8,
2646
+ 10,
2647
+ 11,
2648
+ 26,
2649
+ 27,
2650
+ 28,
2651
+ 30,
2652
+ 37,
2653
+ 39,
2654
+ 43,
2655
+ 47,
2656
+ 50,
2657
+ 53,
2658
+ 56,
2659
+ 57,
2660
+ 59,
2661
+ 68,
2662
+ 74,
2663
+ 75,
2664
+ 76,
2665
+ 77,
2666
+ 88,
2667
+ 89,
2668
+ 93,
2669
+ 97,
2670
+ 99,
2671
+ 101,
2672
+ 103,
2673
+ 106,
2674
+ 111,
2675
+ 112,
2676
+ 119,
2677
+ 122,
2678
+ 123,
2679
+ 127,
2680
+ 128,
2681
+ 133,
2682
+ 137,
2683
+ 143,
2684
+ 145,
2685
+ 157,
2686
+ 168,
2687
+ 169,
2688
+ 171,
2689
+ 175,
2690
+ 177,
2691
+ 184,
2692
+ 188,
2693
+ 189,
2694
+ 191,
2695
+ 192,
2696
+ 194,
2697
+ 196,
2698
+ 197,
2699
+ 205,
2700
+ 227,
2701
+ 230,
2702
+ 237,
2703
+ 240,
2704
+ 244,
2705
+ 245,
2706
+ 251,
2707
+ 254
2708
+ ],
2709
+ "41": [
2710
+ 2,
2711
+ 7,
2712
+ 9,
2713
+ 10,
2714
+ 11,
2715
+ 12,
2716
+ 13,
2717
+ 16,
2718
+ 17,
2719
+ 18,
2720
+ 19,
2721
+ 25,
2722
+ 27,
2723
+ 29,
2724
+ 34,
2725
+ 37,
2726
+ 41,
2727
+ 42,
2728
+ 44,
2729
+ 57,
2730
+ 66,
2731
+ 73,
2732
+ 74,
2733
+ 80,
2734
+ 85,
2735
+ 89,
2736
+ 90,
2737
+ 99,
2738
+ 110,
2739
+ 111,
2740
+ 113,
2741
+ 115,
2742
+ 120,
2743
+ 126,
2744
+ 129,
2745
+ 131,
2746
+ 135,
2747
+ 138,
2748
+ 139,
2749
+ 147,
2750
+ 150,
2751
+ 152,
2752
+ 171,
2753
+ 178,
2754
+ 179,
2755
+ 180,
2756
+ 181,
2757
+ 195,
2758
+ 204,
2759
+ 205,
2760
+ 210,
2761
+ 226,
2762
+ 227,
2763
+ 229,
2764
+ 235,
2765
+ 239,
2766
+ 240,
2767
+ 241,
2768
+ 244,
2769
+ 249,
2770
+ 250,
2771
+ 251,
2772
+ 254,
2773
+ 255
2774
+ ],
2775
+ "42": [
2776
+ 2,
2777
+ 5,
2778
+ 11,
2779
+ 14,
2780
+ 16,
2781
+ 18,
2782
+ 20,
2783
+ 22,
2784
+ 29,
2785
+ 37,
2786
+ 47,
2787
+ 53,
2788
+ 55,
2789
+ 56,
2790
+ 60,
2791
+ 63,
2792
+ 66,
2793
+ 68,
2794
+ 70,
2795
+ 71,
2796
+ 74,
2797
+ 79,
2798
+ 81,
2799
+ 89,
2800
+ 93,
2801
+ 94,
2802
+ 101,
2803
+ 102,
2804
+ 103,
2805
+ 107,
2806
+ 112,
2807
+ 114,
2808
+ 119,
2809
+ 121,
2810
+ 127,
2811
+ 129,
2812
+ 131,
2813
+ 138,
2814
+ 141,
2815
+ 147,
2816
+ 148,
2817
+ 151,
2818
+ 158,
2819
+ 160,
2820
+ 163,
2821
+ 170,
2822
+ 172,
2823
+ 179,
2824
+ 182,
2825
+ 183,
2826
+ 188,
2827
+ 189,
2828
+ 190,
2829
+ 191,
2830
+ 193,
2831
+ 195,
2832
+ 202,
2833
+ 211,
2834
+ 217,
2835
+ 218,
2836
+ 228,
2837
+ 233,
2838
+ 242,
2839
+ 255
2840
+ ],
2841
+ "43": [
2842
+ 4,
2843
+ 5,
2844
+ 15,
2845
+ 18,
2846
+ 19,
2847
+ 27,
2848
+ 28,
2849
+ 30,
2850
+ 32,
2851
+ 35,
2852
+ 36,
2853
+ 38,
2854
+ 39,
2855
+ 41,
2856
+ 48,
2857
+ 49,
2858
+ 50,
2859
+ 51,
2860
+ 61,
2861
+ 63,
2862
+ 67,
2863
+ 74,
2864
+ 79,
2865
+ 80,
2866
+ 95,
2867
+ 100,
2868
+ 104,
2869
+ 108,
2870
+ 111,
2871
+ 128,
2872
+ 132,
2873
+ 144,
2874
+ 145,
2875
+ 147,
2876
+ 154,
2877
+ 156,
2878
+ 158,
2879
+ 162,
2880
+ 163,
2881
+ 164,
2882
+ 165,
2883
+ 169,
2884
+ 171,
2885
+ 176,
2886
+ 182,
2887
+ 189,
2888
+ 190,
2889
+ 192,
2890
+ 194,
2891
+ 199,
2892
+ 201,
2893
+ 204,
2894
+ 205,
2895
+ 211,
2896
+ 212,
2897
+ 214,
2898
+ 221,
2899
+ 233,
2900
+ 235,
2901
+ 238,
2902
+ 242,
2903
+ 244,
2904
+ 249,
2905
+ 252
2906
+ ],
2907
+ "44": [
2908
+ 18,
2909
+ 20,
2910
+ 21,
2911
+ 23,
2912
+ 24,
2913
+ 27,
2914
+ 34,
2915
+ 40,
2916
+ 50,
2917
+ 52,
2918
+ 61,
2919
+ 63,
2920
+ 64,
2921
+ 65,
2922
+ 69,
2923
+ 70,
2924
+ 73,
2925
+ 78,
2926
+ 84,
2927
+ 85,
2928
+ 88,
2929
+ 90,
2930
+ 91,
2931
+ 92,
2932
+ 101,
2933
+ 103,
2934
+ 104,
2935
+ 108,
2936
+ 111,
2937
+ 115,
2938
+ 122,
2939
+ 127,
2940
+ 131,
2941
+ 133,
2942
+ 135,
2943
+ 138,
2944
+ 142,
2945
+ 144,
2946
+ 148,
2947
+ 150,
2948
+ 153,
2949
+ 157,
2950
+ 158,
2951
+ 160,
2952
+ 174,
2953
+ 178,
2954
+ 180,
2955
+ 181,
2956
+ 182,
2957
+ 185,
2958
+ 186,
2959
+ 198,
2960
+ 208,
2961
+ 209,
2962
+ 210,
2963
+ 212,
2964
+ 220,
2965
+ 223,
2966
+ 228,
2967
+ 231,
2968
+ 242,
2969
+ 248,
2970
+ 251,
2971
+ 254
2972
+ ],
2973
+ "45": [
2974
+ 3,
2975
+ 12,
2976
+ 13,
2977
+ 16,
2978
+ 22,
2979
+ 27,
2980
+ 28,
2981
+ 39,
2982
+ 41,
2983
+ 42,
2984
+ 43,
2985
+ 45,
2986
+ 48,
2987
+ 65,
2988
+ 80,
2989
+ 81,
2990
+ 85,
2991
+ 88,
2992
+ 89,
2993
+ 93,
2994
+ 95,
2995
+ 96,
2996
+ 103,
2997
+ 105,
2998
+ 118,
2999
+ 121,
3000
+ 124,
3001
+ 135,
3002
+ 136,
3003
+ 137,
3004
+ 138,
3005
+ 140,
3006
+ 143,
3007
+ 144,
3008
+ 145,
3009
+ 146,
3010
+ 148,
3011
+ 151,
3012
+ 159,
3013
+ 162,
3014
+ 167,
3015
+ 169,
3016
+ 172,
3017
+ 186,
3018
+ 198,
3019
+ 199,
3020
+ 204,
3021
+ 216,
3022
+ 217,
3023
+ 222,
3024
+ 223,
3025
+ 226,
3026
+ 227,
3027
+ 228,
3028
+ 238,
3029
+ 239,
3030
+ 242,
3031
+ 245,
3032
+ 246,
3033
+ 247,
3034
+ 248,
3035
+ 250,
3036
+ 253,
3037
+ 255
3038
+ ],
3039
+ "46": [
3040
+ 2,
3041
+ 4,
3042
+ 10,
3043
+ 11,
3044
+ 13,
3045
+ 16,
3046
+ 18,
3047
+ 25,
3048
+ 28,
3049
+ 32,
3050
+ 42,
3051
+ 47,
3052
+ 51,
3053
+ 55,
3054
+ 60,
3055
+ 61,
3056
+ 62,
3057
+ 66,
3058
+ 67,
3059
+ 68,
3060
+ 73,
3061
+ 75,
3062
+ 77,
3063
+ 79,
3064
+ 95,
3065
+ 102,
3066
+ 104,
3067
+ 111,
3068
+ 118,
3069
+ 121,
3070
+ 127,
3071
+ 131,
3072
+ 139,
3073
+ 140,
3074
+ 144,
3075
+ 148,
3076
+ 152,
3077
+ 153,
3078
+ 155,
3079
+ 156,
3080
+ 157,
3081
+ 174,
3082
+ 186,
3083
+ 187,
3084
+ 192,
3085
+ 199,
3086
+ 201,
3087
+ 203,
3088
+ 206,
3089
+ 207,
3090
+ 210,
3091
+ 222,
3092
+ 224,
3093
+ 225,
3094
+ 227,
3095
+ 228,
3096
+ 229,
3097
+ 230,
3098
+ 231,
3099
+ 238,
3100
+ 239,
3101
+ 240,
3102
+ 243,
3103
+ 251
3104
+ ],
3105
+ "47": [
3106
+ 1,
3107
+ 4,
3108
+ 6,
3109
+ 18,
3110
+ 22,
3111
+ 41,
3112
+ 43,
3113
+ 45,
3114
+ 47,
3115
+ 48,
3116
+ 52,
3117
+ 56,
3118
+ 61,
3119
+ 63,
3120
+ 64,
3121
+ 65,
3122
+ 67,
3123
+ 70,
3124
+ 73,
3125
+ 74,
3126
+ 75,
3127
+ 78,
3128
+ 91,
3129
+ 93,
3130
+ 96,
3131
+ 106,
3132
+ 112,
3133
+ 117,
3134
+ 120,
3135
+ 122,
3136
+ 128,
3137
+ 129,
3138
+ 133,
3139
+ 135,
3140
+ 141,
3141
+ 146,
3142
+ 151,
3143
+ 154,
3144
+ 157,
3145
+ 158,
3146
+ 172,
3147
+ 173,
3148
+ 182,
3149
+ 195,
3150
+ 197,
3151
+ 200,
3152
+ 202,
3153
+ 203,
3154
+ 204,
3155
+ 207,
3156
+ 208,
3157
+ 209,
3158
+ 214,
3159
+ 215,
3160
+ 216,
3161
+ 217,
3162
+ 223,
3163
+ 225,
3164
+ 228,
3165
+ 230,
3166
+ 236,
3167
+ 241,
3168
+ 245,
3169
+ 249
3170
+ ],
3171
+ "48": [
3172
+ 14,
3173
+ 15,
3174
+ 18,
3175
+ 19,
3176
+ 22,
3177
+ 25,
3178
+ 28,
3179
+ 30,
3180
+ 48,
3181
+ 54,
3182
+ 55,
3183
+ 57,
3184
+ 61,
3185
+ 65,
3186
+ 66,
3187
+ 71,
3188
+ 73,
3189
+ 75,
3190
+ 78,
3191
+ 81,
3192
+ 82,
3193
+ 86,
3194
+ 94,
3195
+ 100,
3196
+ 104,
3197
+ 107,
3198
+ 111,
3199
+ 112,
3200
+ 114,
3201
+ 116,
3202
+ 117,
3203
+ 118,
3204
+ 122,
3205
+ 124,
3206
+ 129,
3207
+ 137,
3208
+ 138,
3209
+ 139,
3210
+ 146,
3211
+ 149,
3212
+ 151,
3213
+ 153,
3214
+ 159,
3215
+ 161,
3216
+ 162,
3217
+ 165,
3218
+ 173,
3219
+ 174,
3220
+ 176,
3221
+ 187,
3222
+ 189,
3223
+ 193,
3224
+ 200,
3225
+ 205,
3226
+ 210,
3227
+ 212,
3228
+ 234,
3229
+ 235,
3230
+ 236,
3231
+ 237,
3232
+ 244,
3233
+ 245,
3234
+ 247,
3235
+ 248
3236
+ ],
3237
+ "49": [
3238
+ 11,
3239
+ 16,
3240
+ 21,
3241
+ 23,
3242
+ 43,
3243
+ 53,
3244
+ 55,
3245
+ 57,
3246
+ 59,
3247
+ 61,
3248
+ 70,
3249
+ 77,
3250
+ 78,
3251
+ 79,
3252
+ 82,
3253
+ 83,
3254
+ 86,
3255
+ 91,
3256
+ 92,
3257
+ 95,
3258
+ 98,
3259
+ 103,
3260
+ 106,
3261
+ 110,
3262
+ 118,
3263
+ 119,
3264
+ 122,
3265
+ 125,
3266
+ 127,
3267
+ 134,
3268
+ 139,
3269
+ 140,
3270
+ 141,
3271
+ 142,
3272
+ 143,
3273
+ 147,
3274
+ 149,
3275
+ 161,
3276
+ 162,
3277
+ 163,
3278
+ 165,
3279
+ 168,
3280
+ 180,
3281
+ 181,
3282
+ 184,
3283
+ 185,
3284
+ 187,
3285
+ 192,
3286
+ 197,
3287
+ 198,
3288
+ 206,
3289
+ 210,
3290
+ 211,
3291
+ 212,
3292
+ 215,
3293
+ 217,
3294
+ 220,
3295
+ 226,
3296
+ 227,
3297
+ 229,
3298
+ 230,
3299
+ 247,
3300
+ 248,
3301
+ 251
3302
+ ],
3303
+ "50": [
3304
+ 1,
3305
+ 2,
3306
+ 5,
3307
+ 7,
3308
+ 15,
3309
+ 16,
3310
+ 27,
3311
+ 28,
3312
+ 29,
3313
+ 30,
3314
+ 32,
3315
+ 35,
3316
+ 38,
3317
+ 42,
3318
+ 44,
3319
+ 60,
3320
+ 61,
3321
+ 63,
3322
+ 65,
3323
+ 66,
3324
+ 69,
3325
+ 73,
3326
+ 74,
3327
+ 81,
3328
+ 85,
3329
+ 87,
3330
+ 89,
3331
+ 95,
3332
+ 98,
3333
+ 106,
3334
+ 107,
3335
+ 112,
3336
+ 125,
3337
+ 127,
3338
+ 133,
3339
+ 141,
3340
+ 142,
3341
+ 143,
3342
+ 144,
3343
+ 145,
3344
+ 153,
3345
+ 155,
3346
+ 157,
3347
+ 161,
3348
+ 163,
3349
+ 168,
3350
+ 170,
3351
+ 171,
3352
+ 192,
3353
+ 194,
3354
+ 197,
3355
+ 200,
3356
+ 204,
3357
+ 206,
3358
+ 207,
3359
+ 216,
3360
+ 218,
3361
+ 221,
3362
+ 229,
3363
+ 231,
3364
+ 244,
3365
+ 246,
3366
+ 248,
3367
+ 251
3368
+ ],
3369
+ "51": [
3370
+ 1,
3371
+ 10,
3372
+ 11,
3373
+ 16,
3374
+ 21,
3375
+ 22,
3376
+ 26,
3377
+ 29,
3378
+ 42,
3379
+ 45,
3380
+ 54,
3381
+ 56,
3382
+ 63,
3383
+ 65,
3384
+ 67,
3385
+ 70,
3386
+ 71,
3387
+ 72,
3388
+ 79,
3389
+ 85,
3390
+ 88,
3391
+ 92,
3392
+ 99,
3393
+ 102,
3394
+ 103,
3395
+ 105,
3396
+ 109,
3397
+ 114,
3398
+ 124,
3399
+ 126,
3400
+ 129,
3401
+ 130,
3402
+ 132,
3403
+ 138,
3404
+ 140,
3405
+ 141,
3406
+ 146,
3407
+ 147,
3408
+ 151,
3409
+ 152,
3410
+ 157,
3411
+ 164,
3412
+ 167,
3413
+ 174,
3414
+ 182,
3415
+ 186,
3416
+ 188,
3417
+ 190,
3418
+ 191,
3419
+ 195,
3420
+ 203,
3421
+ 208,
3422
+ 209,
3423
+ 211,
3424
+ 213,
3425
+ 214,
3426
+ 223,
3427
+ 226,
3428
+ 236,
3429
+ 237,
3430
+ 238,
3431
+ 242,
3432
+ 247,
3433
+ 253
3434
+ ],
3435
+ "52": [
3436
+ 2,
3437
+ 11,
3438
+ 12,
3439
+ 13,
3440
+ 17,
3441
+ 25,
3442
+ 27,
3443
+ 36,
3444
+ 41,
3445
+ 43,
3446
+ 45,
3447
+ 47,
3448
+ 50,
3449
+ 51,
3450
+ 55,
3451
+ 56,
3452
+ 71,
3453
+ 72,
3454
+ 77,
3455
+ 84,
3456
+ 86,
3457
+ 95,
3458
+ 99,
3459
+ 100,
3460
+ 101,
3461
+ 104,
3462
+ 105,
3463
+ 106,
3464
+ 114,
3465
+ 120,
3466
+ 131,
3467
+ 146,
3468
+ 147,
3469
+ 148,
3470
+ 152,
3471
+ 153,
3472
+ 156,
3473
+ 159,
3474
+ 162,
3475
+ 163,
3476
+ 165,
3477
+ 168,
3478
+ 172,
3479
+ 174,
3480
+ 175,
3481
+ 179,
3482
+ 193,
3483
+ 199,
3484
+ 201,
3485
+ 205,
3486
+ 209,
3487
+ 214,
3488
+ 215,
3489
+ 225,
3490
+ 230,
3491
+ 232,
3492
+ 236,
3493
+ 237,
3494
+ 240,
3495
+ 241,
3496
+ 242,
3497
+ 250,
3498
+ 252,
3499
+ 253
3500
+ ],
3501
+ "53": [
3502
+ 5,
3503
+ 19,
3504
+ 24,
3505
+ 28,
3506
+ 33,
3507
+ 36,
3508
+ 37,
3509
+ 38,
3510
+ 42,
3511
+ 45,
3512
+ 47,
3513
+ 48,
3514
+ 54,
3515
+ 65,
3516
+ 72,
3517
+ 88,
3518
+ 90,
3519
+ 93,
3520
+ 97,
3521
+ 99,
3522
+ 109,
3523
+ 112,
3524
+ 113,
3525
+ 116,
3526
+ 118,
3527
+ 119,
3528
+ 125,
3529
+ 128,
3530
+ 129,
3531
+ 130,
3532
+ 138,
3533
+ 139,
3534
+ 140,
3535
+ 141,
3536
+ 143,
3537
+ 145,
3538
+ 147,
3539
+ 150,
3540
+ 154,
3541
+ 166,
3542
+ 171,
3543
+ 173,
3544
+ 176,
3545
+ 177,
3546
+ 178,
3547
+ 181,
3548
+ 183,
3549
+ 195,
3550
+ 196,
3551
+ 204,
3552
+ 205,
3553
+ 206,
3554
+ 211,
3555
+ 212,
3556
+ 215,
3557
+ 216,
3558
+ 220,
3559
+ 224,
3560
+ 225,
3561
+ 226,
3562
+ 227,
3563
+ 236,
3564
+ 243,
3565
+ 249
3566
+ ],
3567
+ "54": [
3568
+ 3,
3569
+ 9,
3570
+ 13,
3571
+ 17,
3572
+ 18,
3573
+ 28,
3574
+ 39,
3575
+ 53,
3576
+ 54,
3577
+ 55,
3578
+ 56,
3579
+ 57,
3580
+ 68,
3581
+ 69,
3582
+ 75,
3583
+ 94,
3584
+ 95,
3585
+ 97,
3586
+ 100,
3587
+ 106,
3588
+ 113,
3589
+ 114,
3590
+ 116,
3591
+ 121,
3592
+ 122,
3593
+ 125,
3594
+ 138,
3595
+ 145,
3596
+ 147,
3597
+ 152,
3598
+ 153,
3599
+ 155,
3600
+ 158,
3601
+ 159,
3602
+ 160,
3603
+ 162,
3604
+ 163,
3605
+ 165,
3606
+ 170,
3607
+ 171,
3608
+ 172,
3609
+ 173,
3610
+ 174,
3611
+ 178,
3612
+ 184,
3613
+ 185,
3614
+ 191,
3615
+ 196,
3616
+ 198,
3617
+ 202,
3618
+ 207,
3619
+ 212,
3620
+ 219,
3621
+ 226,
3622
+ 227,
3623
+ 228,
3624
+ 230,
3625
+ 231,
3626
+ 232,
3627
+ 241,
3628
+ 242,
3629
+ 249,
3630
+ 252,
3631
+ 255
3632
+ ],
3633
+ "55": [
3634
+ 1,
3635
+ 21,
3636
+ 24,
3637
+ 32,
3638
+ 35,
3639
+ 53,
3640
+ 55,
3641
+ 58,
3642
+ 59,
3643
+ 63,
3644
+ 69,
3645
+ 82,
3646
+ 85,
3647
+ 90,
3648
+ 91,
3649
+ 93,
3650
+ 97,
3651
+ 102,
3652
+ 103,
3653
+ 104,
3654
+ 106,
3655
+ 107,
3656
+ 114,
3657
+ 122,
3658
+ 124,
3659
+ 125,
3660
+ 129,
3661
+ 133,
3662
+ 134,
3663
+ 136,
3664
+ 138,
3665
+ 140,
3666
+ 145,
3667
+ 152,
3668
+ 153,
3669
+ 155,
3670
+ 157,
3671
+ 162,
3672
+ 164,
3673
+ 165,
3674
+ 166,
3675
+ 188,
3676
+ 191,
3677
+ 192,
3678
+ 193,
3679
+ 195,
3680
+ 196,
3681
+ 198,
3682
+ 202,
3683
+ 204,
3684
+ 206,
3685
+ 208,
3686
+ 209,
3687
+ 217,
3688
+ 220,
3689
+ 226,
3690
+ 232,
3691
+ 235,
3692
+ 236,
3693
+ 241,
3694
+ 245,
3695
+ 246,
3696
+ 251,
3697
+ 252
3698
+ ],
3699
+ "56": [
3700
+ 6,
3701
+ 10,
3702
+ 11,
3703
+ 14,
3704
+ 25,
3705
+ 27,
3706
+ 31,
3707
+ 34,
3708
+ 36,
3709
+ 37,
3710
+ 39,
3711
+ 42,
3712
+ 44,
3713
+ 58,
3714
+ 62,
3715
+ 66,
3716
+ 67,
3717
+ 69,
3718
+ 71,
3719
+ 78,
3720
+ 84,
3721
+ 94,
3722
+ 99,
3723
+ 102,
3724
+ 107,
3725
+ 109,
3726
+ 115,
3727
+ 121,
3728
+ 127,
3729
+ 130,
3730
+ 132,
3731
+ 137,
3732
+ 141,
3733
+ 144,
3734
+ 145,
3735
+ 147,
3736
+ 156,
3737
+ 159,
3738
+ 164,
3739
+ 169,
3740
+ 177,
3741
+ 178,
3742
+ 180,
3743
+ 184,
3744
+ 185,
3745
+ 187,
3746
+ 188,
3747
+ 194,
3748
+ 196,
3749
+ 201,
3750
+ 203,
3751
+ 211,
3752
+ 213,
3753
+ 214,
3754
+ 219,
3755
+ 221,
3756
+ 223,
3757
+ 226,
3758
+ 232,
3759
+ 235,
3760
+ 238,
3761
+ 239,
3762
+ 244,
3763
+ 249
3764
+ ],
3765
+ "57": [
3766
+ 0,
3767
+ 4,
3768
+ 5,
3769
+ 8,
3770
+ 9,
3771
+ 10,
3772
+ 25,
3773
+ 35,
3774
+ 40,
3775
+ 44,
3776
+ 53,
3777
+ 54,
3778
+ 60,
3779
+ 69,
3780
+ 70,
3781
+ 71,
3782
+ 75,
3783
+ 79,
3784
+ 80,
3785
+ 85,
3786
+ 97,
3787
+ 98,
3788
+ 99,
3789
+ 109,
3790
+ 111,
3791
+ 112,
3792
+ 118,
3793
+ 119,
3794
+ 124,
3795
+ 128,
3796
+ 130,
3797
+ 131,
3798
+ 145,
3799
+ 147,
3800
+ 148,
3801
+ 151,
3802
+ 154,
3803
+ 160,
3804
+ 165,
3805
+ 169,
3806
+ 170,
3807
+ 171,
3808
+ 181,
3809
+ 189,
3810
+ 200,
3811
+ 206,
3812
+ 207,
3813
+ 211,
3814
+ 212,
3815
+ 216,
3816
+ 218,
3817
+ 220,
3818
+ 221,
3819
+ 222,
3820
+ 227,
3821
+ 234,
3822
+ 235,
3823
+ 236,
3824
+ 239,
3825
+ 242,
3826
+ 248,
3827
+ 249,
3828
+ 250,
3829
+ 251
3830
+ ],
3831
+ "58": [
3832
+ 0,
3833
+ 1,
3834
+ 4,
3835
+ 8,
3836
+ 13,
3837
+ 16,
3838
+ 20,
3839
+ 21,
3840
+ 25,
3841
+ 34,
3842
+ 36,
3843
+ 39,
3844
+ 41,
3845
+ 45,
3846
+ 46,
3847
+ 47,
3848
+ 57,
3849
+ 59,
3850
+ 68,
3851
+ 74,
3852
+ 76,
3853
+ 80,
3854
+ 81,
3855
+ 82,
3856
+ 87,
3857
+ 88,
3858
+ 92,
3859
+ 93,
3860
+ 101,
3861
+ 104,
3862
+ 105,
3863
+ 113,
3864
+ 114,
3865
+ 122,
3866
+ 123,
3867
+ 134,
3868
+ 141,
3869
+ 147,
3870
+ 149,
3871
+ 150,
3872
+ 156,
3873
+ 158,
3874
+ 159,
3875
+ 173,
3876
+ 177,
3877
+ 179,
3878
+ 180,
3879
+ 181,
3880
+ 182,
3881
+ 190,
3882
+ 193,
3883
+ 207,
3884
+ 212,
3885
+ 214,
3886
+ 216,
3887
+ 218,
3888
+ 221,
3889
+ 225,
3890
+ 227,
3891
+ 228,
3892
+ 235,
3893
+ 240,
3894
+ 241,
3895
+ 250
3896
+ ],
3897
+ "59": [
3898
+ 1,
3899
+ 2,
3900
+ 3,
3901
+ 12,
3902
+ 14,
3903
+ 15,
3904
+ 17,
3905
+ 27,
3906
+ 28,
3907
+ 35,
3908
+ 36,
3909
+ 49,
3910
+ 60,
3911
+ 69,
3912
+ 71,
3913
+ 78,
3914
+ 83,
3915
+ 94,
3916
+ 95,
3917
+ 100,
3918
+ 104,
3919
+ 106,
3920
+ 107,
3921
+ 108,
3922
+ 110,
3923
+ 111,
3924
+ 113,
3925
+ 116,
3926
+ 119,
3927
+ 123,
3928
+ 125,
3929
+ 126,
3930
+ 128,
3931
+ 131,
3932
+ 134,
3933
+ 136,
3934
+ 150,
3935
+ 159,
3936
+ 162,
3937
+ 163,
3938
+ 166,
3939
+ 168,
3940
+ 172,
3941
+ 175,
3942
+ 178,
3943
+ 180,
3944
+ 181,
3945
+ 182,
3946
+ 194,
3947
+ 195,
3948
+ 206,
3949
+ 210,
3950
+ 214,
3951
+ 216,
3952
+ 218,
3953
+ 221,
3954
+ 224,
3955
+ 225,
3956
+ 226,
3957
+ 229,
3958
+ 236,
3959
+ 237,
3960
+ 248,
3961
+ 253
3962
+ ],
3963
+ "60": [
3964
+ 5,
3965
+ 17,
3966
+ 20,
3967
+ 25,
3968
+ 26,
3969
+ 27,
3970
+ 33,
3971
+ 35,
3972
+ 38,
3973
+ 50,
3974
+ 52,
3975
+ 58,
3976
+ 59,
3977
+ 63,
3978
+ 64,
3979
+ 71,
3980
+ 72,
3981
+ 73,
3982
+ 74,
3983
+ 81,
3984
+ 82,
3985
+ 87,
3986
+ 95,
3987
+ 97,
3988
+ 104,
3989
+ 105,
3990
+ 107,
3991
+ 109,
3992
+ 113,
3993
+ 114,
3994
+ 120,
3995
+ 121,
3996
+ 123,
3997
+ 125,
3998
+ 131,
3999
+ 132,
4000
+ 147,
4001
+ 154,
4002
+ 157,
4003
+ 158,
4004
+ 159,
4005
+ 160,
4006
+ 162,
4007
+ 163,
4008
+ 169,
4009
+ 170,
4010
+ 178,
4011
+ 186,
4012
+ 192,
4013
+ 194,
4014
+ 196,
4015
+ 197,
4016
+ 199,
4017
+ 205,
4018
+ 213,
4019
+ 215,
4020
+ 216,
4021
+ 218,
4022
+ 221,
4023
+ 237,
4024
+ 246,
4025
+ 247,
4026
+ 248,
4027
+ 254
4028
+ ],
4029
+ "61": [
4030
+ 5,
4031
+ 8,
4032
+ 11,
4033
+ 16,
4034
+ 18,
4035
+ 24,
4036
+ 29,
4037
+ 32,
4038
+ 33,
4039
+ 36,
4040
+ 42,
4041
+ 45,
4042
+ 48,
4043
+ 49,
4044
+ 55,
4045
+ 56,
4046
+ 75,
4047
+ 79,
4048
+ 81,
4049
+ 82,
4050
+ 90,
4051
+ 94,
4052
+ 99,
4053
+ 104,
4054
+ 112,
4055
+ 117,
4056
+ 118,
4057
+ 124,
4058
+ 126,
4059
+ 128,
4060
+ 130,
4061
+ 131,
4062
+ 132,
4063
+ 140,
4064
+ 141,
4065
+ 145,
4066
+ 149,
4067
+ 156,
4068
+ 159,
4069
+ 161,
4070
+ 169,
4071
+ 171,
4072
+ 172,
4073
+ 176,
4074
+ 179,
4075
+ 183,
4076
+ 184,
4077
+ 190,
4078
+ 196,
4079
+ 199,
4080
+ 201,
4081
+ 202,
4082
+ 207,
4083
+ 210,
4084
+ 225,
4085
+ 228,
4086
+ 230,
4087
+ 231,
4088
+ 239,
4089
+ 241,
4090
+ 242,
4091
+ 245,
4092
+ 252,
4093
+ 255
4094
+ ]
4095
+ }
4096
+ }
extras/force_swap.cpp ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <iostream>
2
+ #include <string>
3
+ #include <cstdlib>
4
+ #include <sys/mman.h>
5
+ #include <unistd.h>
6
+ #include <cstring>
7
+
8
+ int main(int argc, char** argv) {
9
+ if (argc != 2) {
10
+ std::cerr << "Usage: " << argv[0] << " <GB to allocate and lock>\n";
11
+ return 1;
12
+ }
13
+
14
+ double gb = std::stod(argv[1]);
15
+ size_t bytes = static_cast<size_t>(gb * 1024.0 * 1024.0 * 1024.0);
16
+
17
+ std::cout << "Allocating " << gb << " GB (" << bytes << " bytes) of RAM...\n";
18
+
19
+ void* ptr = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
20
+ if (ptr == MAP_FAILED) {
21
+ perror("mmap failed");
22
+ return 1;
23
+ }
24
+
25
+ std::cout << "Memory allocated. Faulting pages and pinning to RAM...\n";
26
+
27
+ // Write to memory to map it to physical pages and prevent lazy allocation
28
+ size_t page_size = sysconf(_SC_PAGESIZE);
29
+ char* char_ptr = static_cast<char*>(ptr);
30
+ for (size_t i = 0; i < bytes; i += page_size) {
31
+ char_ptr[i] = 1;
32
+ }
33
+
34
+ // Mlock to pin it to RAM and prevent it from being swapped out itself
35
+ if (mlock(ptr, bytes) != 0) {
36
+ perror("mlock failed (you probably need to run with sudo)");
37
+ } else {
38
+ std::cout << "mlock successful.\n";
39
+ }
40
+
41
+ std::cout << "Memory is fully resident. Other inactive processes/caches should be pushed to swap.\n";
42
+ std::cout << "Clearing filesystem caches...\n";
43
+
44
+ int ret = system("echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null");
45
+ if (ret != 0) {
46
+ std::cerr << "Failed to clear caches. (Maybe sudo failed?)\n";
47
+ } else {
48
+ std::cout << "Caches cleared successfully.\n";
49
+ }
50
+
51
+ std::cout << "Unlocking and releasing memory...\n";
52
+ munlock(ptr, bytes);
53
+ munmap(ptr, bytes);
54
+
55
+ std::cout << "Done! Try starting your model now.\n";
56
+ return 0;
57
+ }
extras/inference_minimax.sh ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh -
2
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
3
+ MODEL_DIR="$(dirname "$SCRIPT_DIR")"
4
+ . ~/venv/vllm/bin/activate
5
+
6
+ dockless destroy seeker-inference
7
+ sleep 5
8
+ dockless run -d --name seeker-inference \
9
+ -e CUDA_HOME=/usr/local/cuda-13.0 \
10
+ -e C_INCLUDE_PATH=/usr/local/cuda-13.0/include \
11
+ -e LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/nvidia \
12
+ -e FLASHINFER_NVCC=/usr/local/cuda-13.0/bin/nvcc \
13
+ -e VLLM_USE_FLASHINFER_MOE_FP4=0 "$SCRIPT_DIR/unglitched_vllm" \
14
+ --served-model-name Nikola \
15
+ --port 9000 \
16
+ --enable-auto-tool-choice \
17
+ --tool-call-parser minimax_m2 \
18
+ --reasoning-parser minimax_m2_optthink \
19
+ --reasoning-parser-plugin "$SCRIPT_DIR/minimax_m2_optthink_reasoning_parser.py" \
20
+ --enable-prefix-caching \
21
+ --max-num-seqs 4 --cudagraph-capture-sizes 1 2 4 --max-model-len auto \
22
+ --max_num_batched_tokens 8192 \
23
+ --gpu-memory-utilization 0.95 \
24
+ --attention-backend FLASHINFER \
25
+ --async-scheduling \
26
+ --enable-chunked-prefill \
27
+ --chat-template "$SCRIPT_DIR/chat_template.jinja" \
28
+ --model "${@:-$MODEL_DIR}"
29
+
extras/minimax_m2_optthink_reasoning_parser.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # minimax_m2_optthink_reasoning_parser.py
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from collections.abc import Sequence
5
+ from typing import TYPE_CHECKING
6
+
7
+ from vllm.entrypoints.openai.engine.protocol import DeltaMessage
8
+ from vllm.logger import init_logger
9
+ from vllm.reasoning.abs_reasoning_parsers import ReasoningParserManager
10
+ from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser
11
+ from vllm.tokenizers import TokenizerLike
12
+
13
+ if TYPE_CHECKING:
14
+ from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
15
+ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
16
+
17
+ logger = init_logger(__name__)
18
+
19
+ @ReasoningParserManager.register_module("minimax_m2_optthink")
20
+ class MiniMaxM2OptthinkReasoningParser(BaseThinkingReasoningParser):
21
+ """
22
+ Reasoning parser for MiniMax M2 model that handles enable_thinking=False configs.
23
+
24
+ MiniMax M2 models don't generate <think> start token, only </think> end
25
+ token. All content before </think> is reasoning, content after is the
26
+ actual response. This checks chat_template_kwargs for thinking config.
27
+ """
28
+
29
+ def __init__(self, tokenizer: TokenizerLike, *args, **kwargs):
30
+ super().__init__(tokenizer, *args, **kwargs)
31
+ chat_kwargs = kwargs.get("chat_template_kwargs", {}) or {}
32
+ self.thinking_enabled = chat_kwargs.get("enable_thinking", True)
33
+
34
+ @property
35
+ def start_token(self) -> str:
36
+ """The token that starts reasoning content."""
37
+ return "<think>"
38
+
39
+ @property
40
+ def end_token(self) -> str:
41
+ """The token that ends reasoning content."""
42
+ return "</think>"
43
+
44
+ def extract_reasoning(
45
+ self, model_output: str, request: "ChatCompletionRequest | ResponsesRequest"
46
+ ) -> tuple[str | None, str | None]:
47
+ # Strip <think> if present in the generated output.
48
+ model_output_parts = model_output.partition(self.start_token)
49
+ model_output = (
50
+ model_output_parts[2] if model_output_parts[1] else model_output_parts[0]
51
+ )
52
+
53
+ if self.end_token not in model_output:
54
+ if not self.thinking_enabled:
55
+ # Thinking explicitly disabled \u2014 treat everything as content.
56
+ return None, model_output
57
+ # Thinking enabled but no </think>: output was truncated.
58
+ return model_output, None
59
+
60
+ # Extract reasoning content from the model output.
61
+ reasoning, _, content = model_output.partition(self.end_token)
62
+ final_content = content or None
63
+ return reasoning, final_content
64
+
65
+ def extract_reasoning_streaming(
66
+ self,
67
+ previous_text: str,
68
+ current_text: str,
69
+ delta_text: str,
70
+ previous_token_ids: Sequence[int],
71
+ current_token_ids: Sequence[int],
72
+ delta_token_ids: Sequence[int],
73
+ ) -> DeltaMessage | None:
74
+ """
75
+ Extract reasoning content from a delta message for streaming.
76
+ """
77
+ # Skip single special tokens
78
+ if len(delta_token_ids) == 1 and (
79
+ delta_token_ids[0] in [self.start_token_id, self.end_token_id]
80
+ ):
81
+ return None
82
+
83
+ # Check if end token has already appeared in previous tokens
84
+ if self.end_token_id in previous_token_ids:
85
+ # We're past the reasoning phase, this is content
86
+ return DeltaMessage(content=delta_text)
87
+
88
+ # Check if end token is in delta tokens
89
+ if self.end_token_id in delta_token_ids:
90
+ # End token in delta, split reasoning and content
91
+ end_index = delta_text.find(self.end_token)
92
+ if end_index >= 0:
93
+ reasoning = delta_text[:end_index]
94
+ content = delta_text[end_index + len(self.end_token) :]
95
+ return DeltaMessage(
96
+ reasoning=reasoning if reasoning else None,
97
+ content=content if content else None,
98
+ )
99
+ return None
100
+
101
+ # No end token yet, all content is reasoning
102
+ return DeltaMessage(reasoning=delta_text)
extras/unglitched_vllm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/sh -
2
+ unglitch 119
3
+ exec python -m vllm.entrypoints.openai.api_server "$@"
generation_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 200019,
3
+ "do_sample": true,
4
+ "eos_token_id": 200020,
5
+ "temperature": 1.0,
6
+ "top_p": 0.95,
7
+ "top_k": 40,
8
+ "transformers_version": "4.46.1"
9
+ }
hf_quant_config.json ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "producer": {
3
+ "name": "modelopt",
4
+ "version": "0.43.0rc2.dev105+g0b42c143d"
5
+ },
6
+ "quantization": {
7
+ "quant_algo": "NVFP4",
8
+ "kv_cache_quant_algo": "FP8",
9
+ "group_size": 16,
10
+ "exclude_modules": [
11
+ "lm_head",
12
+ "model.layers.0.block_sparse_moe.gate",
13
+ "model.layers.0.self_attn*",
14
+ "model.layers.1.block_sparse_moe.gate",
15
+ "model.layers.1.self_attn*",
16
+ "model.layers.10.block_sparse_moe.gate",
17
+ "model.layers.10.self_attn*",
18
+ "model.layers.11.block_sparse_moe.gate",
19
+ "model.layers.11.self_attn*",
20
+ "model.layers.12.block_sparse_moe.gate",
21
+ "model.layers.12.self_attn*",
22
+ "model.layers.13.block_sparse_moe.gate",
23
+ "model.layers.13.self_attn*",
24
+ "model.layers.14.block_sparse_moe.gate",
25
+ "model.layers.14.self_attn*",
26
+ "model.layers.15.block_sparse_moe.gate",
27
+ "model.layers.15.self_attn*",
28
+ "model.layers.16.block_sparse_moe.gate",
29
+ "model.layers.16.self_attn*",
30
+ "model.layers.17.block_sparse_moe.gate",
31
+ "model.layers.17.self_attn*",
32
+ "model.layers.18.block_sparse_moe.gate",
33
+ "model.layers.18.self_attn*",
34
+ "model.layers.19.block_sparse_moe.gate",
35
+ "model.layers.19.self_attn*",
36
+ "model.layers.2.block_sparse_moe.gate",
37
+ "model.layers.2.self_attn*",
38
+ "model.layers.20.block_sparse_moe.gate",
39
+ "model.layers.20.self_attn*",
40
+ "model.layers.21.block_sparse_moe.gate",
41
+ "model.layers.21.self_attn*",
42
+ "model.layers.22.block_sparse_moe.gate",
43
+ "model.layers.22.self_attn*",
44
+ "model.layers.23.block_sparse_moe.gate",
45
+ "model.layers.23.self_attn*",
46
+ "model.layers.24.block_sparse_moe.gate",
47
+ "model.layers.24.self_attn*",
48
+ "model.layers.25.block_sparse_moe.gate",
49
+ "model.layers.25.self_attn*",
50
+ "model.layers.26.block_sparse_moe.gate",
51
+ "model.layers.26.self_attn*",
52
+ "model.layers.27.block_sparse_moe.gate",
53
+ "model.layers.27.self_attn*",
54
+ "model.layers.28.block_sparse_moe.gate",
55
+ "model.layers.28.self_attn*",
56
+ "model.layers.29.block_sparse_moe.gate",
57
+ "model.layers.29.self_attn*",
58
+ "model.layers.3.block_sparse_moe.gate",
59
+ "model.layers.3.self_attn*",
60
+ "model.layers.30.block_sparse_moe.gate",
61
+ "model.layers.30.self_attn*",
62
+ "model.layers.31.block_sparse_moe.gate",
63
+ "model.layers.31.self_attn*",
64
+ "model.layers.32.block_sparse_moe.gate",
65
+ "model.layers.32.self_attn*",
66
+ "model.layers.33.block_sparse_moe.gate",
67
+ "model.layers.33.self_attn*",
68
+ "model.layers.34.block_sparse_moe.gate",
69
+ "model.layers.34.self_attn*",
70
+ "model.layers.35.block_sparse_moe.gate",
71
+ "model.layers.35.self_attn*",
72
+ "model.layers.36.block_sparse_moe.gate",
73
+ "model.layers.36.self_attn*",
74
+ "model.layers.37.block_sparse_moe.gate",
75
+ "model.layers.37.self_attn*",
76
+ "model.layers.38.block_sparse_moe.gate",
77
+ "model.layers.38.self_attn*",
78
+ "model.layers.39.block_sparse_moe.gate",
79
+ "model.layers.39.self_attn*",
80
+ "model.layers.4.block_sparse_moe.gate",
81
+ "model.layers.4.self_attn*",
82
+ "model.layers.40.block_sparse_moe.gate",
83
+ "model.layers.40.self_attn*",
84
+ "model.layers.41.block_sparse_moe.gate",
85
+ "model.layers.41.self_attn*",
86
+ "model.layers.42.block_sparse_moe.gate",
87
+ "model.layers.42.self_attn*",
88
+ "model.layers.43.block_sparse_moe.gate",
89
+ "model.layers.43.self_attn*",
90
+ "model.layers.44.block_sparse_moe.gate",
91
+ "model.layers.44.self_attn*",
92
+ "model.layers.45.block_sparse_moe.gate",
93
+ "model.layers.45.self_attn*",
94
+ "model.layers.46.block_sparse_moe.gate",
95
+ "model.layers.46.self_attn*",
96
+ "model.layers.47.block_sparse_moe.gate",
97
+ "model.layers.47.self_attn*",
98
+ "model.layers.48.block_sparse_moe.gate",
99
+ "model.layers.48.self_attn*",
100
+ "model.layers.49.block_sparse_moe.gate",
101
+ "model.layers.49.self_attn*",
102
+ "model.layers.5.block_sparse_moe.gate",
103
+ "model.layers.5.self_attn*",
104
+ "model.layers.50.block_sparse_moe.gate",
105
+ "model.layers.50.self_attn*",
106
+ "model.layers.51.block_sparse_moe.gate",
107
+ "model.layers.51.self_attn*",
108
+ "model.layers.52.block_sparse_moe.gate",
109
+ "model.layers.52.self_attn*",
110
+ "model.layers.53.block_sparse_moe.gate",
111
+ "model.layers.53.self_attn*",
112
+ "model.layers.54.block_sparse_moe.gate",
113
+ "model.layers.54.self_attn*",
114
+ "model.layers.55.block_sparse_moe.gate",
115
+ "model.layers.55.self_attn*",
116
+ "model.layers.56.block_sparse_moe.gate",
117
+ "model.layers.56.self_attn*",
118
+ "model.layers.57.block_sparse_moe.gate",
119
+ "model.layers.57.self_attn*",
120
+ "model.layers.58.block_sparse_moe.gate",
121
+ "model.layers.58.self_attn*",
122
+ "model.layers.59.block_sparse_moe.gate",
123
+ "model.layers.59.self_attn*",
124
+ "model.layers.6.block_sparse_moe.gate",
125
+ "model.layers.6.self_attn*",
126
+ "model.layers.60.block_sparse_moe.gate",
127
+ "model.layers.60.self_attn*",
128
+ "model.layers.61.block_sparse_moe.gate",
129
+ "model.layers.61.self_attn*",
130
+ "model.layers.7.block_sparse_moe.gate",
131
+ "model.layers.7.self_attn*",
132
+ "model.layers.8.block_sparse_moe.gate",
133
+ "model.layers.8.self_attn*",
134
+ "model.layers.9.block_sparse_moe.gate",
135
+ "model.layers.9.self_attn*"
136
+ ]
137
+ }
138
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:005d3c3fa71564476658cac6169fe165f86b616a7a183142b239589ca7ffaee2
3
+ size 7983477840
model-00002-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e8d753b20328e591d7473fcca8e43bceaa65ff7f1860e63660afa9c2477965c
3
+ size 7736049080
model-00003-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a6df42a11c868576d109a2716cc09b9a122e26837be4392e0e015f39e46c113
3
+ size 7654258000
model-00004-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84b7c59d56500b27b78277b15b349dc3acc52febf921e9736c58607f9a6e9950
3
+ size 7698893312
model-00005-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:087db31546dc220410b2bf4613c726363b4ef1e7a54b7f5b5e993992dc7e94f9
3
+ size 7699398176
model-00006-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75f6c08f376e44e25f25c4ab5092cd879eecb72ca6db012756ad363ce57964cf
3
+ size 7688262080
model-00007-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db7b38244fe7cf73f2e5575ef037b1672021a7eca9fccb4a7dcd41a5fcad3818
3
+ size 7670196272
model-00008-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6ca577b76b4ac12b440dbc5a382881eb85b91e5a74395b0c3aa862a46c5a9f8
3
+ size 7680297864
model-00009-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce84cc4ff6612f95e1c948ddf4de8c35614406c752366b1a365245ac7b5f9eeb
3
+ size 7678160424
model-00010-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cdb26e874b3e6f0a2506b2b70a60bb08de6b1b5ec3981f31ed2e00c09859899d
3
+ size 7720118944
model-00011-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9ffec0eefcd499d0d21702660f71d057f17d0f4ca214e5f5a751fe7849066f0
3
+ size 7638339656
model-00012-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cee4e7c25124f84065b4595b694f126953a323466a8deebafe06280b1650017
3
+ size 7751975800
model-00013-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:46107bc18db6fd66f0e09e0d7397b6ecb9c8e67fe7e3f1dde9be72bb484ebd13
3
+ size 7606483032
model-00014-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:629d67634d0bd610aae31fb20f993173a4b1f70dac730f70b3267490e078561f
3
+ size 6825988456
model-00015-of-00015.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a68c3eb1afc80eca0909878fda4cb51750ff5edf3f6d4bda1ec059cd8f8fc76
3
+ size 1229193312
model.safetensors.index.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb2c946cc1efede3be704f7762265295192c7a869ea3d0086a96d7a63125323d
3
+ size 14636608
modeling_minimax_m2.py ADDED
@@ -0,0 +1,706 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
2
+ # This file was automatically generated from src/transformers/models/minimax_m2/modular_minimax_m2.py.
3
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
4
+ # the file from the modular. If any change should be done, please apply the change to the
5
+ # modular_minimax_m2.py file directly. One of our CI enforces this.
6
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7
+ # coding=utf-8
8
+ # Copyright 2025 the HuggingFace Team. All rights reserved.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+
22
+
23
+ from collections.abc import Callable
24
+ from typing import Optional, Union, Unpack
25
+
26
+ import torch
27
+ from torch import nn
28
+
29
+ from transformers.activations import ACT2FN
30
+ from transformers.cache_utils import Cache, DynamicCache
31
+ from transformers.generation import GenerationMixin
32
+ from transformers.integrations import use_kernel_forward_from_hub
33
+ from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
34
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
35
+ from transformers.modeling_layers import (
36
+ GenericForQuestionAnswering,
37
+ GenericForSequenceClassification,
38
+ GenericForTokenClassification,
39
+ GradientCheckpointingLayer,
40
+ )
41
+ from transformers.modeling_outputs import MoeCausalLMOutputWithPast, MoeModelOutputWithPast
42
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
43
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
44
+ from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple
45
+ from transformers.utils.deprecation import deprecate_kwarg
46
+ from transformers.utils.generic import OutputRecorder, check_model_inputs
47
+ from .configuration_minimax_m2 import MiniMaxM2Config
48
+
49
+
50
+ class MiniMaxM2MLP(nn.Module):
51
+ def __init__(self, config: MiniMaxM2Config):
52
+ super().__init__()
53
+ self.ffn_dim = config.intermediate_size
54
+ self.hidden_dim = config.hidden_size
55
+
56
+ self.w1 = nn.Linear(self.hidden_dim, self.ffn_dim, bias=False)
57
+ self.w2 = nn.Linear(self.ffn_dim, self.hidden_dim, bias=False)
58
+ self.w3 = nn.Linear(self.hidden_dim, self.ffn_dim, bias=False)
59
+
60
+ self.act_fn = ACT2FN[config.hidden_act]
61
+
62
+ def forward(self, hidden_states):
63
+ current_hidden_states = self.act_fn(self.w1(hidden_states)) * self.w3(hidden_states)
64
+ current_hidden_states = self.w2(current_hidden_states)
65
+ return current_hidden_states
66
+
67
+
68
+ class MiniMaxM2Experts(nn.ModuleList):
69
+ """
70
+ ModuleList of experts.
71
+ """
72
+
73
+ def __init__(self, config: MiniMaxM2Config):
74
+ super().__init__()
75
+ self.top_k = config.num_experts_per_tok
76
+ self.num_experts = config.num_local_experts
77
+ for _ in range(self.num_experts):
78
+ self.append(MiniMaxM2MLP(config))
79
+
80
+ def forward(
81
+ self, hidden_states: torch.Tensor, top_k_index: torch.Tensor, top_k_weights: torch.Tensor
82
+ ) -> torch.Tensor:
83
+ """
84
+ Args:
85
+ hidden_states: (batch_size * sequence_length, hidden_dim)
86
+ selected_experts: (batch_size * sequence_length, top_k)
87
+ routing_weights: (batch_size * sequence_length, top_k)
88
+ Returns:
89
+ (batch_size * sequence_length, hidden_dim)
90
+ """
91
+ final_hidden_states = torch.zeros_like(hidden_states)
92
+ expert_mask = torch.nn.functional.one_hot(top_k_index, num_classes=self.num_experts).permute(2, 1, 0)
93
+
94
+ expert_hit = torch.greater(expert_mask.sum(dim=(-1, -2)), 0).nonzero()
95
+ for expert_idx in expert_hit:
96
+ idx, top_x = torch.where(expert_mask[expert_idx].squeeze(0))
97
+ current_state = hidden_states[None, top_x].reshape(-1, hidden_states.shape[-1])
98
+ current_hidden_states = self[expert_idx](current_state) * top_k_weights[top_x, idx, None]
99
+ final_hidden_states.index_add_(0, top_x, current_hidden_states.to(hidden_states.dtype))
100
+ return final_hidden_states
101
+
102
+
103
+ class MiniMaxM2SparseMoeBlock(nn.Module):
104
+ def __init__(self, config):
105
+ super().__init__()
106
+ self.top_k = config.num_experts_per_tok
107
+ self.jitter_noise = config.router_jitter_noise
108
+ self.gate = nn.Linear(config.hidden_size, config.num_local_experts, bias=False)
109
+ self.experts = MiniMaxM2Experts(config)
110
+ self.register_buffer("e_score_correction_bias", torch.zeros(config.num_local_experts))
111
+
112
+ def route_tokens_to_experts(self, router_logits):
113
+ routing_weights = torch.nn.functional.sigmoid(router_logits.float())
114
+ scores_for_choice = routing_weights + self.e_score_correction_bias
115
+ _, top_k_index = torch.topk(scores_for_choice, self.top_k, dim=-1, sorted=False)
116
+ top_k_weights = routing_weights.gather(1, top_k_index)
117
+ top_k_weights /= top_k_weights.sum(dim=-1, keepdim=True)
118
+ return top_k_index, top_k_weights.to(router_logits.dtype)
119
+
120
+ def forward(self, hidden_states: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
121
+ batch_size, sequence_length, hidden_dim = hidden_states.shape
122
+ if self.training and self.jitter_noise > 0:
123
+ hidden_states *= torch.empty_like(hidden_states).uniform_(1.0 - self.jitter_noise, 1.0 + self.jitter_noise)
124
+ hidden_states = hidden_states.view(-1, hidden_states.shape[-1])
125
+ router_logits = self.gate(hidden_states)
126
+ top_k_index, top_k_weights = self.route_tokens_to_experts(router_logits)
127
+ hidden_states = self.experts(hidden_states, top_k_index, top_k_weights.to(hidden_states.dtype))
128
+ hidden_states = hidden_states.reshape(batch_size, sequence_length, hidden_dim)
129
+ return hidden_states, router_logits
130
+
131
+
132
+ @use_kernel_forward_from_hub("RMSNorm")
133
+ class MiniMaxM2RMSNorm(nn.Module):
134
+ def __init__(self, hidden_size, eps=1e-6):
135
+ """
136
+ MiniMaxM2RMSNorm is equivalent to T5LayerNorm
137
+ """
138
+ super().__init__()
139
+ self.weight = nn.Parameter(torch.ones(hidden_size))
140
+ self.variance_epsilon = eps
141
+
142
+ def forward(self, hidden_states):
143
+ input_dtype = hidden_states.dtype
144
+ hidden_states = hidden_states.to(torch.float32)
145
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
146
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
147
+ return self.weight * hidden_states.to(input_dtype)
148
+
149
+ def extra_repr(self):
150
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
151
+
152
+
153
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
154
+ """
155
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
156
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
157
+ """
158
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
159
+ if n_rep == 1:
160
+ return hidden_states
161
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
162
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
163
+
164
+
165
+ def eager_attention_forward(
166
+ module: nn.Module,
167
+ query: torch.Tensor,
168
+ key: torch.Tensor,
169
+ value: torch.Tensor,
170
+ attention_mask: Optional[torch.Tensor],
171
+ scaling: float,
172
+ dropout: float = 0.0,
173
+ **kwargs: Unpack[TransformersKwargs],
174
+ ):
175
+ key_states = repeat_kv(key, module.num_key_value_groups)
176
+ value_states = repeat_kv(value, module.num_key_value_groups)
177
+
178
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
179
+ if attention_mask is not None:
180
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
181
+ attn_weights = attn_weights + causal_mask
182
+
183
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
184
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
185
+ attn_output = torch.matmul(attn_weights, value_states)
186
+ attn_output = attn_output.transpose(1, 2).contiguous()
187
+
188
+ return attn_output, attn_weights
189
+
190
+
191
+ def rotate_half(x):
192
+ """Rotates half the hidden dims of the input."""
193
+ x1 = x[..., : x.shape[-1] // 2]
194
+ x2 = x[..., x.shape[-1] // 2 :]
195
+ return torch.cat((-x2, x1), dim=-1)
196
+
197
+
198
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
199
+ """Applies Rotary Position Embedding to the query and key tensors.
200
+
201
+ Args:
202
+ q (`torch.Tensor`): The query tensor.
203
+ k (`torch.Tensor`): The key tensor.
204
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
205
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
206
+ position_ids (`torch.Tensor`, *optional*):
207
+ Deprecated and unused.
208
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
209
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
210
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
211
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
212
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
213
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
214
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
215
+ Returns:
216
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
217
+ """
218
+ cos = cos.unsqueeze(unsqueeze_dim)
219
+ sin = sin.unsqueeze(unsqueeze_dim)
220
+
221
+ # Keep half or full tensor for later concatenation
222
+ rotary_dim = cos.shape[-1]
223
+ q_rot, q_pass = q[..., :rotary_dim], q[..., rotary_dim:]
224
+ k_rot, k_pass = k[..., :rotary_dim], k[..., rotary_dim:]
225
+
226
+ # Apply rotary embeddings on the first half or full tensor
227
+ q_embed = (q_rot * cos) + (rotate_half(q_rot) * sin)
228
+ k_embed = (k_rot * cos) + (rotate_half(k_rot) * sin)
229
+
230
+ # Concatenate back to full shape
231
+ q_embed = torch.cat([q_embed, q_pass], dim=-1)
232
+ k_embed = torch.cat([k_embed, k_pass], dim=-1)
233
+ return q_embed, k_embed
234
+
235
+
236
+ class MiniMaxM2Attention(nn.Module):
237
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
238
+
239
+ def __init__(self, config: MiniMaxM2Config, layer_idx: int):
240
+ super().__init__()
241
+ self.config = config
242
+ self.layer_idx = layer_idx
243
+ self.head_dim = getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
244
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
245
+ self.scaling = self.head_dim**-0.5
246
+ self.attention_dropout = config.attention_dropout
247
+ self.is_causal = True
248
+ self.q_proj = nn.Linear(config.hidden_size, config.num_attention_heads * self.head_dim, bias=False)
249
+ self.k_proj = nn.Linear(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=False)
250
+ self.v_proj = nn.Linear(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=False)
251
+ self.o_proj = nn.Linear(config.num_attention_heads * self.head_dim, config.hidden_size, bias=False)
252
+
253
+ self.use_qk_norm = config.use_qk_norm
254
+ if self.use_qk_norm:
255
+ self.q_norm = MiniMaxM2RMSNorm(self.head_dim * config.num_attention_heads, eps=config.rms_norm_eps)
256
+ self.k_norm = MiniMaxM2RMSNorm(self.head_dim * config.num_key_value_heads, eps=config.rms_norm_eps)
257
+
258
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
259
+ def forward(
260
+ self,
261
+ hidden_states: torch.Tensor,
262
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
263
+ attention_mask: Optional[torch.Tensor],
264
+ past_key_values: Optional[Cache] = None,
265
+ cache_position: Optional[torch.LongTensor] = None,
266
+ **kwargs: Unpack[FlashAttentionKwargs],
267
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
268
+ input_shape = hidden_states.shape[:-1]
269
+ hidden_shape = (*input_shape, -1, self.head_dim)
270
+
271
+ query_states = self.q_proj(hidden_states)
272
+ key_states = self.k_proj(hidden_states)
273
+ value_states = self.v_proj(hidden_states)
274
+
275
+ if self.use_qk_norm: # main diff from Llama
276
+ query_states = self.q_norm(query_states)
277
+ key_states = self.k_norm(key_states)
278
+
279
+ key_states = key_states.view(hidden_shape)
280
+ query_states = query_states.view(hidden_shape)
281
+ value_states = value_states.view(hidden_shape)
282
+
283
+ query_states = query_states.transpose(1, 2)
284
+ key_states = key_states.transpose(1, 2)
285
+ value_states = value_states.transpose(1, 2)
286
+
287
+ cos, sin = position_embeddings
288
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
289
+
290
+ if past_key_values is not None:
291
+ # sin and cos are specific to RoPE models; position_ids needed for the static cache
292
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
293
+ key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_kwargs)
294
+
295
+ attention_interface: Callable = eager_attention_forward
296
+ if self.config._attn_implementation != "eager":
297
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
298
+
299
+ attn_output, attn_weights = attention_interface(
300
+ self,
301
+ query_states,
302
+ key_states,
303
+ value_states,
304
+ attention_mask,
305
+ dropout=0.0 if not self.training else self.attention_dropout,
306
+ scaling=self.scaling,
307
+ **kwargs,
308
+ )
309
+
310
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
311
+ attn_output = self.o_proj(attn_output)
312
+ return attn_output, attn_weights
313
+
314
+
315
+ class MiniMaxM2DecoderLayer(GradientCheckpointingLayer):
316
+ def __init__(self, config: MiniMaxM2Config, layer_idx: int):
317
+ super().__init__()
318
+ self.hidden_size = config.hidden_size
319
+
320
+ self.self_attn = MiniMaxM2Attention(config, layer_idx)
321
+
322
+ self.block_sparse_moe = MiniMaxM2SparseMoeBlock(config)
323
+ self.input_layernorm = MiniMaxM2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
324
+ self.post_attention_layernorm = MiniMaxM2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
325
+
326
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
327
+ def forward(
328
+ self,
329
+ hidden_states: torch.Tensor,
330
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
331
+ attention_mask: Optional[torch.Tensor] = None,
332
+ position_ids: Optional[torch.LongTensor] = None,
333
+ past_key_values: Optional[Cache] = None,
334
+ cache_position: Optional[torch.LongTensor] = None,
335
+ **kwargs: Unpack[TransformersKwargs],
336
+ ) -> torch.FloatTensor:
337
+ residual = hidden_states
338
+
339
+ hidden_states = self.input_layernorm(hidden_states)
340
+
341
+ # Self Attention
342
+ hidden_states, _ = self.self_attn(
343
+ hidden_states=hidden_states,
344
+ position_embeddings=position_embeddings,
345
+ attention_mask=attention_mask,
346
+ position_ids=position_ids,
347
+ past_key_values=past_key_values,
348
+ cache_position=cache_position,
349
+ **kwargs,
350
+ )
351
+ hidden_states = residual + hidden_states
352
+
353
+ # Fully Connected
354
+ residual = hidden_states
355
+ hidden_states = self.post_attention_layernorm(hidden_states)
356
+ hidden_states, _ = self.block_sparse_moe(hidden_states)
357
+ hidden_states = residual + hidden_states
358
+
359
+ return hidden_states
360
+
361
+
362
+ class MiniMaxM2RotaryEmbedding(nn.Module):
363
+ inv_freq: torch.Tensor # fix linting for `register_buffer`
364
+
365
+ def __init__(self, config: MiniMaxM2Config, device=None):
366
+ super().__init__()
367
+ # BC: "rope_type" was originally "type"
368
+ if hasattr(config, "rope_scaling") and isinstance(config.rope_scaling, dict):
369
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
370
+ else:
371
+ self.rope_type = "default"
372
+ self.max_seq_len_cached = config.max_position_embeddings
373
+ self.original_max_seq_len = config.max_position_embeddings
374
+
375
+ self.config = config
376
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
377
+
378
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
379
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
380
+ self.original_inv_freq = self.inv_freq
381
+
382
+ @torch.no_grad()
383
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
384
+ def forward(self, x, position_ids):
385
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
386
+ position_ids_expanded = position_ids[:, None, :].float()
387
+
388
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
389
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
390
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
391
+ emb = torch.cat((freqs, freqs), dim=-1)
392
+ cos = emb.cos() * self.attention_scaling
393
+ sin = emb.sin() * self.attention_scaling
394
+
395
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
396
+
397
+
398
+ @auto_docstring
399
+ class MiniMaxM2PreTrainedModel(PreTrainedModel):
400
+ config: MiniMaxM2Config
401
+ base_model_prefix = "model"
402
+ supports_gradient_checkpointing = True
403
+ _no_split_modules = ["MiniMaxM2DecoderLayer"]
404
+ _skip_keys_device_placement = ["past_key_values"]
405
+ _supports_flash_attn = True
406
+ _supports_sdpa = True
407
+ _supports_flex_attn = True
408
+ _can_compile_fullgraph = False # MoE models don't work with torch.compile (`torch.where(condition)` not supported)
409
+ _supports_attention_backend = True
410
+ _can_record_outputs = {
411
+ "router_logits": OutputRecorder(MiniMaxM2SparseMoeBlock, index=1),
412
+ "hidden_states": MiniMaxM2DecoderLayer,
413
+ "attentions": MiniMaxM2Attention,
414
+ }
415
+
416
+
417
+ @auto_docstring
418
+ class MiniMaxM2Model(MiniMaxM2PreTrainedModel):
419
+ def __init__(self, config: MiniMaxM2Config):
420
+ super().__init__(config)
421
+ self.padding_idx = config.pad_token_id
422
+ self.vocab_size = config.vocab_size
423
+
424
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
425
+ self.layers = nn.ModuleList(
426
+ [MiniMaxM2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
427
+ )
428
+ self.norm = MiniMaxM2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
429
+ self.rotary_emb = MiniMaxM2RotaryEmbedding(config=config)
430
+ self.gradient_checkpointing = False
431
+
432
+ # Initialize weights and apply final processing
433
+ self.post_init()
434
+
435
+ @check_model_inputs
436
+ @auto_docstring
437
+ def forward(
438
+ self,
439
+ input_ids: Optional[torch.LongTensor] = None,
440
+ attention_mask: Optional[torch.Tensor] = None,
441
+ position_ids: Optional[torch.LongTensor] = None,
442
+ past_key_values: Optional[Cache] = None,
443
+ inputs_embeds: Optional[torch.FloatTensor] = None,
444
+ use_cache: Optional[bool] = None,
445
+ cache_position: Optional[torch.LongTensor] = None,
446
+ **kwargs: Unpack[TransformersKwargs],
447
+ ) -> MoeModelOutputWithPast:
448
+ if (input_ids is None) ^ (inputs_embeds is not None):
449
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
450
+
451
+ if use_cache and past_key_values is None:
452
+ past_key_values = DynamicCache(config=self.config)
453
+
454
+ if inputs_embeds is None:
455
+ inputs_embeds = self.embed_tokens(input_ids)
456
+
457
+ if cache_position is None:
458
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
459
+ cache_position = torch.arange(
460
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
461
+ )
462
+ if position_ids is None:
463
+ position_ids = cache_position.unsqueeze(0)
464
+
465
+ mask_function = create_causal_mask if self.config.sliding_window is None else create_sliding_window_causal_mask
466
+ causal_mask = mask_function(
467
+ config=self.config,
468
+ input_embeds=inputs_embeds,
469
+ attention_mask=attention_mask,
470
+ cache_position=cache_position,
471
+ past_key_values=past_key_values,
472
+ position_ids=position_ids,
473
+ )
474
+
475
+ hidden_states = inputs_embeds
476
+
477
+ # create position embeddings to be shared across the decoder layers
478
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
479
+
480
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
481
+ hidden_states = decoder_layer(
482
+ hidden_states,
483
+ position_embeddings=position_embeddings,
484
+ attention_mask=causal_mask,
485
+ position_ids=position_ids,
486
+ past_key_values=past_key_values,
487
+ use_cache=use_cache,
488
+ cache_position=cache_position,
489
+ **kwargs,
490
+ )
491
+
492
+ hidden_states = self.norm(hidden_states)
493
+
494
+ return MoeModelOutputWithPast( # only diff with Mistral is the output type, we need MoE
495
+ last_hidden_state=hidden_states,
496
+ past_key_values=past_key_values,
497
+ )
498
+
499
+
500
+ def load_balancing_loss_func(
501
+ gate_logits: Union[torch.Tensor, tuple[torch.Tensor], None],
502
+ num_experts: Optional[int] = None,
503
+ top_k=2,
504
+ attention_mask: Optional[torch.Tensor] = None,
505
+ ) -> Union[torch.Tensor, int]:
506
+ r"""
507
+ Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.
508
+
509
+ See Switch Transformer (https://huggingface.co/papers/2101.03961) for more details. This function implements the loss
510
+ function presented in equations (4) - (6) of the paper. It aims at penalizing cases where the routing between
511
+ experts is too unbalanced.
512
+
513
+ Args:
514
+ gate_logits:
515
+ Logits from the `gate`, should be a tuple of model.config.num_hidden_layers tensors of
516
+ shape [batch_size X sequence_length, num_experts].
517
+ num_experts:
518
+ Number of experts
519
+ top_k:
520
+ The number of experts to route per-token, can be also interpreted as the `top-k` routing
521
+ parameter.
522
+ attention_mask (`torch.Tensor`, *optional*):
523
+ The attention_mask used in forward function
524
+ shape [batch_size X sequence_length] if not None.
525
+
526
+ Returns:
527
+ The auxiliary loss.
528
+ """
529
+ if gate_logits is None or not isinstance(gate_logits, tuple):
530
+ return 0
531
+
532
+ if isinstance(gate_logits, tuple):
533
+ compute_device = gate_logits[0].device
534
+ concatenated_gate_logits = torch.cat([layer_gate.to(compute_device) for layer_gate in gate_logits], dim=0)
535
+
536
+ routing_weights = torch.nn.functional.softmax(concatenated_gate_logits, dim=-1)
537
+
538
+ _, selected_experts = torch.topk(routing_weights, top_k, dim=-1)
539
+
540
+ expert_mask = torch.nn.functional.one_hot(selected_experts, num_experts)
541
+
542
+ if attention_mask is None:
543
+ # Compute the percentage of tokens routed to each experts
544
+ tokens_per_expert = torch.mean(expert_mask.float(), dim=0)
545
+
546
+ # Compute the average probability of routing to these experts
547
+ router_prob_per_expert = torch.mean(routing_weights, dim=0)
548
+ else:
549
+ batch_size, sequence_length = attention_mask.shape
550
+ num_hidden_layers = concatenated_gate_logits.shape[0] // (batch_size * sequence_length)
551
+
552
+ # Compute the mask that masks all padding tokens as 0 with the same shape of expert_mask
553
+ expert_attention_mask = (
554
+ attention_mask[None, :, :, None, None]
555
+ .expand((num_hidden_layers, batch_size, sequence_length, top_k, num_experts))
556
+ .reshape(-1, top_k, num_experts)
557
+ .to(compute_device)
558
+ )
559
+
560
+ # Compute the percentage of tokens routed to each experts
561
+ tokens_per_expert = torch.sum(expert_mask.float() * expert_attention_mask, dim=0) / torch.sum(
562
+ expert_attention_mask, dim=0
563
+ )
564
+
565
+ # Compute the mask that masks all padding tokens as 0 with the same shape of tokens_per_expert
566
+ router_per_expert_attention_mask = (
567
+ attention_mask[None, :, :, None]
568
+ .expand((num_hidden_layers, batch_size, sequence_length, num_experts))
569
+ .reshape(-1, num_experts)
570
+ .to(compute_device)
571
+ )
572
+
573
+ # Compute the average probability of routing to these experts
574
+ router_prob_per_expert = torch.sum(routing_weights * router_per_expert_attention_mask, dim=0) / torch.sum(
575
+ router_per_expert_attention_mask, dim=0
576
+ )
577
+
578
+ overall_loss = torch.sum(tokens_per_expert * router_prob_per_expert.unsqueeze(0))
579
+ return overall_loss * num_experts
580
+
581
+
582
+ @auto_docstring
583
+ class MiniMaxM2ForCausalLM(MiniMaxM2PreTrainedModel, GenerationMixin):
584
+ _tied_weights_keys = ["lm_head.weight"]
585
+ _tp_plan = {"lm_head": "colwise_rep"}
586
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
587
+
588
+ def __init__(self, config):
589
+ super().__init__(config)
590
+ self.model = MiniMaxM2Model(config)
591
+ self.vocab_size = config.vocab_size
592
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
593
+ self.router_aux_loss_coef = config.router_aux_loss_coef
594
+ self.num_experts = config.num_local_experts
595
+ self.num_experts_per_tok = config.num_experts_per_tok
596
+
597
+ # Initialize weights and apply final processing
598
+ self.post_init()
599
+
600
+ @can_return_tuple
601
+ @auto_docstring
602
+ def forward(
603
+ self,
604
+ input_ids: Optional[torch.LongTensor] = None,
605
+ attention_mask: Optional[torch.Tensor] = None,
606
+ position_ids: Optional[torch.LongTensor] = None,
607
+ past_key_values: Optional[Cache] = None,
608
+ inputs_embeds: Optional[torch.FloatTensor] = None,
609
+ labels: Optional[torch.LongTensor] = None,
610
+ use_cache: Optional[bool] = None,
611
+ output_router_logits: Optional[bool] = None,
612
+ cache_position: Optional[torch.LongTensor] = None,
613
+ logits_to_keep: Union[int, torch.Tensor] = 0,
614
+ **kwargs: Unpack[TransformersKwargs],
615
+ ) -> MoeCausalLMOutputWithPast:
616
+ r"""
617
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
618
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
619
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
620
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
621
+
622
+ Example:
623
+
624
+ ```python
625
+ >>> from transformers import AutoTokenizer, MiniMaxM2ForCausalLM
626
+
627
+ >>> model = MiniMaxM2ForCausalLM.from_pretrained("mistralai/MiniMaxM2-8x7B-v0.1")
628
+ >>> tokenizer = AutoTokenizer.from_pretrained("mistralai/MiniMaxM2-8x7B-v0.1")
629
+
630
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
631
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
632
+
633
+ >>> # Generate
634
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
635
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
636
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
637
+ ```"""
638
+
639
+ output_router_logits = (
640
+ output_router_logits if output_router_logits is not None else self.config.output_router_logits
641
+ )
642
+
643
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
644
+ outputs: MoeModelOutputWithPast = self.model(
645
+ input_ids=input_ids,
646
+ attention_mask=attention_mask,
647
+ position_ids=position_ids,
648
+ past_key_values=past_key_values,
649
+ inputs_embeds=inputs_embeds,
650
+ use_cache=use_cache,
651
+ output_router_logits=output_router_logits,
652
+ cache_position=cache_position,
653
+ **kwargs,
654
+ )
655
+
656
+ hidden_states = outputs.last_hidden_state
657
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
658
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
659
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
660
+
661
+ loss = None
662
+ if labels is not None:
663
+ loss = self.loss_function(logits, labels, self.vocab_size, **kwargs)
664
+
665
+ aux_loss = None
666
+ if output_router_logits:
667
+ aux_loss = load_balancing_loss_func(
668
+ outputs.router_logits,
669
+ self.num_experts,
670
+ self.num_experts_per_tok,
671
+ attention_mask,
672
+ )
673
+ if labels is not None:
674
+ loss += self.router_aux_loss_coef * aux_loss.to(loss.device) # make sure to reside in the same device
675
+
676
+ return MoeCausalLMOutputWithPast(
677
+ loss=loss,
678
+ aux_loss=aux_loss,
679
+ logits=logits,
680
+ past_key_values=outputs.past_key_values,
681
+ hidden_states=outputs.hidden_states,
682
+ attentions=outputs.attentions,
683
+ router_logits=outputs.router_logits,
684
+ )
685
+
686
+
687
+ class MiniMaxM2ForSequenceClassification(GenericForSequenceClassification, MiniMaxM2PreTrainedModel):
688
+ pass
689
+
690
+
691
+ class MiniMaxM2ForTokenClassification(GenericForTokenClassification, MiniMaxM2PreTrainedModel):
692
+ pass
693
+
694
+
695
+ class MiniMaxM2ForQuestionAnswering(GenericForQuestionAnswering, MiniMaxM2PreTrainedModel):
696
+ pass
697
+
698
+
699
+ __all__ = [
700
+ "MiniMaxM2ForCausalLM",
701
+ "MiniMaxM2ForQuestionAnswering",
702
+ "MiniMaxM2Model",
703
+ "MiniMaxM2PreTrainedModel",
704
+ "MiniMaxM2ForSequenceClassification",
705
+ "MiniMaxM2ForTokenClassification",
706
+ ]
special_tokens_map.json ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<code_interpreter>",
4
+ "<commit_after>",
5
+ "<commit_before>",
6
+ "<commit_msg>",
7
+ "<empty_output>",
8
+ "<filename>",
9
+ "<fim_middle>",
10
+ "<fim_pad>",
11
+ "<fim_prefix>",
12
+ "<fim_suffix>",
13
+ "<function_call>",
14
+ "<gh_stars>",
15
+ "]<]speech[>[",
16
+ "]<]image[>[",
17
+ "]<]video[>[",
18
+ "]<]start of speech[>[",
19
+ "]<]end of speech[>[",
20
+ "]<]start of image[>[",
21
+ "]<]end of image[>[",
22
+ "]<]start of video[>[",
23
+ "]<]end of video[>[",
24
+ "]<]vision pad[>[",
25
+ "]~!b[",
26
+ "<issue_closed>",
27
+ "<issue_comment>",
28
+ "<issue_start>",
29
+ "<jupyter_code>",
30
+ "<jupyter_output>",
31
+ "<jupyter_start>",
32
+ "<jupyter_text>",
33
+ "<reponame>",
34
+ "[e~[",
35
+ "]!d~[",
36
+ "]!p~[",
37
+ "]~b]",
38
+ "<jupyter_error>",
39
+ "<add_file>",
40
+ "<delete_file>",
41
+ "<rename_file>",
42
+ "<edit_file>",
43
+ "<commit_message>",
44
+ "<empty_source_file>",
45
+ "<repo_struct>",
46
+ "<code_context>",
47
+ "<file_content>",
48
+ "<source_files>",
49
+ "<pr_start>",
50
+ "<review_comment>",
51
+ "<filepath>",
52
+ "<file_sep>"
53
+ ],
54
+ "bos_token": {
55
+ "content": "]~!b[",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": false,
59
+ "single_word": false
60
+ },
61
+ "eos_token": {
62
+ "content": "[e~[",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false
67
+ },
68
+ "pad_token": "[e~[",
69
+ "unk_token": {
70
+ "content": "]!d~[",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false
75
+ }
76
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,495 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "200000": {
4
+ "content": "]!p~[",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "200001": {
12
+ "content": "<fim_prefix>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "200002": {
20
+ "content": "<fim_middle>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "200003": {
28
+ "content": "<fim_suffix>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "200004": {
36
+ "content": "<fim_pad>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "200005": {
44
+ "content": "<reponame>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "200006": {
52
+ "content": "<filename>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "200007": {
60
+ "content": "<gh_stars>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ },
67
+ "200008": {
68
+ "content": "<issue_start>",
69
+ "lstrip": false,
70
+ "normalized": false,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": true
74
+ },
75
+ "200009": {
76
+ "content": "<issue_comment>",
77
+ "lstrip": false,
78
+ "normalized": false,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": true
82
+ },
83
+ "200010": {
84
+ "content": "<issue_closed>",
85
+ "lstrip": false,
86
+ "normalized": false,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": true
90
+ },
91
+ "200011": {
92
+ "content": "<jupyter_start>",
93
+ "lstrip": false,
94
+ "normalized": false,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": true
98
+ },
99
+ "200012": {
100
+ "content": "<jupyter_text>",
101
+ "lstrip": false,
102
+ "normalized": false,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": true
106
+ },
107
+ "200013": {
108
+ "content": "<jupyter_code>",
109
+ "lstrip": false,
110
+ "normalized": false,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": true
114
+ },
115
+ "200014": {
116
+ "content": "<jupyter_output>",
117
+ "lstrip": false,
118
+ "normalized": false,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": true
122
+ },
123
+ "200015": {
124
+ "content": "<empty_output>",
125
+ "lstrip": false,
126
+ "normalized": false,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": true
130
+ },
131
+ "200016": {
132
+ "content": "<commit_before>",
133
+ "lstrip": false,
134
+ "normalized": false,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": true
138
+ },
139
+ "200017": {
140
+ "content": "<commit_msg>",
141
+ "lstrip": false,
142
+ "normalized": false,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": true
146
+ },
147
+ "200018": {
148
+ "content": "<commit_after>",
149
+ "lstrip": false,
150
+ "normalized": false,
151
+ "rstrip": false,
152
+ "single_word": false,
153
+ "special": true
154
+ },
155
+ "200019": {
156
+ "content": "]~b]",
157
+ "lstrip": false,
158
+ "normalized": false,
159
+ "rstrip": false,
160
+ "single_word": false,
161
+ "special": true
162
+ },
163
+ "200020": {
164
+ "content": "[e~[",
165
+ "lstrip": false,
166
+ "normalized": false,
167
+ "rstrip": false,
168
+ "single_word": false,
169
+ "special": true
170
+ },
171
+ "200021": {
172
+ "content": "]!d~[",
173
+ "lstrip": false,
174
+ "normalized": false,
175
+ "rstrip": false,
176
+ "single_word": false,
177
+ "special": true
178
+ },
179
+ "200022": {
180
+ "content": "<function_call>",
181
+ "lstrip": false,
182
+ "normalized": false,
183
+ "rstrip": false,
184
+ "single_word": false,
185
+ "special": true
186
+ },
187
+ "200023": {
188
+ "content": "<code_interpreter>",
189
+ "lstrip": false,
190
+ "normalized": false,
191
+ "rstrip": false,
192
+ "single_word": false,
193
+ "special": true
194
+ },
195
+ "200024": {
196
+ "content": "]<]speech[>[",
197
+ "lstrip": false,
198
+ "normalized": false,
199
+ "rstrip": false,
200
+ "single_word": false,
201
+ "special": true
202
+ },
203
+ "200025": {
204
+ "content": "]<]image[>[",
205
+ "lstrip": false,
206
+ "normalized": false,
207
+ "rstrip": false,
208
+ "single_word": false,
209
+ "special": true
210
+ },
211
+ "200026": {
212
+ "content": "]<]video[>[",
213
+ "lstrip": false,
214
+ "normalized": false,
215
+ "rstrip": false,
216
+ "single_word": false,
217
+ "special": true
218
+ },
219
+ "200027": {
220
+ "content": "]<]start of speech[>[",
221
+ "lstrip": false,
222
+ "normalized": false,
223
+ "rstrip": false,
224
+ "single_word": false,
225
+ "special": true
226
+ },
227
+ "200028": {
228
+ "content": "]<]end of speech[>[",
229
+ "lstrip": false,
230
+ "normalized": false,
231
+ "rstrip": false,
232
+ "single_word": false,
233
+ "special": true
234
+ },
235
+ "200029": {
236
+ "content": "]<]start of image[>[",
237
+ "lstrip": false,
238
+ "normalized": false,
239
+ "rstrip": false,
240
+ "single_word": false,
241
+ "special": true
242
+ },
243
+ "200030": {
244
+ "content": "]<]end of image[>[",
245
+ "lstrip": false,
246
+ "normalized": false,
247
+ "rstrip": false,
248
+ "single_word": false,
249
+ "special": true
250
+ },
251
+ "200031": {
252
+ "content": "]<]start of video[>[",
253
+ "lstrip": false,
254
+ "normalized": false,
255
+ "rstrip": false,
256
+ "single_word": false,
257
+ "special": true
258
+ },
259
+ "200032": {
260
+ "content": "]<]end of video[>[",
261
+ "lstrip": false,
262
+ "normalized": false,
263
+ "rstrip": false,
264
+ "single_word": false,
265
+ "special": true
266
+ },
267
+ "200033": {
268
+ "content": "]<]vision pad[>[",
269
+ "lstrip": false,
270
+ "normalized": false,
271
+ "rstrip": false,
272
+ "single_word": false,
273
+ "special": true
274
+ },
275
+ "200034": {
276
+ "content": "]~!b[",
277
+ "lstrip": false,
278
+ "normalized": false,
279
+ "rstrip": false,
280
+ "single_word": false,
281
+ "special": true
282
+ },
283
+ "200035": {
284
+ "content": "<jupyter_error>",
285
+ "lstrip": false,
286
+ "normalized": false,
287
+ "rstrip": false,
288
+ "single_word": false,
289
+ "special": true
290
+ },
291
+ "200036": {
292
+ "content": "<add_file>",
293
+ "single_word": false,
294
+ "lstrip": false,
295
+ "rstrip": false,
296
+ "normalized": false,
297
+ "special": true
298
+ },
299
+ "200037": {
300
+ "content": "<delete_file>",
301
+ "lstrip": false,
302
+ "normalized": false,
303
+ "rstrip": false,
304
+ "single_word": false,
305
+ "special": true
306
+ },
307
+ "200038": {
308
+ "content": "<rename_file>",
309
+ "lstrip": false,
310
+ "normalized": false,
311
+ "rstrip": false,
312
+ "single_word": false,
313
+ "special": true
314
+ },
315
+ "200039": {
316
+ "content": "<edit_file>",
317
+ "lstrip": false,
318
+ "normalized": false,
319
+ "rstrip": false,
320
+ "single_word": false,
321
+ "special": true
322
+ },
323
+ "200040": {
324
+ "content": "<commit_message>",
325
+ "lstrip": false,
326
+ "normalized": false,
327
+ "rstrip": false,
328
+ "single_word": false,
329
+ "special": true
330
+ },
331
+ "200041": {
332
+ "content": "<empty_source_file>",
333
+ "lstrip": false,
334
+ "normalized": false,
335
+ "rstrip": false,
336
+ "single_word": false,
337
+ "special": true
338
+ },
339
+ "200042": {
340
+ "content": "<repo_struct>",
341
+ "lstrip": false,
342
+ "normalized": false,
343
+ "rstrip": false,
344
+ "single_word": false,
345
+ "special": true
346
+ },
347
+ "200043": {
348
+ "content": "<code_context>",
349
+ "single_word": false,
350
+ "lstrip": false,
351
+ "rstrip": false,
352
+ "normalized": false,
353
+ "special": true
354
+ },
355
+ "200044": {
356
+ "content": "<file_content>",
357
+ "single_word": false,
358
+ "lstrip": false,
359
+ "rstrip": false,
360
+ "normalized": false,
361
+ "special": true
362
+ },
363
+ "200045": {
364
+ "content": "<source_files>",
365
+ "single_word": false,
366
+ "lstrip": false,
367
+ "rstrip": false,
368
+ "normalized": false,
369
+ "special": true
370
+ },
371
+ "200046": {
372
+ "content": "<pr_start>",
373
+ "single_word": false,
374
+ "lstrip": false,
375
+ "rstrip": false,
376
+ "normalized": false,
377
+ "special": true
378
+ },
379
+ "200047": {
380
+ "content": "<review_comment>",
381
+ "single_word": false,
382
+ "lstrip": false,
383
+ "rstrip": false,
384
+ "normalized": false,
385
+ "special": true
386
+ },
387
+ "200048": {
388
+ "content": "<filepath>",
389
+ "single_word": false,
390
+ "lstrip": false,
391
+ "rstrip": false,
392
+ "normalized": false,
393
+ "special": true
394
+ },
395
+ "200049": {
396
+ "content": "<file_sep>",
397
+ "single_word": false,
398
+ "lstrip": false,
399
+ "rstrip": false,
400
+ "normalized": false,
401
+ "special": true
402
+ },
403
+ "200050": {
404
+ "content": "<think>",
405
+ "single_word": false,
406
+ "lstrip": false,
407
+ "rstrip": false,
408
+ "normalized": false,
409
+ "special": false
410
+ },
411
+ "200051": {
412
+ "content": "</think>",
413
+ "single_word": false,
414
+ "lstrip": false,
415
+ "rstrip": false,
416
+ "normalized": false,
417
+ "special": false
418
+ },
419
+ "200052": {
420
+ "content": "<minimax:tool_call>",
421
+ "single_word": false,
422
+ "lstrip": false,
423
+ "rstrip": false,
424
+ "normalized": false,
425
+ "special": false
426
+ },
427
+ "200053": {
428
+ "content": "</minimax:tool_call>",
429
+ "single_word": false,
430
+ "lstrip": false,
431
+ "rstrip": false,
432
+ "normalized": false,
433
+ "special": false
434
+ }
435
+ },
436
+ "additional_special_tokens": [
437
+ "<code_interpreter>",
438
+ "<commit_after>",
439
+ "<commit_before>",
440
+ "<commit_msg>",
441
+ "<empty_output>",
442
+ "<filename>",
443
+ "<fim_middle>",
444
+ "<fim_pad>",
445
+ "<fim_prefix>",
446
+ "<fim_suffix>",
447
+ "<function_call>",
448
+ "<gh_stars>",
449
+ "]<]speech[>[",
450
+ "]<]image[>[",
451
+ "]<]video[>[",
452
+ "]<]start of speech[>[",
453
+ "]<]end of speech[>[",
454
+ "]<]start of image[>[",
455
+ "]<]end of image[>[",
456
+ "]<]start of video[>[",
457
+ "]<]end of video[>[",
458
+ "]<]vision pad[>[",
459
+ "]~!b[",
460
+ "<issue_closed>",
461
+ "<issue_comment>",
462
+ "<issue_start>",
463
+ "<jupyter_code>",
464
+ "<jupyter_output>",
465
+ "<jupyter_start>",
466
+ "<jupyter_text>",
467
+ "<reponame>",
468
+ "[e~[",
469
+ "]!d~[",
470
+ "]!p~[",
471
+ "]~b]",
472
+ "<jupyter_error>",
473
+ "<add_file>",
474
+ "<delete_file>",
475
+ "<rename_file>",
476
+ "<edit_file>",
477
+ "<commit_message>",
478
+ "<empty_source_file>",
479
+ "<repo_struct>",
480
+ "<code_context>",
481
+ "<file_content>",
482
+ "<source_files>",
483
+ "<pr_start>",
484
+ "<review_comment>",
485
+ "<filepath>",
486
+ "<file_sep>"
487
+ ],
488
+ "add_prefix_space": false,
489
+ "bos_token": "]~!b[",
490
+ "clean_up_tokenization_spaces": false,
491
+ "eos_token": "[e~[",
492
+ "model_max_length": 40960000,
493
+ "tokenizer_class": "GPT2Tokenizer",
494
+ "unk_token": "]!d~["
495
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff