yujiepan commited on
Commit
d2d0bad
·
verified ·
1 Parent(s): b73cb0e

Upload folder using huggingface_hub

Browse files
Files changed (9) hide show
  1. .meta.json +12 -0
  2. LICENSE +210 -0
  3. README.md +438 -0
  4. chat_template.jinja +309 -0
  5. config.json +99 -0
  6. generation_config.json +10 -0
  7. model.safetensors +3 -0
  8. tokenizer.json +0 -0
  9. tokenizer_config.json +11 -0
.meta.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "torch": "2.14.1",
3
+ "transformers": "5.19.0",
4
+ "huggingface_hub": "1.33.0",
5
+ "safetensors": "0.8.0",
6
+ "accelerate": "1.15.0",
7
+ "sglang": "0.5.23.dev384+g9ab74b851",
8
+ "flashinfer-python": "0.7.2",
9
+ "kernels": "0.17.0",
10
+ "Python": "3.12.13",
11
+ "CUDA": "13.0"
12
+ }
LICENSE ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Tencent is pleased to support the open source community by making Tencent Hy4 preview available.
2
+
3
+ Copyright (C) 2026 Tencent. All rights reserved.
4
+
5
+ Tencent Hy4 preview is licensed under the Apache-2.0.
6
+
7
+
8
+ Terms of the Apache-2.0:
9
+ --------------------------------------------------------------------
10
+ Apache License
11
+ Version 2.0, January 2004
12
+ http://www.apache.org/licenses/
13
+
14
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
15
+
16
+ 1. Definitions.
17
+
18
+ "License" shall mean the terms and conditions for use, reproduction,
19
+ and distribution as defined by Sections 1 through 9 of this document.
20
+
21
+ "Licensor" shall mean the copyright owner or entity authorized by
22
+ the copyright owner that is granting the License.
23
+
24
+ "Legal Entity" shall mean the union of the acting entity and all
25
+ other entities that control, are controlled by, or are under common
26
+ control with that entity. For the purposes of this definition,
27
+ "control" means (i) the power, direct or indirect, to cause the
28
+ direction or management of such entity, whether by contract or
29
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
30
+ outstanding shares, or (iii) beneficial ownership of such entity.
31
+
32
+ "You" (or "Your") shall mean an individual or Legal Entity
33
+ exercising permissions granted by this License.
34
+
35
+ "Source" form shall mean the preferred form for making modifications,
36
+ including but not limited to software source code, documentation
37
+ source, and configuration files.
38
+
39
+ "Object" form shall mean any form resulting from mechanical
40
+ transformation or translation of a Source form, including but
41
+ not limited to compiled object code, generated documentation,
42
+ and conversions to other media types.
43
+
44
+ "Work" shall mean the work of authorship, whether in Source or
45
+ Object form, made available under the License, as indicated by a
46
+ copyright notice that is included in or attached to the work
47
+ (an example is provided in the Appendix below).
48
+
49
+ "Derivative Works" shall mean any work, whether in Source or Object
50
+ form, that is based on (or derived from) the Work and for which the
51
+ editorial revisions, annotations, elaborations, or other modifications
52
+ represent, as a whole, an original work of authorship. For the purposes
53
+ of this License, Derivative Works shall not include works that remain
54
+ separable from, or merely link (or bind by name) to the interfaces of,
55
+ the Work and Derivative Works thereof.
56
+
57
+ "Contribution" shall mean any work of authorship, including
58
+ the original version of the Work and any modifications or additions
59
+ to that Work or Derivative Works thereof, that is intentionally
60
+ submitted to Licensor for inclusion in the Work by the copyright owner
61
+ or by an individual or Legal Entity authorized to submit on behalf of
62
+ the copyright owner. For the purposes of this definition, "submitted"
63
+ means any form of electronic, verbal, or written communication sent
64
+ to the Licensor or its representatives, including but not limited to
65
+ communication on electronic mailing lists, source code control systems,
66
+ and issue tracking systems that are managed by, or on behalf of, the
67
+ Licensor for the purpose of discussing and improving the Work, but
68
+ excluding communication that is conspicuously marked or otherwise
69
+ designated in writing by the copyright owner as "Not a Contribution."
70
+
71
+ "Contributor" shall mean Licensor and any individual or Legal Entity
72
+ on behalf of whom a Contribution has been received by Licensor and
73
+ subsequently incorporated within the Work.
74
+
75
+ 2. Grant of Copyright License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ copyright license to reproduce, prepare Derivative Works of,
79
+ publicly display, publicly perform, sublicense, and distribute the
80
+ Work and such Derivative Works in Source or Object form.
81
+
82
+ 3. Grant of Patent License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ (except as stated in this section) patent license to make, have made,
86
+ use, offer to sell, sell, import, and otherwise transfer the Work,
87
+ where such license applies only to those patent claims licensable
88
+ by such Contributor that are necessarily infringed by their
89
+ Contribution(s) alone or by combination of their Contribution(s)
90
+ with the Work to which such Contribution(s) was submitted. If You
91
+ institute patent litigation against any entity (including a
92
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
93
+ or a Contribution incorporated within the Work constitutes direct
94
+ or contributory patent infringement, then any patent licenses
95
+ granted to You under this License for that Work shall terminate
96
+ as of the date such litigation is filed.
97
+
98
+ 4. Redistribution. You may reproduce and distribute copies of the
99
+ Work or Derivative Works thereof in any medium, with or without
100
+ modifications, and in Source or Object form, provided that You
101
+ meet the following conditions:
102
+
103
+ (a) You must give any other recipients of the Work or
104
+ Derivative Works a copy of this License; and
105
+
106
+ (b) You must cause any modified files to carry prominent notices
107
+ stating that You changed the files; and
108
+
109
+ (c) You must retain, in the Source form of any Derivative Works
110
+ that You distribute, all copyright, patent, trademark, and
111
+ attribution notices from the Source form of the Work,
112
+ excluding those notices that do not pertain to any part of
113
+ the Derivative Works; and
114
+
115
+ (d) If the Work includes a "NOTICE" text file as part of its
116
+ distribution, then any Derivative Works that You distribute must
117
+ include a readable copy of the attribution notices contained
118
+ within such NOTICE file, excluding those notices that do not
119
+ pertain to any part of the Derivative Works, in at least one
120
+ of the following places: within a NOTICE text file distributed
121
+ as part of the Derivative Works; within the Source form or
122
+ documentation, if provided along with the Derivative Works; or,
123
+ within a display generated by the Derivative Works, if and
124
+ wherever such third-party notices normally appear. The contents
125
+ of the NOTICE file are for informational purposes only and
126
+ do not modify the License. You may add Your own attribution
127
+ notices within Derivative Works that You distribute, alongside
128
+ or as an addendum to the NOTICE text from the Work, provided
129
+ that such additional attribution notices cannot be construed
130
+ as modifying the License.
131
+
132
+ You may add Your own copyright statement to Your modifications and
133
+ may provide additional or different license terms and conditions
134
+ for use, reproduction, or distribution of Your modifications, or
135
+ for any such Derivative Works as a whole, provided Your use,
136
+ reproduction, and distribution of the Work otherwise complies with
137
+ the conditions stated in this License.
138
+
139
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
140
+ any Contribution intentionally submitted for inclusion in the Work
141
+ by You to the Licensor shall be under the terms and conditions of
142
+ this License, without any additional terms or conditions.
143
+ Notwithstanding the above, nothing herein shall supersede or modify
144
+ the terms of any separate license agreement you may have executed
145
+ with Licensor regarding such Contributions.
146
+
147
+ 6. Trademarks. This License does not grant permission to use the trade
148
+ names, trademarks, service marks, or product names of the Licensor,
149
+ except as required for reasonable and customary use in describing the
150
+ origin of the Work and reproducing the content of the NOTICE file.
151
+
152
+ 7. Disclaimer of Warranty. Unless required by applicable law or
153
+ agreed to in writing, Licensor provides the Work (and each
154
+ Contributor provides its Contributions) on an "AS IS" BASIS,
155
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156
+ implied, including, without limitation, any warranties or conditions
157
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
158
+ PARTICULAR PURPOSE. You are solely responsible for determining the
159
+ appropriateness of using or redistributing the Work and assume any
160
+ risks associated with Your exercise of permissions under this License.
161
+
162
+ 8. Limitation of Liability. In no event and under no legal theory,
163
+ whether in tort (including negligence), contract, or otherwise,
164
+ unless required by applicable law (such as deliberate and grossly
165
+ negligent acts) or agreed to in writing, shall any Contributor be
166
+ liable to You for damages, including any direct, indirect, special,
167
+ incidental, or consequential damages of any character arising as a
168
+ result of this License or out of the use or inability to use the
169
+ Work (including but not limited to damages for loss of goodwill,
170
+ work stoppage, computer failure or malfunction, or any and all
171
+ other commercial damages or losses), even if such Contributor
172
+ has been advised of the possibility of such damages.
173
+
174
+ 9. Accepting Warranty or Additional Liability. While redistributing
175
+ the Work or Derivative Works thereof, You may choose to offer,
176
+ and charge a fee for, acceptance of support, warranty, indemnity,
177
+ or other liability obligations and/or rights consistent with this
178
+ License. However, in accepting such obligations, You may act only
179
+ on Your own behalf and on Your sole responsibility, not on behalf
180
+ of any other Contributor, and only if You agree to indemnify,
181
+ defend, and hold each Contributor harmless for any liability
182
+ incurred by, or claims asserted against, such Contributor by reason
183
+ of your accepting any such warranty or additional liability.
184
+
185
+ END OF TERMS AND CONDITIONS
186
+
187
+ APPENDIX: How to apply the Apache License to your work.
188
+
189
+ To apply the Apache License to your work, attach the following
190
+ boilerplate notice, with the fields enclosed by brackets "[]"
191
+ replaced with your own identifying information. (Don't include
192
+ the brackets!) The text should be enclosed in the appropriate
193
+ comment syntax for the file format. We also recommend that a
194
+ file or class name and description of purpose be included on the
195
+ same "printed page" as the copyright notice for easier
196
+ identification within third-party archives.
197
+
198
+ Copyright [yyyy] [name of copyright owner]
199
+
200
+ Licensed under the Apache License, Version 2.0 (the "License");
201
+ you may not use this file except in compliance with the License.
202
+ You may obtain a copy of the License at
203
+
204
+ http://www.apache.org/licenses/LICENSE-2.0
205
+
206
+ Unless required by applicable law or agreed to in writing, software
207
+ distributed under the License is distributed on an "AS IS" BASIS,
208
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209
+ See the License for the specific language governing permissions and
210
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,438 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - tencent/Hy4-preview
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [tencent/Hy4-preview](https://huggingface.co/tencent/Hy4-preview).
8
+
9
+ Structural comparison with `tencent/Hy4-preview`:
10
+
11
+ | Feature | Source | Tiny |
12
+ |---|---|---|
13
+ | Architecture / input | HYV4; text | Same |
14
+ | Vocabulary / tied embeddings | 120,832 / false | Same |
15
+ | Backbone layers / hidden size | 78 / 6,144 | 10 / 16 |
16
+ | MLP layout | 1 dense layer, then MoE | Same |
17
+ | Routed experts / top-k / shared experts | 256 / 8 / 1 | 32 / 8 / 1 |
18
+ | Dense / expert intermediate size | 18,432 / 2,048 | 128 / 128 |
19
+ | Attention Q heads; non-RoPE / RoPE / V dimensions | 64; 192 / 64 / 256 | 8; 32 / 64 / 32 |
20
+ | Q / KV LoRA rank | 2,048 / 512 | 64 / 512 |
21
+ | Indexer heads / dimension / selected tokens | 32 / 128 / 2,048 | Same |
22
+ | Full indexer layers | 0, 1, 5, 9, ... | 0, 1, 5, 9; remaining layers reuse the preceding indexer |
23
+ | Independent Hyper-Connections | 4 streams; gated pre/post branches | Same |
24
+ | MLA gating / learned attention sinks / SwiGLU clamp | Elementwise / enabled / 10 | Same |
25
+ | MTP | 1 plain DSA/MoE decoder; shared embedding/head | Same |
26
+ | Checkpoint precision | BF16; FP32 iHC/main attention sinks and router correction bias | Same |
27
+
28
+ Tokenizer, chat template and generation assets are copied unchanged from the pinned source.
29
+ The registered Transformers `indexed_attention` config tag represents the source DSA layers.
30
+
31
+ | File path | Size |
32
+ |------|------|
33
+ | model.safetensors | 21.8MB |
34
+
35
+
36
+ ### Example usage:
37
+
38
+ - SGLang (✅ verified)
39
+
40
+ - Run on four one-GPU nodes with NODE_RANK=0..3, the same DIST_INIT_ADDR and an available local NCCL_PORT. Enables TP=4, NEXTN/MTP and CUDA Graph.
41
+ - Verified on four NVIDIA H20 GPUs for English, Chinese and long DSA prompts; see Test environment for dependency versions.
42
+
43
+ ```bash
44
+ model_id=tiny-random/hy4-preview
45
+ node_rank=${NODE_RANK:-0}
46
+ dist_init_addr=${DIST_INIT_ADDR}
47
+ nccl_port=${NCCL_PORT}
48
+ export SGLANG_DG_CACHE_DIR=/tmp/hy4-deepgemm-$node_rank
49
+ sglang serve \
50
+ --model-path $model_id \
51
+ --tp-size 4 \
52
+ --nnodes 4 \
53
+ --node-rank $node_rank \
54
+ --dist-init-addr $dist_init_addr \
55
+ --nccl-port $nccl_port \
56
+ --fp8-gemm-backend triton \
57
+ --moe-runner-backend triton \
58
+ --speculative-algorithm NEXTN \
59
+ --speculative-num-steps 3 \
60
+ --speculative-eagle-topk 1 \
61
+ --speculative-num-draft-tokens 4 \
62
+ --context-length 4096 \
63
+ --max-total-tokens 4096 \
64
+ --chunked-prefill-size 512 \
65
+ --mem-fraction-static 0.3 \
66
+ --cuda-graph-config '{"decode": {"bs": [1, 2, 4]}}' \
67
+ --disable-custom-all-reduce
68
+ ```
69
+
70
+ - Transformers (✅ verified)
71
+
72
+ ```python
73
+ import torch
74
+ from transformers import AutoModelForCausalLM, AutoTokenizer
75
+
76
+ model_id = "tiny-random/hy4-preview"
77
+ # Transformers 5.19.0 implements Hy4's DSA and learned sinks only with eager attention.
78
+ model = AutoModelForCausalLM.from_pretrained(
79
+ model_id, dtype=torch.bfloat16, device_map="cuda", attn_implementation="eager",
80
+ )
81
+
82
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
83
+ inputs = tokenizer.apply_chat_template(
84
+ [{"role": "user", "content": "Hello"}], tokenize=True,
85
+ add_generation_prompt=True, return_dict=True, return_tensors="pt",
86
+ ).to(model.device)
87
+ output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
88
+ print(tokenizer.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
89
+ ```
90
+
91
+ ### Codes to create this repo (✅ verified):
92
+
93
+ <details><summary>Click to expand</summary>
94
+
95
+ ```python
96
+ import json
97
+ import re
98
+ from copy import deepcopy
99
+ from pathlib import Path
100
+ from shutil import copyfile
101
+
102
+ import torch
103
+ from huggingface_hub import hf_hub_download, list_repo_files
104
+ from safetensors.torch import save_file
105
+ from transformers import AutoConfig, AutoModelForCausalLM, set_seed
106
+
107
+ source_model_id = "tencent/Hy4-preview"
108
+ save_folder = "/tmp/tiny-random/hy4-preview"
109
+ source_revision = '705d81ee51566a186d645b74c974d642ef2828fe'
110
+ set_seed(42)
111
+ folder = Path(save_folder)
112
+ folder.mkdir(parents=True, exist_ok=True)
113
+ raw = json.loads(Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text())
114
+
115
+ raw.update(
116
+ hidden_size=16, num_hidden_layers=10, num_attention_heads=8,
117
+ intermediate_size=128, moe_intermediate_size=128, n_routed_experts=32,
118
+ q_lora_rank=64, qk_nope_head_dim=32, v_head_dim=32, qk_head_dim=96,
119
+ layer_types=["indexed_attention"] * 10,
120
+ )
121
+ raw["indexer_types"] = raw["indexer_types"][:10]
122
+ raw["mlp_layer_types"] = raw["mlp_layer_types"][:10]
123
+ (folder / "config.json").write_text(json.dumps(raw, indent=2))
124
+ config = AutoConfig.from_pretrained(folder)
125
+ # Transformers 5.19.0 implements Hy4's DSA and learned sinks only with eager attention.
126
+ model = AutoModelForCausalLM.from_config(config, dtype=torch.bfloat16, attn_implementation="eager")
127
+ backbone = model.model
128
+ last = backbone.layers[-1]
129
+ model.model.mtp_layers = torch.nn.ModuleList([torch.nn.ModuleDict({
130
+ "enorm": deepcopy(backbone.norm), "hnorm": deepcopy(backbone.norm),
131
+ "eh_proj": torch.nn.Linear(2 * config.hidden_size, config.hidden_size, bias=False, dtype=torch.bfloat16),
132
+ "input_layernorm": deepcopy(last.input_layernorm), "self_attn": deepcopy(last.self_attn),
133
+ "post_attention_layernorm": deepcopy(last.post_attention_layernorm), "mlp": deepcopy(last.mlp),
134
+ "final_layernorm": deepcopy(backbone.norm),
135
+ })])
136
+ model.model.mtp_layers.apply(model._init_weights)
137
+
138
+ def public_name(name):
139
+ for native, source in (("attn_hc", "hc_attn_layer"), ("ffn_hc", "hc_mlp_layer")):
140
+ name = re.sub(r"\." + native + r"\.(fn|base|scale)$", r"." + source + r".hc_pre.hc_\1", name)
141
+ name = name.replace(".self_attn.gate_proj", ".self_attn.linear_gate")
142
+ name = name.replace(".self_attn.sinks", ".self_attn.learnable_sink_param")
143
+ for suffix in ("fn", "base", "scale"):
144
+ name = name.replace(".hc_head.hc_" + suffix, ".hc_head.hc_head_" + suffix)
145
+ return name
146
+
147
+ state = {}
148
+ for name, value in model.state_dict().items():
149
+ name = public_name(name)
150
+ full_precision = name.endswith((".hc_fn", ".hc_base", ".hc_scale", ".hc_head_fn", ".hc_head_base", ".hc_head_scale"))
151
+ full_precision |= name.endswith((".learnable_sink_param", ".e_score_correction_bias")) and not name.startswith("model.mtp_layers.")
152
+ state[name] = value.detach().to(torch.float32 if full_precision else torch.bfloat16).cpu().contiguous()
153
+
154
+ save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
155
+
156
+ assets = {"tokenizer.json", "tokenizer_config.json", "chat_template.jinja", "generation_config.json", "LICENSE"}
157
+ for name in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
158
+ copyfile(hf_hub_download(source_model_id, name, revision=source_revision), folder / name)
159
+ ```
160
+
161
+ </details>
162
+
163
+ ### Printing the model:
164
+
165
+ <details><summary>Click to expand</summary>
166
+
167
+ ```text
168
+ HYV4ForCausalLM(
169
+ (model): HYV4Model(
170
+ (embed_tokens): Embedding(120832, 16, padding_idx=120002)
171
+ (layers): ModuleList(
172
+ (0): HYV4DecoderLayer(
173
+ (self_attn): HYV4Attention(
174
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
175
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
176
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
177
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
178
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
179
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
180
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
181
+ (indexer): HYV4Indexer(
182
+ (wq_b): Linear(in_features=64, out_features=4096, bias=False)
183
+ (wk): Linear(in_features=16, out_features=128, bias=False)
184
+ (k_norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True, bias=True)
185
+ (weights_proj): Linear(in_features=16, out_features=32, bias=False)
186
+ )
187
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
188
+ )
189
+ (mlp): HYV4MLP(
190
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
191
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
192
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
193
+ (act_fn): SiLUActivation()
194
+ )
195
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
196
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
197
+ (attn_hc): HYV4HyperConnection(
198
+ (input_norm): HYV4UnweightedRMSNorm()
199
+ )
200
+ (ffn_hc): HYV4HyperConnection(
201
+ (input_norm): HYV4UnweightedRMSNorm()
202
+ )
203
+ )
204
+ (1): HYV4DecoderLayer(
205
+ (self_attn): HYV4Attention(
206
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
207
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
208
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
209
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
210
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
211
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
212
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
213
+ (indexer): HYV4Indexer(
214
+ (wq_b): Linear(in_features=64, out_features=4096, bias=False)
215
+ (wk): Linear(in_features=16, out_features=128, bias=False)
216
+ (k_norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True, bias=True)
217
+ (weights_proj): Linear(in_features=16, out_features=32, bias=False)
218
+ )
219
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
220
+ )
221
+ (mlp): HYV4MoE(
222
+ (experts): HYV4Experts()
223
+ (gate): HYV4TopkRouter()
224
+ (shared_experts): HYV4MLP(
225
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
226
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
227
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
228
+ (act_fn): SiLUActivation()
229
+ )
230
+ )
231
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
232
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
233
+ (attn_hc): HYV4HyperConnection(
234
+ (input_norm): HYV4UnweightedRMSNorm()
235
+ )
236
+ (ffn_hc): HYV4HyperConnection(
237
+ (input_norm): HYV4UnweightedRMSNorm()
238
+ )
239
+ )
240
+ (2-4): 3 x HYV4DecoderLayer(
241
+ (self_attn): HYV4Attention(
242
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
243
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
244
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
245
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
246
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
247
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
248
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
249
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
250
+ )
251
+ (mlp): HYV4MoE(
252
+ (experts): HYV4Experts()
253
+ (gate): HYV4TopkRouter()
254
+ (shared_experts): HYV4MLP(
255
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
256
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
257
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
258
+ (act_fn): SiLUActivation()
259
+ )
260
+ )
261
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
262
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
263
+ (attn_hc): HYV4HyperConnection(
264
+ (input_norm): HYV4UnweightedRMSNorm()
265
+ )
266
+ (ffn_hc): HYV4HyperConnection(
267
+ (input_norm): HYV4UnweightedRMSNorm()
268
+ )
269
+ )
270
+ (5): HYV4DecoderLayer(
271
+ (self_attn): HYV4Attention(
272
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
273
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
274
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
275
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
276
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
277
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
278
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
279
+ (indexer): HYV4Indexer(
280
+ (wq_b): Linear(in_features=64, out_features=4096, bias=False)
281
+ (wk): Linear(in_features=16, out_features=128, bias=False)
282
+ (k_norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True, bias=True)
283
+ (weights_proj): Linear(in_features=16, out_features=32, bias=False)
284
+ )
285
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
286
+ )
287
+ (mlp): HYV4MoE(
288
+ (experts): HYV4Experts()
289
+ (gate): HYV4TopkRouter()
290
+ (shared_experts): HYV4MLP(
291
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
292
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
293
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
294
+ (act_fn): SiLUActivation()
295
+ )
296
+ )
297
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
298
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
299
+ (attn_hc): HYV4HyperConnection(
300
+ (input_norm): HYV4UnweightedRMSNorm()
301
+ )
302
+ (ffn_hc): HYV4HyperConnection(
303
+ (input_norm): HYV4UnweightedRMSNorm()
304
+ )
305
+ )
306
+ (6-8): 3 x HYV4DecoderLayer(
307
+ (self_attn): HYV4Attention(
308
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
309
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
310
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
311
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
312
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
313
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
314
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
315
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
316
+ )
317
+ (mlp): HYV4MoE(
318
+ (experts): HYV4Experts()
319
+ (gate): HYV4TopkRouter()
320
+ (shared_experts): HYV4MLP(
321
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
322
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
323
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
324
+ (act_fn): SiLUActivation()
325
+ )
326
+ )
327
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
328
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
329
+ (attn_hc): HYV4HyperConnection(
330
+ (input_norm): HYV4UnweightedRMSNorm()
331
+ )
332
+ (ffn_hc): HYV4HyperConnection(
333
+ (input_norm): HYV4UnweightedRMSNorm()
334
+ )
335
+ )
336
+ (9): HYV4DecoderLayer(
337
+ (self_attn): HYV4Attention(
338
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
339
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
340
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
341
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
342
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
343
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
344
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
345
+ (indexer): HYV4Indexer(
346
+ (wq_b): Linear(in_features=64, out_features=4096, bias=False)
347
+ (wk): Linear(in_features=16, out_features=128, bias=False)
348
+ (k_norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True, bias=True)
349
+ (weights_proj): Linear(in_features=16, out_features=32, bias=False)
350
+ )
351
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
352
+ )
353
+ (mlp): HYV4MoE(
354
+ (experts): HYV4Experts()
355
+ (gate): HYV4TopkRouter()
356
+ (shared_experts): HYV4MLP(
357
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
358
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
359
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
360
+ (act_fn): SiLUActivation()
361
+ )
362
+ )
363
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
364
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
365
+ (attn_hc): HYV4HyperConnection(
366
+ (input_norm): HYV4UnweightedRMSNorm()
367
+ )
368
+ (ffn_hc): HYV4HyperConnection(
369
+ (input_norm): HYV4UnweightedRMSNorm()
370
+ )
371
+ )
372
+ )
373
+ (norm): HYV4RMSNorm((16,), eps=1e-05)
374
+ (rotary_emb): HYV4RotaryEmbedding()
375
+ (hc_head): HYV4HyperHead(
376
+ (input_norm): HYV4UnweightedRMSNorm()
377
+ )
378
+ (mtp_layers): ModuleList(
379
+ (0): ModuleDict(
380
+ (enorm): HYV4RMSNorm((16,), eps=1e-05)
381
+ (hnorm): HYV4RMSNorm((16,), eps=1e-05)
382
+ (eh_proj): Linear(in_features=32, out_features=16, bias=False)
383
+ (input_layernorm): HYV4RMSNorm((16,), eps=1e-05)
384
+ (self_attn): HYV4Attention(
385
+ (q_a_proj): Linear(in_features=16, out_features=64, bias=False)
386
+ (q_a_layernorm): HYV4RMSNorm((64,), eps=1e-06)
387
+ (q_b_proj): Linear(in_features=64, out_features=768, bias=False)
388
+ (kv_a_proj_with_mqa): Linear(in_features=16, out_features=576, bias=False)
389
+ (kv_a_layernorm): HYV4RMSNorm((512,), eps=1e-06)
390
+ (kv_b_proj): Linear(in_features=512, out_features=512, bias=False)
391
+ (o_proj): Linear(in_features=256, out_features=16, bias=False)
392
+ (indexer): HYV4Indexer(
393
+ (wq_b): Linear(in_features=64, out_features=4096, bias=False)
394
+ (wk): Linear(in_features=16, out_features=128, bias=False)
395
+ (k_norm): LayerNorm((128,), eps=1e-05, elementwise_affine=True, bias=True)
396
+ (weights_proj): Linear(in_features=16, out_features=32, bias=False)
397
+ )
398
+ (gate_proj): Linear(in_features=16, out_features=256, bias=False)
399
+ )
400
+ (post_attention_layernorm): HYV4RMSNorm((16,), eps=1e-05)
401
+ (mlp): HYV4MoE(
402
+ (experts): HYV4Experts()
403
+ (gate): HYV4TopkRouter()
404
+ (shared_experts): HYV4MLP(
405
+ (gate_proj): Linear(in_features=16, out_features=128, bias=False)
406
+ (up_proj): Linear(in_features=16, out_features=128, bias=False)
407
+ (down_proj): Linear(in_features=128, out_features=16, bias=False)
408
+ (act_fn): SiLUActivation()
409
+ )
410
+ )
411
+ (final_layernorm): HYV4RMSNorm((16,), eps=1e-05)
412
+ )
413
+ )
414
+ )
415
+ (lm_head): Linear(in_features=16, out_features=120832, bias=False)
416
+ )
417
+ ```
418
+
419
+ </details>
420
+
421
+ ### Test environment:
422
+
423
+ - torch: 2.14.1
424
+ - transformers: 5.19.0
425
+ - huggingface_hub: 1.33.0
426
+ - safetensors: 0.8.0
427
+ - accelerate: 1.15.0
428
+ - sglang: 0.5.23.dev384+g9ab74b851
429
+ - flashinfer-python: 0.7.2
430
+ - kernels: 0.17.0
431
+ - Python: 3.12.13
432
+ - CUDA: 13.0
433
+
434
+ ### Change log:
435
+
436
+ - 2026-10-23: Initial version.
437
+
438
+ This repo is generated by GPT-6.1-Sol
chat_template.jinja ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- ----------‑‑‑ special token variables ‑‑‑---------- -#}
2
+ {%- set HYTK = ':opensource' %}
3
+ {%- set hy_start_token = '<|hy_start{}|>'.format(HYTK) %}
4
+ {%- set hy_middle_token = '<|hy_middle{}|>'.format(HYTK) %}
5
+ {%- set hy_end_token = '<|hy_end{}|>'.format(HYTK) %}
6
+ {%- set think_begin_token = '<think{}>'.format(HYTK) %}
7
+ {%- set think_end_token = '</think{}>'.format(HYTK) %}
8
+ {%- set toolcalls_begin_token = '<tool_calls{}>'.format(HYTK) %}
9
+ {%- set toolcalls_end_token = '</tool_calls{}>'.format(HYTK) %}
10
+ {%- set toolcall_begin_token = '<tool_call{}>'.format(HYTK) %}
11
+ {%- set toolcall_end_token = '</tool_call{}>'.format(HYTK) %}
12
+ {%- set argkey_begin_token = '<arg_key{}>'.format(HYTK) %}
13
+ {%- set argkey_end_token = '</arg_key{}>'.format(HYTK) %}
14
+ {%- set argvalue_begin_token = '<arg_value{}>'.format(HYTK) %}
15
+ {%- set argvalue_end_token = '</arg_value{}>'.format(HYTK) %}
16
+ {%- set toolresponse_begin_token = '<tool_response{}>'.format(HYTK) %}
17
+ {%- set toolresponse_end_token = '</tool_response{}>'.format(HYTK) %}
18
+ {%- set reasoning_mode_token = '<|reasoning_mode{}|>'.format(HYTK) %}
19
+
20
+ {#- ----------‑‑‑ hyperparameters variables ‑‑‑---------- -#}
21
+ {%- if not add_generation_prompt is defined %}
22
+ {%- set add_generation_prompt = false %}
23
+ {%- endif %}
24
+ {%- if not preserved_thinking is defined %}
25
+ {%- if not tools %}
26
+ {%- set preserved_thinking = false %}
27
+ {%- else %}
28
+ {%- set preserved_thinking = true %}
29
+ {%- endif %}
30
+ {%- endif %}
31
+
32
+ {%- if not reasoning_effort is defined %}
33
+ {%- set reasoning_effort = 'high' %}
34
+ {%- elif reasoning_effort not in ['high', 'no_think'] %}
35
+ {%- if reasoning_effort is none %}
36
+ {{- raise_exception('reasoning_effort error : None, should be no_think/high') }}
37
+ {%- else %}
38
+ {{- raise_exception('reasoning_effort error : ' + reasoning_effort + ', should be no_think/high') }}
39
+ {%- endif %}
40
+ {%- endif %}
41
+
42
+ {%- if fallback_strategy is defined and fallback_strategy == 'reasoning_toolcall_retry' %}
43
+ {%- set reasoning_effort = 'high' %}
44
+ {%- set add_generation_prompt = false %}
45
+ {%- endif %}
46
+ {%- if not raw_last_assistant is defined %}
47
+ {%- set raw_last_assistant = false %}
48
+ {%- endif %}
49
+
50
+ {%- macro tool_to_json(tool) -%}
51
+ {%- set ns_tool = namespace(first=true) -%}
52
+ {{- '{' -}}
53
+ {%- for k, v in tool.items() -%}
54
+ {%- if k != 'defer_loading' and k != 'strict' -%}
55
+ {%- if not ns_tool.first -%}{{- ', ' -}}{%- endif -%}
56
+ {%- set ns_tool.first = false -%}
57
+ {{- '"' ~ k ~ '": ' ~ (v | tojson(ensure_ascii=False)) -}}
58
+ {%- endif -%}
59
+ {%- endfor -%}
60
+ {{- '}' -}}
61
+ {%- endmacro -%}
62
+
63
+ {%- macro render_content(content) -%}
64
+ {%- if content is string -%}
65
+ {{- content -}}
66
+ {%- elif content is iterable and content is not mapping -%}
67
+ {%- for item in content -%}
68
+ {%- if item is mapping and item.type == 'text' -%}
69
+ {{- item.text -}}
70
+ {%- elif item is string -%}
71
+ {{- item -}}
72
+ {%- else -%}
73
+ {{- item | string -}}
74
+ {%- endif -%}
75
+ {%- endfor -%}
76
+ {%- elif content is none -%}
77
+ {{- '' -}}
78
+ {%- else -%}
79
+ {{- content | string -}}
80
+ {%- endif -%}
81
+ {%- endmacro -%}
82
+
83
+ {%- macro render_tools_prompt() -%}
84
+ {{- '# Tools\n\nYou may call one or more functions to assist with the user query.' -}}
85
+ {{- '\n\nYou are provided with function signatures within <tools></tools> XML tags:' -}}
86
+ {{- '\n<tools>\n' -}}
87
+ {%- set tool_ns = namespace(first=true) -%}
88
+ {%- for tool in tools -%}
89
+ {%- set t = tool['function'] if tool is mapping and 'function' in tool else tool -%}
90
+ {%- if t.defer_loading is not defined or not t.defer_loading -%}
91
+ {%- if not tool_ns.first -%}{{- '\n' -}}{%- endif -%}
92
+ {%- set tool_ns.first = false -%}
93
+ {{- tool_to_json(t) -}}
94
+ {%- endif -%}
95
+ {%- endfor -%}
96
+ {{- '\n</tools>\n\n' -}}
97
+ {{- 'For function call returns, you should first print ' ~ toolcalls_begin_token -}}
98
+ {{- '\nFor each function call, you should return object like:\n' -}}
99
+ {{- toolcall_begin_token ~ '{function-name}' -}}
100
+ {{- argkey_begin_token ~ '{arg-key-1}' ~ argkey_end_token -}}
101
+ {{- argvalue_begin_token ~ '{arg-value-1}' ~ argvalue_end_token -}}
102
+ {{- argkey_begin_token ~ '{arg-key-2}' ~ argkey_end_token -}}
103
+ {{- argvalue_begin_token ~ '{arg-value-2}' ~ argvalue_end_token -}}
104
+ {{- '...' -}}
105
+ {{- toolcall_end_token -}}
106
+ {{- '\nAt the end of function call returns, you should print ' ~ toolcalls_end_token -}}
107
+ {%- endmacro -%}
108
+
109
+ {%- macro render_tool_response(message) -%}
110
+ {%- set content = message['content'] -%}
111
+ {%- if content is string -%}
112
+ {{- toolresponse_begin_token ~ content ~ toolresponse_end_token -}}
113
+ {%- elif content is iterable and content is not mapping and content and content[0] is mapping and content[0].type == 'tool_reference' -%}
114
+ {{- toolresponse_begin_token -}}
115
+ {{- '<tools>\n' -}}
116
+ {%- for tr in content -%}
117
+ {%- for tool in tools -%}
118
+ {%- set t = tool['function'] if tool is mapping and 'function' in tool else tool -%}
119
+ {%- if t.name == tr.name -%}
120
+ {{- tool_to_json(t) ~ '\n' -}}
121
+ {%- endif -%}
122
+ {%- endfor -%}
123
+ {%- endfor -%}
124
+ {{- '</tools>' -}}
125
+ {{- toolresponse_end_token -}}
126
+ {%- elif content is iterable and content is not mapping and content and content[0] is mapping and content[0].output is defined -%}
127
+ {%- for tr in content -%}
128
+ {{- toolresponse_begin_token ~ tr.output ~ toolresponse_end_token -}}
129
+ {%- endfor -%}
130
+ {%- else -%}
131
+ {{- toolresponse_begin_token ~ render_content(content) ~ toolresponse_end_token -}}
132
+ {%- endif -%}
133
+ {%- endmacro -%}
134
+
135
+ {#- consecutive tool messages are clustered into a single tool message whose content is the list of the original tool messages; the result is written to merged_ns.messages (a macro cannot return a list) -#}
136
+ {%- set merged_ns = namespace(messages=[]) %}
137
+ {%- macro merge_tool_responses(messages) -%}
138
+ {%- set merge_ns = namespace(result=[], cluster=[]) -%}
139
+ {%- for message in messages -%}
140
+ {%- if message['role'] == 'tool' -%}
141
+ {%- set merge_ns.cluster = merge_ns.cluster + [message] -%}
142
+ {%- else -%}
143
+ {%- if merge_ns.cluster -%}
144
+ {%- set merge_ns.result = merge_ns.result + [{'role': 'tool', 'content': merge_ns.cluster}] -%}
145
+ {%- set merge_ns.cluster = [] -%}
146
+ {%- endif -%}
147
+ {%- set merge_ns.result = merge_ns.result + [message] -%}
148
+ {%- endif -%}
149
+ {%- endfor -%}
150
+ {%- if merge_ns.cluster -%}
151
+ {%- set merge_ns.result = merge_ns.result + [{'role': 'tool', 'content': merge_ns.cluster}] -%}
152
+ {%- endif -%}
153
+ {%- set merged_ns.messages = merge_ns.result -%}
154
+ {%- endmacro -%}
155
+
156
+ {#- render one tool cluster, reordered to follow the tool_call order of the preceding assistant turn; any missing / ambiguous id falls back to the original tool message order for the whole cluster -#}
157
+ {%- macro render_tool_responses(tool_messages, tool_call_ids) -%}
158
+ {%- set order_ns = namespace(ordered=[], matched=true) -%}
159
+ {%- if tool_call_ids and tool_call_ids | length == tool_messages | length -%}
160
+ {%- for tool_call_id in tool_call_ids -%}
161
+ {%- set hit_ns = namespace(count=0, message=none) -%}
162
+ {%- for tool_message in tool_messages -%}
163
+ {%- set message_id = tool_message['tool_call_id'] if tool_message['tool_call_id'] is defined else tool_message['id'] -%}
164
+ {%- if message_id is defined and message_id == tool_call_id -%}
165
+ {%- set hit_ns.count = hit_ns.count + 1 -%}
166
+ {%- set hit_ns.message = tool_message -%}
167
+ {%- endif -%}
168
+ {%- endfor -%}
169
+ {%- if hit_ns.count == 1 -%}
170
+ {%- set order_ns.ordered = order_ns.ordered + [hit_ns.message] -%}
171
+ {%- else -%}
172
+ {%- set order_ns.matched = false -%}
173
+ {%- endif -%}
174
+ {%- endfor -%}
175
+ {%- else -%}
176
+ {%- set order_ns.matched = false -%}
177
+ {%- endif -%}
178
+ {%- for tool_message in (order_ns.ordered if order_ns.matched else tool_messages) -%}
179
+ {{- render_tool_response(tool_message) -}}
180
+ {%- endfor -%}
181
+ {%- endmacro -%}
182
+
183
+ {%- set _ = merge_tool_responses(messages) %}
184
+ {%- set normed_messages = merged_ns.messages %}
185
+
186
+ {%- set ns = namespace(last_user_index=-1, has_leading_system=false) %}
187
+ {%- if normed_messages and normed_messages[0].role == 'system' %}
188
+ {%- set ns.has_leading_system = true %}
189
+ {%- endif %}
190
+ {%- for message in normed_messages %}
191
+ {%- if message['role'] == 'user' %}
192
+ {%- set ns.last_user_index = loop.index0 %}
193
+ {%- endif %}
194
+ {%- endfor %}
195
+
196
+ {#- no leading system: synthesize one for tools and/or reasoning_mode -#}
197
+ {%- if not ns.has_leading_system %}
198
+ {{- hy_start_token ~ 'system' ~ hy_middle_token -}}
199
+ {%- if tools %}
200
+ {{- render_tools_prompt() -}}
201
+ {%- endif %}
202
+ {{- reasoning_mode_token ~ 'reasoning_effort:' ~ reasoning_effort -}}
203
+ {{- hy_end_token -}}
204
+ {%- endif %}
205
+
206
+ {%- set last_ns = namespace(last_is_assistant=false) %}
207
+ {%- set prev_ns = namespace(tool_call_ids=[]) %}
208
+ {%- for message in normed_messages %}
209
+ {%- if message['role'] == 'system' %}
210
+ {{- hy_start_token ~ 'system' ~ hy_middle_token -}}
211
+ {#- tools / reasoning_mode only attach to the leading system (messages[0]) -#}
212
+ {%- if loop.first %}
213
+ {%- if tools %}
214
+ {{- render_tools_prompt() -}}
215
+ {%- endif %}
216
+ {%- set content = render_content(message['content']) -%}
217
+ {%- if tools and content -%}
218
+ {{- '\n\n' -}}
219
+ {%- endif -%}
220
+ {{- content -}}
221
+ {{- reasoning_mode_token ~ 'reasoning_effort:' ~ reasoning_effort -}}
222
+ {%- else %}
223
+ {{- render_content(message['content']) -}}
224
+ {%- endif %}
225
+ {{- hy_end_token -}}
226
+ {%- elif message['role'] == 'user' %}
227
+ {{- hy_start_token ~ 'user' ~ hy_middle_token -}}
228
+ {{- render_content(message['content']) -}}
229
+ {{- hy_end_token -}}
230
+ {%- elif message['role'] == 'assistant' %}
231
+ {%- set content_body = render_content(message['content']) -%}
232
+ {#- 'reasoning' takes precedence, fall back to 'reasoning_content' when it is empty -#}
233
+ {%- set reasoning_text = '' %}
234
+ {%- if message['reasoning'] is defined and message['reasoning'] is string and message['reasoning'] %}
235
+ {%- set reasoning_text = message['reasoning'] %}
236
+ {%- elif message['reasoning_content'] is defined and message['reasoning_content'] is string and message['reasoning_content'] %}
237
+ {%- set reasoning_text = message['reasoning_content'] %}
238
+ {%- endif %}
239
+ {#- no_think overrides preserved_thinking: history is always emitted with empty think tags -#}
240
+ {%- if reasoning_effort != 'no_think' and (preserved_thinking or loop.index0 > ns.last_user_index) and reasoning_text %}
241
+ {%- set content = think_begin_token ~ reasoning_text ~ think_end_token ~ content_body %}
242
+ {%- else %}
243
+ {%- set content = think_begin_token ~ think_end_token ~ content_body %}
244
+ {%- endif %}
245
+ {{- hy_start_token ~ 'assistant' ~ hy_middle_token -}}
246
+ {%- if message['tool_calls'] is defined and message['tool_calls'] %}
247
+ {#- remember the tool_call ids of this turn to order the following tool responses; an incomplete id set means "do not reorder" -#}
248
+ {%- set ids_ns = namespace(ids=[], complete=true) %}
249
+ {%- for tool in message['tool_calls'] %}
250
+ {%- set tool_call_id = tool['id'] if tool['id'] is defined and tool['id'] else tool['tool_call_id'] %}
251
+ {%- if tool_call_id is defined and tool_call_id %}
252
+ {%- set ids_ns.ids = ids_ns.ids + [tool_call_id] %}
253
+ {%- else %}
254
+ {%- set ids_ns.complete = false %}
255
+ {%- endif %}
256
+ {%- endfor %}
257
+ {%- set prev_ns.tool_call_ids = ids_ns.ids if ids_ns.complete else [] %}
258
+ {{- content -}}
259
+ {{- toolcalls_begin_token -}}
260
+ {%- for tool in message['tool_calls'] -%}
261
+ {%- set func = tool['function'] if tool is mapping and 'function' in tool else tool -%}
262
+ {%- set arguments = func['arguments'] -%}
263
+ {{- toolcall_begin_token ~ func['name'] -}}
264
+ {%- for key, value in arguments.items() -%}
265
+ {{- argkey_begin_token ~ key ~ argkey_end_token -}}
266
+ {%- if value is not string -%}
267
+ {%- set value = value | tojson(ensure_ascii=False) -%}
268
+ {%- endif -%}
269
+ {{- argvalue_begin_token ~ value ~ argvalue_end_token -}}
270
+ {%- endfor -%}
271
+ {{- toolcall_end_token -}}
272
+ {%- endfor -%}
273
+ {{- toolcalls_end_token -}}
274
+ {%- else %}
275
+ {%- if loop.last and raw_last_assistant %}
276
+ {{- content_body -}}
277
+ {%- else %}
278
+ {{- content -}}
279
+ {%- endif %}
280
+ {%- endif %}
281
+ {#- continuation / prefill: last assistant is still open, do not close with hy_end -#}
282
+ {%- if not (loop.last and raw_last_assistant) %}
283
+ {{- hy_end_token -}}
284
+ {%- endif %}
285
+ {%- elif message['role'] == 'tool' %}
286
+ {{- hy_start_token ~ 'tool' ~ hy_middle_token -}}
287
+ {{- render_tool_responses(message['content'], prev_ns.tool_call_ids) -}}
288
+ {{- hy_end_token -}}
289
+ {%- else %}
290
+ {{- hy_start_token ~ message['role'] ~ hy_middle_token -}}
291
+ {{- render_content(message['content']) -}}
292
+ {{- hy_end_token -}}
293
+ {%- endif %}
294
+ {%- if message['role'] != 'assistant' or not (message['tool_calls'] is defined and message['tool_calls']) %}
295
+ {%- set prev_ns.tool_call_ids = [] %}
296
+ {%- endif %}
297
+ {%- if loop.last and message['role'] == 'assistant' %}
298
+ {%- set last_ns.last_is_assistant = true %}
299
+ {%- endif %}
300
+ {%- endfor %}
301
+ {%- if add_generation_prompt %}
302
+ {%- if not last_ns.last_is_assistant %}
303
+ {%- if reasoning_effort == 'no_think' %}
304
+ {{- hy_start_token ~ 'assistant' ~ hy_middle_token ~ think_begin_token ~ think_end_token -}}
305
+ {%- else %}
306
+ {{- hy_start_token ~ 'assistant' ~ hy_middle_token ~ think_begin_token -}}
307
+ {%- endif %}
308
+ {%- endif %}
309
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "HYV4ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bitwise_backward_align": false,
8
+ "bos_token_id": 120000,
9
+ "dtype": "bfloat16",
10
+ "enable_ihc": true,
11
+ "enable_lm_head_fp32": true,
12
+ "eos_token_id": 120025,
13
+ "gated_mla": true,
14
+ "gating_type": "elementwise",
15
+ "hc_eps": 1e-06,
16
+ "hc_magnitude": 2.0,
17
+ "hc_mult": 4,
18
+ "head_dim": 64,
19
+ "hidden_act": "silu",
20
+ "hidden_size": 16,
21
+ "index_head_dim": 128,
22
+ "index_n_heads": 32,
23
+ "index_topk": 2048,
24
+ "indexer_types": [
25
+ "full",
26
+ "full",
27
+ "shared",
28
+ "shared",
29
+ "shared",
30
+ "full",
31
+ "shared",
32
+ "shared",
33
+ "shared",
34
+ "full"
35
+ ],
36
+ "initializer_range": 0.006,
37
+ "intermediate_size": 128,
38
+ "kv_lora_rank": 512,
39
+ "layer_types": [
40
+ "indexed_attention",
41
+ "indexed_attention",
42
+ "indexed_attention",
43
+ "indexed_attention",
44
+ "indexed_attention",
45
+ "indexed_attention",
46
+ "indexed_attention",
47
+ "indexed_attention",
48
+ "indexed_attention",
49
+ "indexed_attention"
50
+ ],
51
+ "learnable_sink": true,
52
+ "learnable_sink_init": 0.0,
53
+ "max_position_embeddings": 1048576,
54
+ "mlp_layer_types": [
55
+ "dense",
56
+ "sparse",
57
+ "sparse",
58
+ "sparse",
59
+ "sparse",
60
+ "sparse",
61
+ "sparse",
62
+ "sparse",
63
+ "sparse",
64
+ "sparse"
65
+ ],
66
+ "model_type": "hy_v4",
67
+ "moe_intermediate_size": 128,
68
+ "mtp_loss_factor": 0.1,
69
+ "n_group": 1,
70
+ "n_routed_experts": 32,
71
+ "n_shared_experts": 1,
72
+ "norm_topk_prob": true,
73
+ "num_attention_heads": 8,
74
+ "num_experts_per_tok": 8,
75
+ "num_hidden_layers": 10,
76
+ "num_key_value_heads": 8,
77
+ "num_nextn_predict_layers": 1,
78
+ "pad_token_id": 120002,
79
+ "q_lora_rank": 64,
80
+ "qk_head_dim": 96,
81
+ "qk_nope_head_dim": 32,
82
+ "qk_rope_head_dim": 64,
83
+ "rms_norm_eps": 1e-05,
84
+ "rope_parameters": {
85
+ "rope_theta": 10000000,
86
+ "rope_type": "default"
87
+ },
88
+ "routed_scaling_factor": 2.827,
89
+ "swiglu_limit": 10.0,
90
+ "tie_word_embeddings": false,
91
+ "topk_group": 1,
92
+ "transformers_version": "5.16.2",
93
+ "use_cache": true,
94
+ "use_dsa": true,
95
+ "use_mla": true,
96
+ "v_head_dim": 32,
97
+ "vocab_size": 120832,
98
+ "torch_dtype": "bfloat16"
99
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 120000,
3
+ "do_sample": true,
4
+ "eos_token_id": 120025,
5
+ "pad_token_id": 120002,
6
+ "temperature": 0.9,
7
+ "top_k": -1,
8
+ "top_p": 1,
9
+ "transformers_version": "5.16.2"
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c7aac62bf1cd6f5e94986aba60b7591adefb76437fe3d65b7fd9ee4e8d7245e7
3
+ size 21805284
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|hy_start:opensource|>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "eos_token": "<|hy_end:opensource|>",
6
+ "is_local": true,
7
+ "local_files_only": false,
8
+ "model_max_length": 1000000000000000019884624838656,
9
+ "pad_token": "<|hy_pad:opensource|>",
10
+ "tokenizer_class": "TokenizersBackend"
11
+ }