Commit ·
b0234bb
0
Parent(s):
Mach-2 Additive Medium
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributesAdded+37
- LICENSEAdded+202
- MANIFEST.jsonAdded+21
- README.mdAdded+64
- assets/size_vs_performance.pngAdded
- chat_template.jinjaAdded+170
- config.jsonAdded+154
- decode.pyAdded+404
- draft/mtp_q4g64.safetensorsAdded+3
- extras.safetensorsAdded+3
- generation_config.jsonAdded+12
- merges.txtAdded
- packed/experts/L00.safetensorsAdded+3
- packed/experts/L01.safetensorsAdded+3
- packed/experts/L02.safetensorsAdded+3
- packed/experts/L03.safetensorsAdded+3
- packed/experts/L04.safetensorsAdded+3
- packed/experts/L05.safetensorsAdded+3
- packed/experts/L06.safetensorsAdded+3
- packed/experts/L07.safetensorsAdded+3
- packed/experts/L08.safetensorsAdded+3
- packed/experts/L09.safetensorsAdded+3
- packed/experts/L10.safetensorsAdded+3
- packed/experts/L11.safetensorsAdded+3
- packed/experts/L12.safetensorsAdded+3
- packed/experts/L13.safetensorsAdded+3
- packed/experts/L14.safetensorsAdded+3
- packed/experts/L15.safetensorsAdded+3
- packed/experts/L16.safetensorsAdded+3
- packed/experts/L17.safetensorsAdded+3
- packed/experts/L18.safetensorsAdded+3
- packed/experts/L19.safetensorsAdded+3
- packed/experts/L20.safetensorsAdded+3
- packed/experts/L21.safetensorsAdded+3
- packed/experts/L22.safetensorsAdded+3
- packed/experts/L23.safetensorsAdded+3
- packed/experts/L24.safetensorsAdded+3
- packed/experts/L25.safetensorsAdded+3
- packed/experts/L26.safetensorsAdded+3
- packed/experts/L27.safetensorsAdded+3
- packed/experts/L28.safetensorsAdded+3
- packed/experts/L29.safetensorsAdded+3
- packed/experts/L30.safetensorsAdded+3
- packed/experts/L31.safetensorsAdded+3
- packed/experts/L32.safetensorsAdded+3
- packed/experts/L33.safetensorsAdded+3
- packed/experts/L34.safetensorsAdded+3
- packed/experts/L35.safetensorsAdded+3
- packed/experts/L36.safetensorsAdded+3
- packed/experts/L37.safetensorsAdded+3
12345678910111213141516171819202122232425262728293031323334353637*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -textassets/size_vs_performance.png filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2026 Alibaba Cloud
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.123456789101112131415161718192021{ "model": "Mach-2 Additive Medium", "format": "fn_packed_v2", "base_model": "Qwen/Qwen3.8-Flash-Next@de4b8e4d43b917e7706784d8bb445c9af86a3540", "text_params": 125743653760, "text_bpw": 1.69982, "bytes": { "experts": 23638716680, "non_expert": 2504915216, "head": 417180688, "extras": 156822168, "text_total": 26717634752, "ngram_table_bf16": 102400513984 }, "not_shipped": "Vision weights and the bf16 MTP layer, outside the text budget; decode.py materialize copies them from the base repo", "mtp": { "path": "draft/mtp_q4g64.safetensors", "format": "fn_mtp_q_v1", "sha256": "c5d20938036e4e53e3de0ba8a805f9d544d5aabac6665e0a4dc5833418cff3be" }}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364---license: apache-2.0base_model: Qwen/Qwen3.8-Flash-Nexttags:- qwen- mach-2- additive- mixture-of-experts---

# Mach-2 Additive Medium
Mach-2 Additive Medium is Qwen3.8-Flash-Next at **1.70 bits per weight**: 26.7 GB for the 125.7B text parameters, plusthe model's n-gram embedding table at bf16 (102.4 GB).
## Benchmarks

