infosave commited on
Commit
3bd12dd
·
verified ·
1 Parent(s): 9307826

Card (EN/RU/ZH), figures, license, sha256

Browse files
.gitattributes CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  hy4-flash-fast-code.cmf filter=lfs diff=lfs merge=lfs -text
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  hy4-flash-fast-code.cmf filter=lfs diff=lfs merge=lfs -text
37
+ assets/aquarium_fast_code.png filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Tencent Hy License, Version 1.0
2
+
3
+ This License is derived from the Apache License, Version 2.0
4
+ (http://www.apache.org/licenses/LICENSE-2.0), with modifications, mainly
5
+ the additional commercial terms for large Model-as-a-Service ("MaaS")
6
+ businesses in Section 10. This License is not the Apache License,
7
+ Version 2.0, and is not endorsed by or affiliated with the Apache
8
+ Software Foundation.
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 10 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship, whether in Source or
41
+ Object form, made available under the License, as indicated by a
42
+ copyright notice that is included in or attached to the work
43
+ (an example is provided in the Appendix below). For the avoidance
44
+ of doubt, the Work includes the model weights, parameters,
45
+ configuration files, inference and training code, and documentation
46
+ made available by Licensor under this License.
47
+
48
+ "Derivative Works" shall mean any work, whether in Source or Object
49
+ form, that is based on (or derived from) the Work and for which the
50
+ editorial revisions, annotations, elaborations, or other modifications
51
+ represent, as a whole, an original work of authorship. For the purposes
52
+ of this License, Derivative Works shall not include works that remain
53
+ separable from, or merely link (or bind by name) to the interfaces of,
54
+ the Work and Derivative Works thereof. For the avoidance of doubt,
55
+ Derivative Works include any fine-tuned, quantized, distilled, merged,
56
+ pruned, or otherwise modified versions of the model weights.
57
+
58
+ "Contribution" shall mean any work of authorship, including
59
+ the original version of the Work and any modifications or additions
60
+ to that Work or Derivative Works thereof, that is intentionally
61
+ submitted to Licensor for inclusion in the Work by the copyright owner
62
+ or by an individual or Legal Entity authorized to submit on behalf of
63
+ the copyright owner. For the purposes of this definition, "submitted"
64
+ means any form of electronic, verbal, or written communication sent
65
+ to the Licensor or its representatives, including but not limited to
66
+ communication on electronic mailing lists, source code control systems,
67
+ and issue tracking systems that are managed by, or on behalf of, the
68
+ Licensor for the purpose of discussing and improving the Work, but
69
+ excluding communication that is conspicuously marked or otherwise
70
+ designated in writing by the copyright owner as "Not a Contribution."
71
+
72
+ "Contributor" shall mean Licensor and any individual or Legal Entity
73
+ on behalf of whom a Contribution has been received by Licensor and
74
+ subsequently incorporated within the Work.
75
+
76
+ 2. Grant of Copyright License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ copyright license to reproduce, prepare Derivative Works of,
80
+ publicly display, publicly perform, sublicense, and distribute the
81
+ Work and such Derivative Works in Source or Object form.
82
+
83
+ 3. Grant of Patent License. Subject to the terms and conditions of
84
+ this License, each Contributor hereby grants to You a perpetual,
85
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
86
+ (except as stated in this section) patent license to make, have made,
87
+ use, offer to sell, sell, import, and otherwise transfer the Work,
88
+ where such license applies only to those patent claims licensable
89
+ by such Contributor that are necessarily infringed by their
90
+ Contribution(s) alone or by combination of their Contribution(s)
91
+ with the Work to which such Contribution(s) was submitted. If You
92
+ institute patent litigation against any entity (including a
93
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
94
+ or a Contribution incorporated within the Work constitutes direct
95
+ or contributory patent infringement, then any patent licenses
96
+ granted to You under this License for that Work shall terminate
97
+ as of the date such litigation is filed.
98
+
99
+ 4. Redistribution. You may reproduce and distribute copies of the
100
+ Work or Derivative Works thereof in any medium, with or without
101
+ modifications, and in Source or Object form, provided that You
102
+ meet the following conditions:
103
+
104
+ (a) You must give any other recipients of the Work or
105
+ Derivative Works a copy of this License; and
106
+
107
+ (b) You must cause any modified files to carry prominent notices
108
+ stating that You changed the files; and
109
+
110
+ (c) You must retain, in the Source form of any Derivative Works
111
+ that You distribute, all copyright, patent, trademark, and
112
+ attribution notices from the Source form of the Work,
113
+ excluding those notices that do not pertain to any part of
114
+ the Derivative Works; and
115
+
116
+ (d) If the Work includes a "NOTICE" text file as part of its
117
+ distribution, then any Derivative Works that You distribute must
118
+ include a readable copy of the attribution notices contained
119
+ within such NOTICE file, excluding those notices that do not
120
+ pertain to any part of the Derivative Works, in at least one
121
+ of the following places: within a NOTICE text file distributed
122
+ as part of the Derivative Works; within the Source form or
123
+ documentation, if provided along with the Derivative Works; or,
124
+ within a display generated by the Derivative Works, if and
125
+ wherever such third-party notices normally appear. The contents
126
+ of the NOTICE file are for informational purposes only and
127
+ do not modify the License. You may add Your own attribution
128
+ notices within Derivative Works that You distribute, alongside
129
+ or as an addendum to the NOTICE text from the Work, provided
130
+ that such additional attribution notices cannot be construed
131
+ as modifying the License.
132
+
133
+ You may add Your own copyright statement to Your modifications and
134
+ may provide additional or different license terms and conditions
135
+ for use, reproduction, or distribution of Your modifications, or
136
+ for any such Derivative Works as a whole, provided Your use,
137
+ reproduction, and distribution of the Work otherwise complies with
138
+ the conditions stated in this License. Notwithstanding the
139
+ foregoing, any license terms You provide for the Work or any
140
+ Derivative Works must not remove, limit, or conflict with Section 10,
141
+ and Section 10 shall continue to apply to every recipient of the
142
+ Work or any Derivative Works.
143
+
144
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
145
+ any Contribution intentionally submitted for inclusion in the Work
146
+ by You to the Licensor shall be under the terms and conditions of
147
+ this License, without any additional terms or conditions.
148
+ Notwithstanding the above, nothing herein shall supersede or modify
149
+ the terms of any separate license agreement you may have executed
150
+ with Licensor regarding such Contributions.
151
+
152
+ 6. Trademarks. This License does not grant permission to use the trade
153
+ names, trademarks, service marks, or product names of the Licensor,
154
+ except as required for reasonable and customary use in describing the
155
+ origin of the Work and reproducing the content of the NOTICE file.
156
+
157
+ 7. Disclaimer of Warranty. Unless required by applicable law or
158
+ agreed to in writing, Licensor provides the Work (and each
159
+ Contributor provides its Contributions) on an "AS IS" BASIS,
160
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
161
+ implied, including, without limitation, any warranties or conditions
162
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
163
+ PARTICULAR PURPOSE. You are solely responsible for determining the
164
+ appropriateness of using or redistributing the Work and assume any
165
+ risks associated with Your exercise of permissions under this License.
166
+
167
+ 8. Limitation of Liability. In no event and under no legal theory,
168
+ whether in tort (including negligence), contract, or otherwise,
169
+ unless required by applicable law (such as deliberate and grossly
170
+ negligent acts) or agreed to in writing, shall any Contributor be
171
+ liable to You for damages, including any direct, indirect, special,
172
+ incidental, or consequential damages of any character arising as a
173
+ result of this License or out of the use or inability to use the
174
+ Work (including but not limited to damages for loss of goodwill,
175
+ work stoppage, computer failure or malfunction, or any and all
176
+ other commercial damages or losses), even if such Contributor
177
+ has been advised of the possibility of such damages.
178
+
179
+ 9. Accepting Warranty or Additional Liability. While redistributing
180
+ the Work or Derivative Works thereof, You may choose to offer,
181
+ and charge a fee for, acceptance of support, warranty, indemnity,
182
+ or other liability obligations and/or rights consistent with this
183
+ License. However, in accepting such obligations, You may act only
184
+ on Your own behalf and on Your sole responsibility, not on behalf
185
+ of any other Contributor, and only if You agree to indemnify,
186
+ defend, and hold each Contributor harmless for any liability
187
+ incurred by, or claims asserted against, such Contributor by reason
188
+ of your accepting any such warranty or additional liability.
189
+
190
+ 10. Additional Commercial Terms.
191
+
192
+ 10.1 MaaS. "MaaS" means giving third parties remote access to model
193
+ inference or fine-tuning (e.g., via API), allowing them to
194
+ submit inputs or specify parameters or training data. This
195
+ excludes (i) end-user products with model capabilities confined
196
+ to specific features or workflows, without general-purpose
197
+ model access, or (ii) merely relaying requests to an
198
+ independently operated third-party model service.
199
+
200
+ 10.2 Separate License Required. Notwithstanding Sections 2 and 3,
201
+ and except as provided in Section 10.3, if You operate a MaaS
202
+ business, You must obtain a separate written license to use the
203
+ Work or any Derivative Works from Licensor (including by email),
204
+ in either of the following cases:
205
+
206
+ (a) if Your aggregate worldwide gross revenue exceeds
207
+ US$50 million (or the equivalent in other currencies) in
208
+ any consecutive 12-month period, whether or not such
209
+ revenue is derived from the Work or any Derivative Works,
210
+ before using (or continuing to use) the Work or any
211
+ Derivative Works; or
212
+
213
+ (b) before using the Work or any Derivative Works in or for any
214
+ product or service provided by You that has more than
215
+ 100 million monthly active users in any calendar month.
216
+
217
+ 10.3 Internal Use. Section 10.2 does not apply to Your use of the
218
+ Work or any Derivative Works solely for internal purposes,
219
+ provided that neither the Work, any Derivative Works, nor their
220
+ outputs are made available to third parties.
221
+
222
+ 10.4 Contact. For licensing requests or questions, please contact
223
+ hy_partners@tencent.com.
224
+
225
+ END OF TERMS AND CONDITIONS
226
+
227
+ APPENDIX: How to apply the Tencent Hy License to your work.
228
+
229
+ To apply this License to a Derivative Work, attach the following
230
+ notice, with the fields enclosed by brackets "[]" replaced with your
231
+ own identifying information. (Don't include the brackets!)
232
+
233
+ Copyright [yyyy] [name of copyright owner]
234
+
235
+ Licensed under the Tencent Hy License, Version 1.0 (the "License"),
236
+ which is based on the Apache License, Version 2.0, with additional
237
+ commercial terms. You may not use this file except in compliance
238
+ with the License. You may obtain a copy of the License in the
239
+ LICENSE file distributed with this work.
240
+
241
+ Unless required by applicable law or agreed to in writing, software
242
+ distributed under the License is distributed on an "AS IS" BASIS,
243
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
244
+ implied. See the License for the specific language governing
245
+ permissions and limitations under the License.
README.md ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: tencent-hy-license
4
+ license_link: LICENSE
5
+ library_name: cortiq
6
+ base_model: tencent/Hy4-flash
7
+ base_model_relation: quantized
8
+ pipeline_tag: text-generation
9
+ tags:
10
+ - cmf
11
+ - cortiq
12
+ - quantized
13
+ - q4tp
14
+ - moe
15
+ - code
16
+ - expert-pruning
17
+ - cuda
18
+ - hy4-flash
19
+ language:
20
+ - en
21
+ - ru
22
+ - zh
23
+ ---
24
+
25
+ # Hy4-flash Fast Code — CMF
26
+
27
+ [Tencent Hy4-flash](https://huggingface.co/tencent/Hy4-flash) cut for code: 256 of the 512 routed experts of every
28
+ layer, at 4 bits, in one 111.7 GB [CMF](https://github.com/infosave2007/cmf) file for `cortiq`, a Rust inference
29
+ engine with no Python and no ML framework.
30
+
31
+ - **Speed, CUDA:** 48.2 tok/s on an RTX PRO 6000, 30.6 tok/s within 24 GB and 26.2 tok/s within 16 GB of card
32
+ memory; the full model 48.0 / 11.9 / 8.9 on the same card.
33
+ - **Code:** perplexity on fresh code 8.97 (the full model 8.42), on Rust 4.22 (3.92); HumanEval
34
+ pass@1 93.3 %.
35
+ - **The router stays whole.** It still chooses 16 of all 512 experts with the full model's weights; a pick of a
36
+ dropped expert adds nothing and the kept picks keep their weights.
37
+
38
+ [English](#quick-start) · [Русский](#документация-на-русском) · [中文](#中文说明)
39
+
40
+ ## Quick start
41
+
42
+ ```bash
43
+ cargo install cortiq-cli --features cuda
44
+ hf download infosave/Hy4-flash-Fast-Code-cmf hy4-flash-fast-code.cmf hy4-flash-fast-code.cmf.sha256 --local-dir .
45
+ sha256sum -c hy4-flash-fast-code.cmf.sha256
46
+ CMF_GPU=cuda cortiq run hy4-flash-fast-code.cmf --prompt "Write a Rust function that parses an ISO 8601 date." --greedy --no-think
47
+ ```
48
+
49
+ cortiq 0.9.7 or newer, built with `--features cuda` (CUDA 12.x `libnvrtc` and `libcublas` at run time, no CUDA
50
+ toolkit at build time). The file runs on CUDA; Vulkan, DX12 and Metal read it on the host for now (slow). On cards
51
+ below the whole file the routed experts live in host memory (the RAM tier) and the card keeps the hot ones; the
52
+ Engram tables are read from the page cache (63 GB).
53
+
54
+ ## How it was cut
55
+
56
+ 1. The full `q4tp` model read 89 677 tokens: 32 768 of Python code (Magicoder), a long programming task (an
57
+ interactive three.js page) with the full model's answers, and a cut's own answers to that task. Every routed
58
+ FFN's latent input, picks and weights were captured (`cortiq hy4-sfq --capture-only`).
59
+ 2. Per layer, every expert's output on its own picks: the 256 experts with the largest energy
60
+ Σ (weight · ‖output‖)² were kept. On held-out tokens this leaves 5.4 % of a layer's routed output missing,
61
+ against 8.6 % for the most often picked 256.
62
+ 3. `CMF_DEFRAG_ABSENT=1 cortiq moe-defrag --keep 256`: the other experts are left out of the file, the kept ones keep
63
+ their numbers, the router and its selection bias stay whole.
64
+
65
+ Why the router stays whole: a plain cut lets the router choose among the kept experts only, so a pick of a dropped
66
+ expert falls to another one and the weights renormalize over the rest. Hy4-flash's experts do not stand in for
67
+ each other (the best kept substitute reconstructs a dropped expert's output worse than nothing), so that costs
68
+ code more: perplexity on fresh code 9.75 for the plain cut of the same 256 experts, 8.97 here.
69
+
70
+ ## Quality
71
+
72
+ | model | fresh code | Rust source | HumanEval pass@1 |
73
+ |---|---:|---:|---:|
74
+ | Fast Code (256 experts) | **8.97** | **4.22** | **93.3 %** |
75
+ | plain cut of the same experts | 9.75 | 4.31 | — |
76
+ | full `q4tp` (512 experts) | 8.42 | 3.92 | 93.9 % |
77
+
78
+ Perplexity, windows of 512 tokens on the card's prompt graph: code written after the model's release (16 windows),
79
+ Rust source (8). HumanEval: 164 problems through `cortiq serve`, greedy, thinking off.
80
+
81
+ **Long code.** An interactive three.js aquarium as one HTML page (6 400–8 900 tokens): 2 of 4 runs (greedy and three seeds) gave a working page, the full model 6 of 6. The other two are valid JavaScript that misuse three.js (a module import without an importmap; a missing page element).
82
+
83
+ ![An aquarium page this file wrote (seed 13)](https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/assets/aquarium_fast_code.png)
84
+
85
+ ## Speed · RTX PRO 6000
86
+
87
+ Stand: NVIDIA RTX PRO 6000 Blackwell Server Edition (96 GB), the CUDA backend (`CMF_GPU=cuda`), a release build.
88
+ `cortiq run --greedy --no-think`, 256 tokens after a 1 000-token WikiText-2 prompt, the file already in the page
89
+ cache (a second run); `CMF_GPU_VRAM_MB` caps the card.
90
+
91
+ | limit (`CMF_GPU_VRAM_MB`) | Fast Code decode, tok/s | full decode, tok/s | peak in use Fast Code / full, GB |
92
+ |---:|---:|---:|---:|
93
+ | 96 GB (whole) | **48.2** | 48.0 | 50.7 / 88.6 |
94
+ | 24 GB | **30.6** | 11.9 | 24.2 / 24.3 |
95
+ | 16 GB | **26.2** | 8.9 | 16.3 / 16.3 |
96
+
97
+ Host: 48 CPU cores and 176 GB of RAM, so the 111.7 GB file stays in the page cache while the 150.5 GB full model
98
+ does not; that is most of the gap within 24 and 16 GB, where the experts come from host memory. Within 12 GB the
99
+ expert slots do not fit and the prompt falls to the host.
100
+
101
+ ![Decode by card size](https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/assets/fc_cuda_en.png)
102
+
103
+ ## Server
104
+
105
+ ```bash
106
+ CMF_GPU=cuda cortiq serve hy4-flash-fast-code.cmf --port 8080 --host 127.0.0.1
107
+ curl http://localhost:8080/v1/chat/completions -H 'Content-Type: application/json' \
108
+ -d '{"model":"hy4-fast-code","messages":[{"role":"user","content":"Write a binary search in Python."}],"max_tokens":512}'
109
+ ```
110
+
111
+ An OpenAI-compatible API (`/v1/chat/completions`, `/v1/completions`, streaming) and a web dashboard on the same
112
+ port.
113
+
114
+ ## License
115
+
116
+ The weights are Tencent's, under the [Tencent Hy License](LICENSE) (a copy is in this repository). This file is a
117
+ modified form: converted to CMF, quantized and cut to 256 routed experts a layer as described above.
118
+
119
+ ---
120
+
121
+ ## Документация на русском
122
+
123
+ [Tencent Hy4-flash](https://huggingface.co/tencent/Hy4-flash), урезанная под код: 256 из 512 маршрутизируемых
124
+ экспертов каждого слоя, 4 бита, один файл [CMF](https://github.com/infosave2007/cmf) на 111,7 ГБ для `cortiq` —
125
+ движка инференса на Rust без Python и ML-фреймворков.
126
+
127
+ - **Скорость, CUDA:** 48,2 ток/с на RTX PRO 6000, 30,6 ток/с в пределах 24 ГБ и 26,2 ток/с в пределах 16 ГБ
128
+ памяти карты; полная модель на той же карте — 48,0 / 11,9 / 8,9.
129
+ - **Код:** перплексия на свежем коде 8,97 (полная модель 8,42), на Rust 4,22 (3,92); HumanEval
130
+ pass@1 93,3 %.
131
+ - **Роутер остаётся целым.** Он по-прежнему выбирает 16 из всех 512 экспертов с весами полной модели; выбор
132
+ выброшенного эксперта ничего не добавляет, а оставшиеся выборы сохраняют свои веса.
133
+
134
+ ### Быстрый старт
135
+
136
+ ```bash
137
+ cargo install cortiq-cli --features cuda
138
+ hf download infosave/Hy4-flash-Fast-Code-cmf hy4-flash-fast-code.cmf hy4-flash-fast-code.cmf.sha256 --local-dir .
139
+ sha256sum -c hy4-flash-fast-code.cmf.sha256
140
+ CMF_GPU=cuda cortiq run hy4-flash-fast-code.cmf --prompt "Напиши на Rust функцию разбора даты ISO 8601." --greedy --no-think
141
+ ```
142
+
143
+ Нужен cortiq 0,9.7 или новее, собранный с `--features cuda` (во время работы — `libnvrtc` и `libcublas` из
144
+ CUDA 12.x, для сборки CUDA не нужна). Файл работает на CUDA; Vulkan, DX12 и Metal пока читают его на хосте
145
+ (медленно). На картах меньше файла маршрутизируемые эксперты живут в памяти хоста (RAM-уровень), а карта держит
146
+ горячих; таблицы Engram читаются из страничного кэша (63 ГБ).
147
+
148
+ ### Как урезали
149
+
150
+ 1. Полная модель `q4tp` прочитала 89 677 токенов: 32 768 токенов кода на Python (Magicoder), длинную задачу по
151
+ программированию (интерактивная страница на three.js) с ответами полной модели и ответы урезанной модели на эту
152
+ же задачу. Для каждого маршрутизируемого FFN сохранены латентный вход, выборы и веса
153
+ (`cortiq hy4-sfq --capture-only`).
154
+ 2. В каждом слое посчитан выход каждого эксперта на его выборах; оставлены 256 экспертов с наибольшей энергией
155
+ Σ (вес · ‖выход‖)². На отложенных токенах это теряет 5,4 % маршрутизируемого выхода слоя против 8,6 % у 256
156
+ самых часто выбираемых.
157
+ 3. `CMF_DEFRAG_ABSENT=1 cortiq moe-defrag --keep 256`: остальные эксперты не попадают в файл, оставшиеся сохраняют
158
+ номера, роутер и его смещение выбора остаются целыми.
159
+
160
+ Почему роутер целый: обычная нарезка даёт роутеру выбирать только среди оставшихся экспертов — выбор выброшенного
161
+ переходит к другому, а веса перенормируются. Эксперты Hy4-flash не заменяют друг друга (лучший оставшийся заменитель
162
+ восстанавливает выход выброшенного хуже, чем ноль), и это сильнее бьёт по коду: перплексия на свежем коде
163
+ 9,75 у обычной нарезки тех же 256 экспертов, 8,97 здесь.
164
+
165
+ ### Качество
166
+
167
+ | модель | свежий код | код на Rust | HumanEval pass@1 |
168
+ |---|---:|---:|---:|
169
+ | Fast Code (256 экспертов) | **8,97** | **4,22** | **93,3 %** |
170
+ | обычная нарезка тех же экспертов | 9,75 | 4,31 | — |
171
+ | полная `q4tp` (512 экспертов) | 8,42 | 3,92 | 93,9 % |
172
+
173
+ Перплексия, окна по 512 токенов на графе промпта карты: код, написанный после выхода модели (16 окон), исходники на
174
+ Rust (8). HumanEval: 164 задачи через `cortiq serve`, жадно, без размышлений.
175
+
176
+ **Длинный код.** Интерактивный аквариум на three.js одной HTML-страницей (6 400–8 900 токенов): 2 из 4 запусков (жадный и три сида) дали рабочую страницу, полная модель — 6 из 6. Остальные два — корректный JavaScript с ошибками в использовании three.js (импорт модуля без importmap; обращение к несуществующему элементу страницы).
177
+
178
+ ![Страница-аквариум, написанная этим файлом (сид 13)](https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/assets/aquarium_fast_code.png)
179
+
180
+ ### Скорость · RTX PRO 6000
181
+
182
+ Стенд: NVIDIA RTX PRO 6000 Blackwell Server Edition (96 ГБ), бэкенд CUDA (`CMF_GPU=cuda`), релизная сборка.
183
+ `cortiq run --greedy --no-think`, 256 токенов после промпта WikiText-2 из 1 000 токенов, файл уже в страничном кэше
184
+ (второй запуск); `CMF_GPU_VRAM_MB` ограничивает карту.
185
+
186
+ | лимит (`CMF_GPU_VRAM_MB`) | Fast Code, декод ток/с | полная, декод ток/с | пик занятой памяти Fast Code / полная, ГБ |
187
+ |---:|---:|---:|---:|
188
+ | 96 ГБ (вся) | **48,2** | 48,0 | 50,7 / 88,6 |
189
+ | 24 ГБ | **30,6** | 11,9 | 24,2 / 24,3 |
190
+ | 16 ГБ | **26,2** | 8,9 | 16,3 / 16,3 |
191
+
192
+ Хост: 48 ядер и 176 ГБ памяти, поэтому файл на 111,7 ГБ остаётся в страничном кэше, а полная модель на 150,5 ГБ —
193
+ нет; отсюда основная часть разрыва в пределах 24 и 16 ГБ, где эксперты приходят из памяти хоста. В пределах 12 ГБ
194
+ слоты экспертов не помещаются, и промпт уходит на хост.
195
+
196
+ ![Декод по объёму карты](https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/assets/fc_cuda_ru.png)
197
+
198
+ ### Сервер
199
+
200
+ ```bash
201
+ CMF_GPU=cuda cortiq serve hy4-flash-fast-code.cmf --port 8080 --host 127.0.0.1
202
+ ```
203
+
204
+ OpenAI-совместимый API (`/v1/chat/completions`, `/v1/completions`, потоковый вывод) и веб-панель на том же порту.
205
+
206
+ ### Лицензия
207
+
208
+ Веса принадлежат Tencent и распространяются по [Tencent Hy License](LICENSE) (копия в этом репозитории). Этот файл —
209
+ изменённая форма: конвертирован в CMF, квантован и урезан до 256 маршрутизируемых экспертов на слой, как описано выше.
210
+
211
+ ---
212
+
213
+ ## 中文说明
214
+
215
+ 为代码裁剪的 [Tencent Hy4-flash](https://huggingface.co/tencent/Hy4-flash):每层 512 个路由专家保留 256 个,4 比特,
216
+ 一个 111.7 GB 的 [CMF](https://github.com/infosave2007/cmf) 文件,供 `cortiq` 使用——一个不依赖 Python 和机器学习框架的 Rust 推理引擎。
217
+
218
+ - **速度(CUDA):** RTX PRO 6000 上 48.2 tok/s,显存限制在 24 GB 时 30.6 tok/s,16 GB 时 26.2 tok/s;同一张卡上完整模型为 48.0 / 11.9 / 8.9。
219
+ - **代码:** 新代码困惑度 8.97(完整模型 8.42),Rust 4.22(3.92);HumanEval pass@1 93.3 %。
220
+ - **路由器保持完整。** 它仍以完整模型的权重从全部 512 个专家中选出 16 个;选中被删除的专家时不产生任何贡献,其余选中专家保持原有权重。
221
+
222
+ ### 快速开始
223
+
224
+ ```bash
225
+ cargo install cortiq-cli --features cuda
226
+ hf download infosave/Hy4-flash-Fast-Code-cmf hy4-flash-fast-code.cmf hy4-flash-fast-code.cmf.sha256 --local-dir .
227
+ sha256sum -c hy4-flash-fast-code.cmf.sha256
228
+ CMF_GPU=cuda cortiq run hy4-flash-fast-code.cmf --prompt "用 Rust 写一个解析 ISO 8601 日期的函数。" --greedy --no-think
229
+ ```
230
+
231
+ 需要 cortiq 0.9.7 或更新版本,并以 `--features cuda` 构建(运行时需要 CUDA 12.x 的 `libnvrtc` 和 `libcublas`,构建时不需要 CUDA)。
232
+ 该文件在 CUDA 上运行;Vulkan、DX12 和 Metal 目前在主机上读取它(较慢)。显存小于文件时,路由专家放在主机内存(RAM 层),显卡保留热门专家;Engram 表从页缓存读取(63 GB)。
233
+
234
+ ### 裁剪方法
235
+
236
+ 1. 完整的 `q4tp` 模型读取 89 677 个 token:32 768 个 Python 代码 token(Magicoder)、一个较长的编程任务(交互式 three.js 页面)及完整模型的回答,以及裁剪模型对该任务的回答。记录每个路由 FFN 的潜在输入、选择和权重(`cortiq hy4-sfq --capture-only`)。
237
+ 2. 每层计算每个专家在其被选中位置上的输出;保留能量 Σ(权重 · ‖输出‖)² 最大的 256 个专家。在留出的 token 上,这样丢失该层路由输出的 5.4 %,而按选择次数保留 256 个时为 8.6 %。
238
+ 3. `CMF_DEFRAG_ABSENT=1 cortiq moe-defrag --keep 256`:其余专家不写入文件,保留的专家保持编号,路由器及其选择偏置保持完整。
239
+
240
+ 为何保持路由器完整:普通裁剪让路由器只在保留的专家中选择,被删除专家的选择落到其他专家上,权重在其余专家间重新归一化。Hy4-flash 的专家无法互相替代(最佳替代专家重建被删除专家输出的效果比零还差),这对代码影响更大:同样 256 个专家的普通裁剪新代码困惑度为 9.75,本文件为 8.97。
241
+
242
+ ### 质量
243
+
244
+ | 模型 | 新代码 | Rust 源码 | HumanEval pass@1 |
245
+ |---|---:|---:|---:|
246
+ | Fast Code(256 专家) | **8.97** | **4.22** | **93.3 %** |
247
+ | 相同专家的普通裁剪 | 9.75 | 4.31 | — |
248
+ | 完整 `q4tp`(512 专家) | 8.42 | 3.92 | 93.9 % |
249
+
250
+ 困惑度:显卡提示图上 512 token 窗口,模型发布后编写的代码(16 个窗口),Rust 源码(8 个)。HumanEval:通过 `cortiq serve` 的 164 道题,贪婪解码,关闭思考。
251
+
252
+ **长代码。** 单个 HTML 页面的交互式 three.js 水族箱(6 400–8 900 token):4 次运行(贪婪解码和三个随机种子)中有 2 次生成了可运行的页面,完整模型为 6 次中 6 次。另外两次是语法正确的 JavaScript,但误用了 three.js(没有 importmap 的模块导入;引用了不存在的页面元素)。
253
+
254
+ ![本文件生成的水族箱页面(种子 13)](https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/assets/aquarium_fast_code.png)
255
+
256
+ ### 速度 · RTX PRO 6000
257
+
258
+ 测试平台:NVIDIA RTX PRO 6000 Blackwell Server Edition(96 GB),CUDA 后端(`CMF_GPU=cuda`),发布版构建。
259
+ `cortiq run --greedy --no-think`,1000 token 的 WikiText-2 提示后生成 256 token,文件已在页缓存中(第二次运行);`CMF_GPU_VRAM_MB` 限制显存。
260
+
261
+ | 限制(`CMF_GPU_VRAM_MB`) | Fast Code 解码 tok/s | 完整模型解码 tok/s | 峰值显存 Fast Code / 完整,GB |
262
+ |---:|---:|---:|---:|
263
+ | 96 GB (整卡) | **48.2** | 48.0 | 50.7 / 88.6 |
264
+ | 24 GB | **30.6** | 11.9 | 24.2 / 24.3 |
265
+ | 16 GB | **26.2** | 8.9 | 16.3 / 16.3 |
266
+
267
+ 主机:48 个 CPU 核心和 176 GB 内存,因此 111.7 GB 的文件能留在页缓存中,而 150.5 GB 的完整模型不能;这是 24 GB 和 16 GB 限制下(专家来自主机内存)差距的主要来源。显存限制为 12 GB 时专家槽位放不下,提示会回退到主机。
268
+
269
+ ![按显存大小的解码速度](https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/assets/fc_cuda_zh.png)
270
+
271
+ ### 服务器
272
+
273
+ ```bash
274
+ CMF_GPU=cuda cortiq serve hy4-flash-fast-code.cmf --port 8080 --host 127.0.0.1
275
+ ```
276
+
277
+ 同一端口提供兼容 OpenAI 的 API(`/v1/chat/completions`、`/v1/completions`、流式输出)和网页控制台。
278
+
279
+ ### 许可证
280
+
281
+ 权重归腾讯所有,遵循 [Tencent Hy License](LICENSE)(本仓库附有副本)。本文件为修改形式:转换为 CMF、量化,并按上述方法裁剪为每层 256 个路由专家。
assets/aquarium_fast_code.png ADDED

Git LFS Details

  • SHA256: ab4cfac520b105583612fc822b519b099ff272ec25d82f1758d0aab7784dde55
  • Pointer size: 131 Bytes
  • Size of remote file: 326 kB
assets/fc_cuda_en.png ADDED
assets/fc_cuda_ru.png ADDED
assets/fc_cuda_zh.png ADDED
hy4-flash-fast-code.cmf.sha256 ADDED
@@ -0,0 +1 @@
 
 
1
+ a3333a6df0eacbae2c28590f586d98e29cc6a56903092fdc4d2eef3c1a01d8e7 hy4-flash-fast-code.cmf