Retention is Mach-2 Additive Medium's score divided by that of Qwen3.8-Flash-Next BF16, with both run on the sameharness, settings and tasks.
| Benchmark | Tasks | Mach-2 Additive Medium | BF16 | Retention || --- | ---: | ---: | ---: | ---: || Humanity's Last Exam (text) | 2,158 | 33.87 | 39.85 | 85.0% || GPQA Diamond | 198 x 5 | 90.51 | 92.22 | 98.1% || AIME 2026 | 30 x 8 | 96.25 | 95.83 | 100.4% || Terminal-Bench 2.1 | 89 | 78.65 | 82.02 | 95.9% || AutomationBench 1.0.6 | 600 | 71.67 | 70.29 | 102.0% || NL2Repo | 98 | 56.12 | 60.06 | 93.4% || DeepSWE v1.1 | 113 | 48.67 | 49.56 | 98.2% || τ³-Banking | 97 x 5 | 45.10 | 46.41 | 97.2% |
- **Humanity's Last Exam**: up to 163,840 output tokens, graded by Artificial Analysis's judge.- **GPQA Diamond**: mean accuracy over 5 samples per question. Answers that reached 81,920 tokens were re-asked at 163,840.- **AIME 2026**: mean accuracy over 8 samples per problem, up to 81,920 output tokens.- **Terminal-Bench 2.1**: Terminus 2, one attempt per task, 4 hours per task.- **AutomationBench**: up to 50 steps per task, scored by Artificial Analysis's rule.- **NL2Repo**: OpenHands without internet access; the 102 tasks BF16 finished, less 4 whose BF16 test run hit the 1-hour scoring limit. Test runs cut at that limit are left out rather than scored 0. Mach-2 Additive Medium's score averages two runs.- **DeepSWE**: Claude Code as the agent, all 113 tasks, up to 10.5 hours per task. A task counts as solved only if the agent solved it within 700 steps.- **τ³-Banking**: tau2-bench 1.0.1, 5 trials per task, GPT-5.4 mini as the simulated user and judge, as Artificial Analysis runs it. Pass rate over the 459 conversations both models completed; 26 that outgrew the context window or lost the simulated user to an API error are left out.
Empty answers and answers still unfinished at the token limit score 0. Agents and limits differ from those behindQwen's model card, so compare these columns with each other rather than with scores published elsewhere.
## Use
Run Mach-2 Additive Medium from its compressed weights with[Mach-2 Additive Medium GGUF](https://huggingface.co/SyzygyResearch/Mach-2-Additive-Medium-GGUF) and the[Mach-1 fork of llama.cpp](https://github.com/SyzygyResearch/llama.cpp-mach1). The 26.7 GB of weights fit on one GPUwith 32 GB or more.
Sample at temperature 1.0, top_p 0.95, top_k 20 (`generation_config.json`). Without these settings the model can loop.
This repository holds the packed weights; `decode.py` documents the packed format. `draft/mtp_q4g64.safetensors` is thebase model's MTP layer at 4 bits (group size 64) for speculative decoding with MLX.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170{%- set image_count = namespace(value=0) %}{%- set video_count = namespace(value=0) %}{%- macro render_content(content, do_vision_count, is_system_content=false) %} {%- if content is string %} {{- content }} {%- elif content is iterable and content is not mapping %} {%- for item in content %} {%- if 'image' in item or 'image_url' in item or item.type == 'image' %} {%- if is_system_content %} {{- raise_exception('System message cannot contain images.') }} {%- endif %} {%- if do_vision_count %} {%- set image_count.value = image_count.value + 1 %} {%- endif %} {%- if add_vision_id %} {{- 'Picture ' ~ image_count.value ~ ': ' }} {%- endif %} {{- '<|vision_start|><|image_pad|><|vision_end|>' }} {%- elif 'video' in item or item.type == 'video' %} {%- if is_system_content %} {{- raise_exception('System message cannot contain videos.') }} {%- endif %} {%- if do_vision_count %} {%- set video_count.value = video_count.value + 1 %} {%- endif %} {%- if add_vision_id %} {{- 'Video ' ~ video_count.value ~ ': ' }} {%- endif %} {{- '<|vision_start|><|video_pad|><|vision_end|>' }} {%- elif 'text' in item %} {{- item.text }} {%- else %} {{- raise_exception('Unexpected item type in content.') }} {%- endif %} {%- endfor %} {%- elif content is none or content is undefined %} {{- '' }} {%- else %} {{- raise_exception('Unexpected content type.') }} {%- endif %}{%- endmacro %}{%- if not messages %} {{- raise_exception('No messages provided.') }}{%- endif %}{%- set reasoning_instructions = '' %}{%- if enable_thinking is undefined or enable_thinking is true %} {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %} {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %} {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }} {%- endif %} {%- if resolved_reasoning_effort == 'xhigh' %} {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %} {%- elif resolved_reasoning_effort == 'low' %} {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %} {%- endif %}{%- endif %}{%- if tools and tools is iterable and tools is not mapping %} {{- '<|im_start|>system\n' }} {%- if reasoning_instructions %} {{- reasoning_instructions + '\n\n' }} {%- endif %} {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }} {%- for tool in tools %} {{- "\n" }} {{- tool | tojson }} {%- endfor %} {{- "\n</tools>" }} {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }} {%- if messages[0].role == 'system' %} {%- set content = render_content(messages[0].content, false, true)|trim %} {%- if content %} {{- '\n\n' + content }} {%- endif %} {%- endif %} {{- '<|im_end|>\n' }}{%- else %} {%- if messages[0].role == 'system' %} {%- set content = render_content(messages[0].content, false, true)|trim %} {%- if content %} {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }} {%- elif reasoning_instructions %} {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }} {%- endif %} {%- elif reasoning_instructions %} {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }} {%- endif %}{%- endif %}{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}{%- for message in messages[::-1] %} {%- set index = (messages|length - 1) - loop.index0 %} {%- if ns.multi_step_tool and message.role == "user" %} {%- set content = render_content(message.content, false)|trim %} {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %} {%- set ns.multi_step_tool = false %} {%- set ns.last_query_index = index %} {%- endif %} {%- endif %}{%- endfor %}{%- if ns.multi_step_tool %} {{- raise_exception('No user query found in messages.') }}{%- endif %}{%- for message in messages %} {%- set content = render_content(message.content, true)|trim %} {%- if message.role == "system" %} {%- if not loop.first %} {{- raise_exception('System message must be at the beginning.') }} {%- endif %} {%- elif message.role == "user" %} {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }} {%- elif message.role == "assistant" %} {%- set reasoning_content = '' %} {%- if message.reasoning_content is string %} {%- set reasoning_content = message.reasoning_content %} {%- endif %} {%- set reasoning_content = reasoning_content|trim %} {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %} {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }} {%- else %} {{- '<|im_start|>' + message.role + '\n' + content }} {%- endif %} {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {%- if loop.first %} {%- if content|trim %} {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }} {%- else %} {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }} {%- endif %} {%- else %} {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }} {%- endif %} {%- if tool_call.arguments is defined and tool_call.arguments != '' %} {%- for args_name, args_value in tool_call.arguments|items %} {{- '<parameter=' + args_name + '>\n' }} {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %} {{- args_value }} {{- '\n</parameter>\n' }} {%- endfor %} {%- endif %} {{- '</function>\n</tool_call>' }} {%- endfor %} {%- endif %} {{- '<|im_end|>\n' }} {%- elif message.role == "tool" %} {%- if loop.previtem and loop.previtem.role != "tool" %} {{- '<|im_start|>user' }} {%- endif %} {{- '\n<tool_response>\n' }} {{- content }} {{- '\n</tool_response>' }} {%- if not loop.last and loop.nextitem.role != "tool" %} {{- '<|im_end|>\n' }} {%- elif loop.last %} {{- '<|im_end|>\n' }} {%- endif %} {%- else %} {{- raise_exception('Unexpected message role.') }} {%- endif %}{%- endfor %}{%- if add_generation_prompt %} {{- '<|im_start|>assistant\n' }} {%- if enable_thinking is defined and enable_thinking is false %} {{- '<think>\n\n</think>\n\n' }} {%- else %} {{- '<think>\n' }} {%- endif %}{%- endif %}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154{ "architectures": [ "Qwen4ExpForConditionalGeneration" ], "image_token_id": 248056, "language_model_only": false, "model_type": "qwen4_exp", "text_config": { "attention_bias": false, "attention_dropout": 0.0, "bos_token_id": 248044, "dtype": "bfloat16", "eos_token_id": 248044, "full_attention_interval": 4, "hc_count": 4, "hc_lowrank": 320, "head_dim": 256, "heads_per_ngram": 8, "hidden_act": "silu", "hidden_size": 2560, "indexer_budget": 2048, "indexer_compress_ratio": 4, "indexer_head_dim": 128, "indexer_kv_heads": 1, "indexer_n_heads": 4, "initializer_range": 0.02, "layer_types": [ "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention", "linear_attention", "linear_attention", "linear_attention", "full_attention" ], "linear_conv_kernel_dim": 4, "linear_key_head_dim": 128, "linear_num_key_heads": 16, "linear_num_value_heads": 48, "linear_value_head_dim": 128, "make_ngram_vocab_size_divisible_by": 128, "mamba_ssm_dtype": "float32", "max_position_embeddings": 262144, "model_type": "qwen4_exp_text", "moe_intermediate_size": 640, "mtp": { "hybrid": true, "layer_types": [ "full_attention" ], "mtp_use_hidden_state_from_layer": null, "num_hidden_layers": 1, "rope_theta": 10000000 }, "mtp_num_hidden_layers": 1, "mtp_use_dedicated_embeddings": false, "ngram_size": 3, "ngram_vocab_size_base": 20000000, "num_attention_heads": 24, "num_experts": 512, "num_experts_per_tok": 10, "num_hidden_layers": 48, "num_key_value_heads": 2, "output_gate_type": "sigmoid", "output_router_logits": false, "pad_token_id": null, "partial_rotary_factor": 0.25, "ple_conv_kernel_size": 4, "ple_embed_dim": 2560, "ple_layer_ids": [ 2 ], "rms_norm_eps": 1e-06, "rope_parameters": { "mrope_interleaved": true, "mrope_section": [ 11, 11, 10 ], "partial_rotary_factor": 0.25, "rope_theta": 10000000, "rope_type": "default" }, "router_aux_loss_coef": 0.001, "shared_expert_intermediate_size": 640, "split_ngram_parts": 128, "tie_word_embeddings": false, "use_cache": true, "vocab_size": 248320 }, "tie_word_embeddings": false, "transformers_version": "5.8.0.dev0", "video_token_id": 248057, "vision_config": { "deepstack_visual_indexes": [], "depth": 27, "hidden_act": "gelu_pytorch_tanh", "hidden_size": 1152, "in_channels": 3, "initializer_range": 0.02, "intermediate_size": 4304, "model_type": "qwen4_exp", "num_heads": 16, "num_position_embeddings": 2304, "out_hidden_size": 2560, "patch_size": 16, "spatial_merge_size": 2, "temporal_patch_size": 2 }, "vision_end_token_id": 248054, "vision_start_token_id": 248053}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404#!/usr/bin/env python3"""Decode the packed Mach-2 Additive Medium checkpoint into a bf16 Hugging Face checkpoint.
python decode.py materialize --packed-dir . --out /path/ckpt [--workers 8] [--no-base]"""import argparseimport hashlibimport jsonimport mathimport os
import numpy as np
HIDDEN, INTER, NEXP, NLAYERS = 2560, 640, 512, 48BASE_REPO, BASE_REVISION = "Qwen/Qwen3.8-Flash-Next", "de4b8e4d43b917e7706784d8bb445c9af86a3540"FORMAT = "fn_packed_v2"
def _hmat(q_elems, chi, sub): n = len(q_elems) Q = np.array([[chi(sub(q_elems[i], q_elems[j])) for j in range(n)] for i in range(n)], np.float64) C = np.zeros((n + 1, n + 1)) C[0, 1:] = 1.0 C[1:, 0] = 1.0 C[1:, 1:] = Q A = np.array([[1.0, 1.0], [1.0, -1.0]]) B = np.array([[1.0, -1.0], [-1.0, -1.0]]) H = np.kron(C, A) + np.kron(np.eye(n + 1), B) r = 2 * (n + 1) assert np.array_equal(H, H.T) and np.array_equal(H @ H, r * np.eye(r)) return H.astype(np.float32)
def hadamard_12(): chi5 = {0: 0, 1: 1, 2: -1, 3: -1, 4: 1} return _hmat(list(range(5)), lambda e: chi5[e], lambda u, v: (u - v) % 5)
def hadamard_20(): els = [(a, b) for a in range(3) for b in range(3)]
def mul(u, v): (a, b), (c, d) = u, v return ((a * c - b * d) % 3, (a * d + b * c) % 3) squares = {mul(e, e) for e in els if e != (0, 0)} return _hmat(els, lambda e: 0 if e == (0, 0) else (1 if e in squares else -1), lambda u, v: ((u[0] - v[0]) % 3, (u[1] - v[1]) % 3))
_HS = { 12: ["+-----------", "++-+---+++-+", "+++-+---+++-", "+-++-+---+++", "++-++-+---++", "+++-++-+---+", "++++-++-+---", "+-+++-++-+--", "+--+++-++-+-", "+---+++-++-+", "++---+++-++-", "+-+---+++-++"], 20: ["+-------------------", "++-++----+-+-++++--+", "+++-++----+-+-++++--", "+-++-++----+-+-++++-", "+--++-++----+-+-++++", "++--++-++----+-+-+++", "+++--++-++----+-+-++", "++++--++-++----+-+-+", "+++++--++-++----+-+-", "+-++++--++-++----+-+", "++-++++--++-++----+-", "+-+-++++--++-++----+", "++-+-++++--++-++----", "+-+-+-++++--++-++---", "+--+-+-++++--++-++--", "+---+-+-++++--++-++-", "+----+-+-++++--++-++", "++----+-+-++++--++-+", "+++----+-+-++++--++-", "+-++----+-+-++++--++"],}_HR = {}
def _hr(kind, radix): if (kind, radix) not in _HR: if kind == "spine": H = np.array([[1.0 if c == "+" else -1.0 for c in r] for r in _HS[radix]], np.float32) assert np.array_equal(H @ H.T, radix * np.eye(radix, dtype=np.float32)) else: H = hadamard_12() if radix == 12 else hadamard_20() _HR[(kind, radix)] = H return _HR[(kind, radix)]
def hadamard(x, kind="expert"): x = np.asarray(x, np.float32) shape, N = x.shape, x.shape[-1] if N & (N - 1): radix = 12 if (N % 12 == 0 and (N // 12) & (N // 12 - 1) == 0) else 20 M = N // radix assert N % radix == 0 and M & (M - 1) == 0, f"Hadamard needs 2^k, 12*2^k or 20*2^k, got {N}" if kind == "spine": xb = _butterflies(x.reshape(-1, radix, M)) if M > 1 else x.reshape(-1, radix, 1) return (np.matmul(_hr(kind, radix), xb) / np.float32(math.sqrt(N))).reshape(shape) xb = hadamard(x.reshape(-1, radix, M)) if M > 1 else x.reshape(-1, radix, 1) return (np.matmul(_hr(kind, radix), xb) / np.float32(math.sqrt(radix))).reshape(shape) return (_butterflies(x) / np.float32(math.sqrt(N))).reshape(shape)
def _butterflies(x): N = x.shape[-1] cur = np.ascontiguousarray(x, np.float32).reshape(-1, N) span = 1 while span < N: blk = cur.reshape(-1, N // (2 * span), 2, span) cur = np.stack([blk[:, :, 0] + blk[:, :, 1], blk[:, :, 0] - blk[:, :, 1]], 2).reshape(-1, N) span *= 2 return cur.reshape(x.shape)
def bf16_round(x): u = np.ascontiguousarray(x, np.float32).view(np.uint32) return ((u + np.uint32(0x7FFF) + ((u >> np.uint32(16)) & np.uint32(1))) & np.uint32(0xFFFF0000)).view(np.float32)
def _read(path): from safetensors import safe_open with safe_open(path, framework="np") as fh: return {k: fh.get_tensor(k) for k in fh.keys()}, dict(fh.metadata() or {})
EX_V, EX_L, EX_TD = 4, 16, 16EX_SHAPES = {"gate": (INTER, HIDDEN), "up": (INTER, HIDDEN), "down": (HIDDEN, INTER)}
def _ex_states(words, K4): words = np.asarray(words).view(np.uint16).astype(np.int64) rows, nstep, step = words.shape[0], EX_TD * EX_TD // EX_V, int(K4) bits = ((words[:, :, None] >> np.arange(15, -1, -1)) & 1).reshape(rows, -1)[:, :step * nstep] bits = np.concatenate([bits, bits[:, :EX_L - step]], axis=1) w = 1 << np.arange(EX_L - 1, -1, -1, dtype=np.int64) idx = np.arange(nstep)[:, None] * step + np.arange(EX_L)[None, :] return bits[:, idx] @ w
def wave_map(Mb, Nb): starts = [(Mb - i - 1, Nb - 1) for i in range(Mb)] + [(0, Nb - i - 1) for i in range(Nb)] idx = np.zeros((Mb, Nb), dtype=np.int64) for w, (jm, jn) in enumerate(starts): while 0 <= jm < Mb and 0 <= jn < Nb: idx[jm, jn] = w jm, jn = jm + 1, jn - 1 return idx
def sign_seed(layer, expert, proj, side, ns="canon"): return int.from_bytes(hashlib.sha256(f"{ns}|L{layer}|e{expert}|{proj}|{side}".encode()).digest()[:7], "big")
_PM0, _PM1 = np.uint64(0xD2511F53), np.uint64(0xCD9E8D57)_PW0, _PW1, _PMASK = np.uint64(0x9E3779B9), np.uint64(0xBB67AE85), np.uint64(0xFFFFFFFF)
def expert_signs(seeds, dim): E = len(seeds) c2 = np.tile(np.arange(dim, dtype=np.uint64), E) k0 = np.repeat(np.array([s & 0xFFFFFFFF for s in seeds], np.uint64), dim) k1 = np.repeat(np.array([s >> 32 for s in seeds], np.uint64), dim) c0 = c1 = c3 = np.zeros(E * dim, np.uint64) for r in range(10): if r: k0, k1 = (k0 + _PW0) & _PMASK, (k1 + _PW1) & _PMASK p0, p1 = _PM0 * c0, _PM1 * c2 c0, c1, c2, c3 = (p1 >> np.uint64(32)) ^ c1 ^ k0, p1 & _PMASK, (p0 >> np.uint64(32)) ^ c3 ^ k1, p0 & _PMASK inv2pi = np.float32(2 * np.pi / 2 ** 32) v = (c1.astype(np.float32) * inv2pi + inv2pi / np.float32(2)).astype(np.float32) u = (c0.astype(np.float32) * np.float32(2.0 ** -32) + np.float32(2.0 ** -33)).astype(np.float32) return np.where((v <= np.float32(np.pi)) | (u == np.float32(1.0)), 1.0, -1.0).astype(np.float32).reshape(E, dim)
def _lut(cb, K4): return np.asarray(cb.get(f"lut.k{K4}", cb["lut"]), np.float32)
def decode_expert(t, cb, proj, e): m, n = EX_SHAPES[proj] K4 = int(t[f"{proj}.rate_k4"][e]) ex = np.asarray(t[f"k{K4}.{proj}.experts"]) row = int(np.searchsorted(ex, e)) assert row < ex.size and ex[row] == e, (proj, e, K4) states = _ex_states(t[f"k{K4}.{proj}.trellis"][row], K4) Mb, Nb = m // EX_TD, n // EX_TD unit = _lut(cb, K4)[states].reshape(Mb, Nb, EX_TD, EX_TD).transpose(0, 2, 1, 3).reshape(m, n) g = np.asarray(t[f"{proj}.wave_gamma"][e], np.float32)[wave_map(Mb, Nb)] unit = (unit.reshape(Mb, EX_TD, Nb, EX_TD) * g[:, None, :, None]).reshape(m, n) unit = unit * np.float32(t[f"{proj}.wscale"][e]) rows = hadamard(unit) * t[f"{proj}.SU"][e] cols = hadamard(np.ascontiguousarray(rows.T)) * t[f"{proj}.SV"][e] return np.ascontiguousarray(cols.T)
def load_expert_layer(packed_dir, layer): t, meta = _read(os.path.join(packed_dir, "experts", f"L{layer:02d}.safetensors")) assert meta.get("format") == FORMAT, f"L{layer}: not an {FORMAT} expert shard ({meta.get('format')})" cb = _read(os.path.join(packed_dir, "experts", "codebook.safetensors"))[0] return with_signs(t, layer), cb
def with_signs(t, layer): for p, (m, n) in EX_SHAPES.items(): if f"{p}.SU" not in t: t[f"{p}.SU"] = expert_signs([sign_seed(layer, e, p, "SU") for e in range(NEXP)], n) t[f"{p}.SV"] = expert_signs([sign_seed(layer, e, p, "SV") for e in range(NEXP)], m) return t
def decode_expert_layer(packed_dir, layer, experts=None): t, cb = load_expert_layer(packed_dir, layer) experts = list(range(NEXP)) if experts is None else list(experts) gu = np.empty((len(experts), 2 * INTER, HIDDEN), np.float32) dn = np.empty((len(experts), HIDDEN, INTER), np.float32) for i, e in enumerate(experts): gu[i, :INTER] = decode_expert(t, cb, "gate", e) gu[i, INTER:] = decode_expert(t, cb, "up", e) dn[i] = decode_expert(t, cb, "down", e) return {"gate_up_proj": gu, "down_proj": dn}
NE_K, NE_L, NE_V, NE_TLUT_BITS, NE_TD = 4, 16, 2, 9, 16_FULL_LUT = {}
def _ne_full_lut(tlut): key = np.asarray(tlut).tobytes() if key not in _FULL_LUT: small = np.asarray(tlut, np.float32) s = np.arange(1 << NE_L, dtype=np.int64) p = s * (s + 1) row = (p >> (16 - NE_TLUT_BITS - 1)) & ((1 << NE_TLUT_BITS) - 1) table = small[row].copy() table[:, 0] *= (1 - ((p >> 15) & 1) * 2).astype(np.float32) _FULL_LUT[key] = table return _FULL_LUT[key]
def _ne_states(words): words = np.asarray(words).view(np.uint16).astype(np.int64) rows, T = words.shape[0], NE_TD * NE_TD step, nstep = NE_K * NE_V, T // NE_V bits = ((words[:, :, None] >> np.arange(15, -1, -1)) & 1).reshape(rows, -1)[:, :T * NE_K] bits = np.concatenate([bits, bits[:, :NE_L - step]], axis=1) w = 1 << np.arange(NE_L - 1, -1, -1, dtype=np.int64) idx = np.arange(nstep)[:, None] * step + np.arange(NE_L)[None, :] return bits[:, idx] @ w
def decode_ne_tensor(t, name, m, n, tlut): states = _ne_states(t[f"{name}|trellis"]) vals = _ne_full_lut(tlut)[states] unit = np.ascontiguousarray(vals.reshape(m // NE_TD, n // NE_TD, NE_TD, NE_TD).transpose(0, 2, 1, 3)).reshape(m, n) unit = unit * np.float32(np.asarray(t[f"{name}|Wscale"]).reshape(-1)[0]) su, sv = np.asarray(t[f"{name}|SU"]), np.asarray(t[f"{name}|SV"]) rows = hadamard(unit, "spine") * np.sign(su).astype(np.float32) cols = hadamard(np.ascontiguousarray(rows.T), "spine") * np.sign(sv).astype(np.float32) w = np.ascontiguousarray(cols.T) mx = np.asarray(t[f"{name}|rc_max"], np.float32) r, c = rc_grid(mx[0], np.abs(sv.astype(np.int32))), rc_grid(mx[1], np.abs(su.astype(np.int32))) return (r[:, None] * bf16_round(w)) * c[None, :]
def rc_grid(mx, k): return (np.float32(mx) * k.astype(np.float32)).astype(np.float32) * np.float32(1.0 / 127.0)
def decode_ne_shard(packed_dir, layer): t, meta = _read(os.path.join(packed_dir, "ne", f"L{layer:02d}.safetensors")) tlut = _read(os.path.join(packed_dir, "ne", "tlut.safetensors"))[0]["tlut"] dims = json.loads(meta["dims"]) return {name: decode_ne_tensor(t, name, d[2], d[3], tlut)[:d[0], :d[1]] for name, d in dims.items()}
def unpack_int5(qp, n): m = qp.shape[0] by = np.asarray(qp).reshape(m, n // 8, 5) full = np.zeros((m, n // 8, 8), dtype=np.uint8) full[:, :, :5] = by word = full.reshape(m, n).view("<u8").reshape(m, n // 8) out = np.zeros((m, n // 8, 8), dtype=np.int8) for i in range(8): out[:, :, i] = ((word >> np.uint64(5 * i)) & np.uint64(31)).astype(np.int8) - 16 return out.reshape(m, n)
def decode_head(packed_dir): d = os.path.join(packed_dir, "head") parts = [] for f in sorted(x for x in os.listdir(d) if x.startswith("head_c") and x.endswith(".safetensors")): t, meta = _read(os.path.join(d, f)) parts += [(int(name.split(":")[1]), m0, n0, int(meta.get("group", 64)), t, name) for name, (m0, n0) in json.loads(meta["dims"]).items()] parts.sort(key=lambda x: x[0]) out = np.empty((sum(p[1] for p in parts), parts[0][2]), np.float32) for r0, m0, n0, g, t, name in parts: q = unpack_int5(t[f"{name}|qp"], n0).astype(np.float32) out[r0:r0 + m0] = q * np.repeat(np.asarray(t[f"{name}|gscale"], np.float32), g, axis=1)[:, :n0] return out
def decode_embed(packed_dir, bits=4, rows_per=16384): t, _ = _read(os.path.join(packed_dir, "ne", f"embed_int{bits}.safetensors")) rows, ng = t["mn"].shape hid = t["q_packed"].shape[1] * 8 // bits out = np.empty((rows, hid), np.float32) for r0 in range(0, rows, rows_per): sl = slice(r0, min(r0 + rows_per, rows)) b = np.unpackbits(t["q_packed"][sl], axis=1, count=hid * bits).reshape(-1, hid, bits) q = np.zeros(b.shape[:2], np.uint8) for j in range(bits): q = (q << 1) | b[..., j] mn = t["mn"][sl].astype(np.float32)[..., None] mx = t["mx"][sl].astype(np.float32)[..., None] step = np.maximum(mx - mn, np.float32(1e-8)) * np.float32(1.0 / (2 ** bits - 1)) out[sl] = (mn + q.reshape(-1, ng, hid // ng).astype(np.float32) * step).reshape(-1, hid) return out
def decode_int8_rows(packed_dir): from safetensors import safe_open out = {} with safe_open(os.path.join(packed_dir, "ne", "int8_rows.safetensors"), framework="pt") as fh: names = sorted({k.split("|")[0] for k in fh.keys()}) for name in names: q = fh.get_tensor(f"{name}|q").numpy().astype(np.float32) s = fh.get_tensor(f"{name}|scale").float().numpy() out[name] = q * s return out
def _bf16(a): import torch return torch.from_numpy(np.ascontiguousarray(a, np.float32)).to(torch.bfloat16)
def _expert_layer_job(args): packed_dir, out, L = args import torch from safetensors.torch import save_file t, cb = load_expert_layer(packed_dir, L) gu = torch.empty((NEXP, 2 * INTER, HIDDEN), dtype=torch.bfloat16) dn = torch.empty((NEXP, HIDDEN, INTER), dtype=torch.bfloat16) for e in range(NEXP): gu[e, :INTER] = _bf16(decode_expert(t, cb, "gate", e)) gu[e, INTER:] = _bf16(decode_expert(t, cb, "up", e)) dn[e] = _bf16(decode_expert(t, cb, "down", e)) p = f"model.language_model.layers.{L}.mlp.experts." fn = f"experts-L{L:02d}.safetensors" save_file({p + "gate_up_proj": gu, p + "down_proj": dn}, os.path.join(out, fn), metadata={"format": "pt"}) return {p + "gate_up_proj": fn, p + "down_proj": fn}
def _ne_layer_job(args): packed_dir, out, L = args from safetensors.torch import save_file dec = decode_ne_shard(packed_dir, L) fn = f"spine-L{L:02d}.safetensors" save_file({k: _bf16(v) for k, v in dec.items()}, os.path.join(out, fn), metadata={"format": "pt"}) return {k: fn for k in dec}
def materialize(packed_dir, out, workers=4, base=True): import shutil from concurrent.futures import ProcessPoolExecutor from safetensors import safe_open from safetensors.torch import save_file os.makedirs(out, exist_ok=True) root = os.path.dirname(os.path.abspath(packed_dir.rstrip("/"))) if os.path.basename(packed_dir.rstrip("/")) == "packed" \ else packed_dir pk = os.path.join(root, "packed") wm = {} with ProcessPoolExecutor(workers) as ex: for r in ex.map(_ne_layer_job, [(pk, out, L) for L in range(NLAYERS)]): wm.update(r) for r in ex.map(_expert_layer_job, [(pk, out, L) for L in range(NLAYERS)]): wm.update(r) save_file({"lm_head.weight": _bf16(decode_head(pk))}, os.path.join(out, "head.safetensors"), metadata={"format": "pt"}) wm["lm_head.weight"] = "head.safetensors" emb = "model.language_model.embed_tokens.weight" save_file({emb: _bf16(decode_embed(pk))}, os.path.join(out, "embed.safetensors"), metadata={"format": "pt"}) wm[emb] = "embed.safetensors" i8 = decode_int8_rows(pk) save_file({k: _bf16(v) for k, v in i8.items()}, os.path.join(out, "int8rows.safetensors"), metadata={"format": "pt"}) wm.update({k: "int8rows.safetensors" for k in i8}) for f in ["extras.safetensors"] + sorted(os.path.join("packed", "table", x) for x in os.listdir(os.path.join(pk, "table")) if x.endswith(".safetensors")): dst = os.path.basename(f) shutil.copyfile(os.path.join(root, f), os.path.join(out, dst)) with safe_open(os.path.join(out, dst), framework="pt") as fh: wm.update({k: dst for k in fh.keys()}) if base: from huggingface_hub import hf_hub_download idx = json.load(open(hf_hub_download(BASE_REPO, "model.safetensors.index.json", revision=BASE_REVISION)))["weight_map"] want = {k: f for k, f in idx.items() if k.startswith("mtp.") or k.startswith("model.visual.")} for f in sorted(set(want.values())): src = hf_hub_download(BASE_REPO, f, revision=BASE_REVISION) with safe_open(src, framework="pt") as fh: ks = [k for k in fh.keys() if k in want] save_file({k: fh.get_tensor(k) for k in ks}, os.path.join(out, f"base-{f}"), metadata={"format": "pt"}) wm.update({k: f"base-{f}" for k in ks}) for f in os.listdir(root): if f.endswith((".json", ".jinja", ".txt")) and f not in ("MANIFEST.json", "model.safetensors.index.json"): shutil.copyfile(os.path.join(root, f), os.path.join(out, f)) json.dump({"metadata": {}, "weight_map": dict(sorted(wm.items()))}, open(os.path.join(out, "model.safetensors.index.json"), "w"), indent=1) print(f"MATERIALIZED {len(wm)} tensors -> {out}", flush=True)
if __name__ == "__main__": ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) sub = ap.add_subparsers(dest="cmd", required=True) m = sub.add_parser("materialize") m.add_argument("--packed-dir", default=".") m.add_argument("--out", required=True) m.add_argument("--workers", type=int, default=4) m.add_argument("--no-base", action="store_true", help="text-only: skip MTP and vision weights") a = ap.parse_args() materialize(a.packed_dir, a.out, a.workers, not a.no_base)123version https://git-lfs.github.com/spec/v1oid sha256:c5d20938036e4e53e3de0ba8a805f9d544d5aabac6665e0a4dc5833418cff3besize 1512635845123version https://git-lfs.github.com/spec/v1oid sha256:fbbced7ad87bc663044eb8f35349e56bccf4d57f456b18600c3b36481f26152bsize 156822168123456789101112{ "bos_token_id": 248044, "do_sample": true, "eos_token_id": [ 248046, 248044 ], "pad_token_id": 248044, "temperature": 1.0, "top_k": 20, "top_p": 0.95}123version https://git-lfs.github.com/spec/v1oid sha256:e99dcc1d6ca7ed32d02f66d613143991385832e189e36237400b447cad1bdbbesize 533316488123version https://git-lfs.github.com/spec/v1oid sha256:cbb17185e876c23a58dedd6c75a1b769a8d8b9039a792860b9ea5e4ff9b54b87size 513502088123version https://git-lfs.github.com/spec/v1oid sha256:5fcab802a471051c975ee917a500c09be2da5dd398a3c49b2cdee3bc270eb6e5size 518110096123version https://git-lfs.github.com/spec/v1oid sha256:0f2d64d35b2db6863099c84187722a8d688fc8d979a0f0605ef253fcd25c7a41size 480170904123version https://git-lfs.github.com/spec/v1oid sha256:3c1f02b7c0b8f098b271d30f2c4151da4a68acb0e2e5456a49474461893a90d3size 493841296123version https://git-lfs.github.com/spec/v1oid sha256:d1a61848a549988b47032ba0520f256959b5b1a941de88ef8e26f7198171a89dsize 511198096123version https://git-lfs.github.com/spec/v1oid sha256:bdbb4b76fdac70682ff2dd476efc80377cf6a905cadb4177583ba1e896867114size 511812496123version https://git-lfs.github.com/spec/v1oid sha256:d0472e314cb41e7900697fdd82d02ed074b3ecd18cd3cdf8e8d7185abeaf3a81size 510276496123version https://git-lfs.github.com/spec/v1oid sha256:eab2698738aae45f74b19e68075f992f94937cf8452d49934f325c886fef6087size 498602896123version https://git-lfs.github.com/spec/v1oid sha256:c9c345470b1a58e5f49e9bf2844503d421c39e0c88be77324b612222f627028csize 495070096123version https://git-lfs.github.com/spec/v1oid sha256:b4667ea834cb3b694a5ef1995dee2ebe4da8033b1c2eb5f754d1fe7cd7ebbffbsize 510430096123version https://git-lfs.github.com/spec/v1oid sha256:9759b241a85f7b1b9487e532e3e014caa61de6e8eb8aab0ca7198c739b891aaasize 499831704123version https://git-lfs.github.com/spec/v1oid sha256:81a10406eebefed32a85b08f922da69c7b9d2794df3283ca2b3fb4fb5ca8f704size 508740496123version https://git-lfs.github.com/spec/v1oid sha256:089f9c0dbbccd9fe981efdf1d34bbac560e70484b34caaacbddc823da90934d0size 511966096123version https://git-lfs.github.com/spec/v1oid sha256:7186adb703c5d69a933f38e654cc0499a739fb2e99c2243c27b8acb0a381e323size 491537304123version https://git-lfs.github.com/spec/v1oid sha256:3660f1ba16085cbf18a8977d8d9098d86931a8f1cc3b6aa9e89e0c566af6712esize 467575704123version https://git-lfs.github.com/spec/v1oid sha256:15afe7a13d8e35937176aed12bcf15c93f0a81edd89e7e632deeccc7ef358ed5size 471569304123version https://git-lfs.github.com/spec/v1oid sha256:9902a7bd509c4e02f95caa388f79c4c6a1724b476e936494d7da4369cadd0710size 493534096123version https://git-lfs.github.com/spec/v1oid sha256:670662b2c7e660b82352bfaa7480facef8c26509a01bea13d7e9217137d14fbdsize 509201296123version https://git-lfs.github.com/spec/v1oid sha256:7c6f384536ecf77026fd0a3e4823055e2325e3e440c2960902cbebf4341197dasize 492151704123version https://git-lfs.github.com/spec/v1oid sha256:d190c34e37d3ae9202db3d58326b6048332911393ccb4b39713a31ea28af7c5asize 494916504123version https://git-lfs.github.com/spec/v1oid sha256:98bed192933800e2cfaf36052e6643f05fb2bbe7b63c7eb0103360e0097e4e16size 503210896123version https://git-lfs.github.com/spec/v1oid sha256:0e8d86faa4307e402c8a1dedf2df370d57fb4b9c602a1036871ae9f2debcdd51size 510583688123version https://git-lfs.github.com/spec/v1oid sha256:cda7c6e0fc373985df1c0b53e1fcb88245551c292f5ddb48e8e4848babdc3b19size 494455704123version https://git-lfs.github.com/spec/v1oid sha256:11b39f74aee653679c74ba6c824f9868c89b010dbc4b711a4785717c30f56e86size 497527704123version https://git-lfs.github.com/spec/v1oid sha256:2a5f2d25dcbc819bdfbf1db1fd15a2cb7f6058ce2702c66e072d22659769a3f9size 491690904123version https://git-lfs.github.com/spec/v1oid sha256:cc59344425975938112126db05d2572c3d5539c0f51c4c9eacd883f2d275c94asize 499985304123version https://git-lfs.github.com/spec/v1oid sha256:081423166140fc179c73a64445ad733c5a06c9e57a05eabb721c45b4c378f210size 492766104123version https://git-lfs.github.com/spec/v1oid sha256:adf9f23a5bbd60fef93d10875534ec638ab9ca8fb4d5e6b096765761264b2560size 504132496123version https://git-lfs.github.com/spec/v1oid sha256:039e92c2768c5a353341d2dd8ae13df19e94fc63cbd7750032017429a76d9d42size 503671696123version https://git-lfs.github.com/spec/v1oid sha256:8539bd2bf9682952b62a789710ec6296501c464aa7aeea0754a5e407b8ec41f9size 488004504123version https://git-lfs.github.com/spec/v1oid sha256:f0284540abfffba22d3a9d1e654434774dc59b27df1e3f11c333b5d9670f0387size 468804504123version https://git-lfs.github.com/spec/v1oid sha256:02a03fcafb1d91c3daa862e3c7e440d4b7b2c32be6da7d92cb7ee31cf9e243bfsize 475102104123version https://git-lfs.github.com/spec/v1oid sha256:90871dab9870681589fe197759eda5908164fd6cbe5fdcc1ec24b17a76ec9861size 496452496123version https://git-lfs.github.com/spec/v1oid sha256:18b960da6f0317caad88269c61e6888ddc88052c07ba1d446317f060c8a52abdsize 509815688123version https://git-lfs.github.com/spec/v1oid sha256:0e98d1433782fe23a466ada0dfb44a0005225250218cd71b1724c98734b685e0size 490922904123version https://git-lfs.github.com/spec/v1oid sha256:3f1239de13966f34ff41e8a2bccee59e4d368dfa655899396a43b39117bb323asize 479556512123version https://git-lfs.github.com/spec/v1oid sha256:cb43c4af85822c59ce1fce98db7622e06ae3a4d0958f793c98243822637c9cbasize 491076504.gitattributesAdded+37
LICENSEAdded+202
MANIFEST.jsonAdded+21
README.mdAdded+64
assets/size_vs_performance.pngAdded

Large File Pointer Details
- SHA256: 839b6cd6f069f0742411cad0ee42e5c32c4d961ec170c7f6791eee57729bbc4f
- Pointer size: 131 Bytes
- Size of remote file: 199 kB
chat_template.jinjaAdded+170
config.jsonAdded+154
decode.pyAdded+404
draft/mtp_q4g64.safetensorsAdded+3
extras.safetensorsAdded+3
generation_config.jsonAdded+12
merges.txtAdded
packed/experts/L00.safetensorsAdded+3
packed/experts/L01.safetensorsAdded+3
packed/experts/L02.safetensorsAdded+3
packed/experts/L03.safetensorsAdded+3
packed/experts/L04.safetensorsAdded+3
packed/experts/L05.safetensorsAdded+3
packed/experts/L06.safetensorsAdded+3
packed/experts/L07.safetensorsAdded+3
packed/experts/L08.safetensorsAdded+3
packed/experts/L09.safetensorsAdded+3
packed/experts/L10.safetensorsAdded+3
packed/experts/L11.safetensorsAdded+3
packed/experts/L12.safetensorsAdded+3
packed/experts/L13.safetensorsAdded+3
packed/experts/L14.safetensorsAdded+3
packed/experts/L15.safetensorsAdded+3
packed/experts/L16.safetensorsAdded+3
packed/experts/L17.safetensorsAdded+3
packed/experts/L18.safetensorsAdded+3
packed/experts/L19.safetensorsAdded+3
packed/experts/L20.safetensorsAdded+3
packed/experts/L21.safetensorsAdded+3
packed/experts/L22.safetensorsAdded+3
packed/experts/L23.safetensorsAdded+3
packed/experts/L24.safetensorsAdded+3
packed/experts/L25.safetensorsAdded+3
packed/experts/L26.safetensorsAdded+3
packed/experts/L27.safetensorsAdded+3
packed/experts/L28.safetensorsAdded+3
packed/experts/L29.safetensorsAdded+3
packed/experts/L30.safetensorsAdded+3
packed/experts/L31.safetensorsAdded+3
packed/experts/L32.safetensorsAdded+3
packed/experts/L33.safetensorsAdded+3
packed/experts/L34.safetensorsAdded+3
packed/experts/L35.safetensorsAdded+3
packed/experts/L36.safetensorsAdded+3
packed/experts/L37.safetensorsAdded+3