Text Generation
cortiq
English
Russian
Chinese
cmf
quantized
q4tp
Mixture of Experts
code
expert-pruning
cuda
hy4-flash
Instructions to use infosave/Hy4-flash-Fast-Code-cmf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- cortiq
How to use infosave/Hy4-flash-Fast-Code-cmf with cortiq:
# one Rust binary, no additional dependencies cargo install cortiq-cli # or a prebuilt binary from github.com/infosave2007/cmf/releases hf download infosave/Hy4-flash-Fast-Code-cmf --include "*.cmf" --local-dir . ls *.cmf # some repos ship more than one quantization
cortiq run FILE.cmf --prompt "What is the capital of France?"
cortiq serve FILE.cmf --port 8080 # OpenAI-compatible server
- Notebooks
- Google Colab
- Kaggle
|
Download README.md from infosave/Hy4-flash-Fast-Code-cmf: direct link, hf CLI and curl.
- Browser
- Download file 21.2 kB
-
https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/README.md
- Command line
-
hf download hf://infosave/Hy4-flash-Fast-Code-cmf/README.md
-
curl -L -o README.md https://huggingface.co/infosave/Hy4-flash-Fast-Code-cmf/resolve/main/README.md
21.2 kB
| license: other | |
| license_name: tencent-hy-license | |
| license_link: LICENSE | |
| library_name: cortiq | |
| base_model: tencent/Hy4-flash | |
| base_model_relation: quantized | |
| pipeline_tag: text-generation | |
| tags: | |
| - cmf | |
| - cortiq | |
| - quantized | |
| - q4tp | |
| - moe | |
| - code | |
| - expert-pruning | |
| - cuda | |
| - hy4-flash | |
| language: | |
| - en | |
| - ru | |
| - zh | |
| # Hy4-flash Fast Code — CMF | |
| [Tencent Hy4-flash](https://huggingface.co/tencent/Hy4-flash) cut for code: 256 of the 512 routed experts of every | |
| layer, in [CMF](https://github.com/infosave2007/cmf) files for `cortiq`, a Rust inference engine with no Python and | |
| no ML framework. | |
| - **Speed, CUDA:** `hy4-flash-fast-code-q4.cmf` decodes 67.4 tok/s on an RTX PRO 6000, 49.5 tok/s within 24 GB, | |
| 39.8 within 16 GB and 32.6 within 12 GB of card memory; the full 512-expert model 48.0 / 11.9 / 8.9 on the same | |
| card (cortiq 0.9.7). | |
| - **Code:** HumanEval pass@1 92.7 % (the full model 93.9 %); perplexity on fresh code 9.63 (8.42). | |
| - **The router stays whole.** It still chooses 16 of all 512 experts with the full model's weights; a pick of a | |
| dropped expert adds nothing and the kept picks keep their weights. | |
| [English](#quick-start) · [Русский](#документация-на-русском) · [中文](#中文说明) | |
| ## Quick start | |
| ```bash | |
| cargo install cortiq-cli --features cuda | |
| hf download infosave/Hy4-flash-Fast-Code-cmf hy4-flash-fast-code-q4.cmf hy4-flash-fast-code-q4.cmf.sha256 --local-dir . | |
| sha256sum -c hy4-flash-fast-code-q4.cmf.sha256 | |
| CMF_GPU=cuda cortiq run hy4-flash-fast-code-q4.cmf --prompt "Write a Rust function that parses an ISO 8601 date." --greedy --no-think | |
| ``` | |
| cortiq 0.9.8 or newer, built with `--features cuda` (CUDA 12.x `libnvrtc` and `libcublas` at run time, no CUDA | |
| toolkit at build time). The files run on CUDA; Vulkan, DX12 and Metal read them on the host for now (slow). On cards | |
| below the whole file the routed experts live in host memory (the RAM tier) and the card keeps the hot ones; the | |
| Engram tables are read from the page cache. | |
| ## Files | |
| | file | routed experts | attention, shared expert, latent projections | size | use | | |
| |---|---|---|---:|---| | |
| | `hy4-flash-fast-code-q4.cmf` | 256 a layer, 4-bit | 4-bit | 108.8 GB | **default**: the fastest | | |
| | `hy4-flash-fast-code.cmf` | 256 a layer, 4-bit | 8-bit | 111.7 GB | a little more accurate, slower | | |
| Both keep the head at 8 bits and the router, the Engram tables and the hyper-connections as released. | |
| ## How it was cut | |
| 1. The full `q4tp` model read 89 677 tokens: 32 768 of Python code (Magicoder), a long programming task (an | |
| interactive three.js page) with the full model's answers, and a cut's own answers to that task. Every routed | |
| FFN's latent input, picks and weights were captured (`cortiq hy4-sfq --capture-only`). | |
| 2. Per layer, every expert's output on its own picks: the 256 experts with the largest energy | |
| Σ (weight · ‖output‖)² were kept. On held-out tokens this leaves 5.4 % of a layer's routed output missing, | |
| against 8.6 % for the most often picked 256. | |
| 3. `CMF_DEFRAG_ABSENT=1 cortiq moe-defrag --keep 256`: the other experts are left out of the file, the kept ones keep | |
| their numbers, the router and its selection bias stay whole (`hy4-flash-fast-code.cmf`). | |
| 4. `cortiq requant --quant q4tp-dense`: the 8-bit attention, shared expert and latent projections at 4 bits | |
| (`hy4-flash-fast-code-q4.cmf`): half the bytes of that part a token. | |
| Why the router stays whole: a plain cut lets the router choose among the kept experts only, so a pick of a dropped | |
| expert falls to another one and the weights renormalize over the rest. Hy4-flash's experts do not stand in for | |
| each other (the best kept substitute reconstructs a dropped expert's output worse than nothing), so that costs | |
| code more: perplexity on fresh code 9.75 for the plain cut of the same 256 experts, 8.97 here. | |
| ## Quality | |
| | model | fresh code | Rust source | HumanEval pass@1 | | |
| |---|---:|---:|---:| | |
| | `hy4-flash-fast-code-q4.cmf` | 9.63 | 4.43 | 92.7 % | | |
| | `hy4-flash-fast-code.cmf` | **8.97** | **4.22** | **93.3 %** | | |
| | plain cut of the same experts | 9.75 | 4.31 | — | | |
| | full `q4tp` (512 experts) | 8.42 | 3.92 | 93.9 % | | |
| Perplexity, windows of 512 tokens on the card's prompt graph: code written after the model's release (16 windows), | |
| Rust source (8). HumanEval: 164 problems through `cortiq serve`, greedy, thinking off. | |
| **Long code** (`hy4-flash-fast-code.cmf`). 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). | |
|  | |
| ## Speed · RTX PRO 6000 | |
| Stand: NVIDIA RTX PRO 6000 Blackwell Server Edition (96 GB), 48 CPU cores, 176 GB of RAM, the CUDA backend | |
| (`CMF_GPU=cuda`), a release build. `cortiq run --greedy --no-think`, 256 tokens after a 1 000-token WikiText-2 | |
| prompt, the file already in the page cache; `CMF_GPU_VRAM_MB` caps the card; the mean of two runs (one within 12 GB). | |
| | limit (`CMF_GPU_VRAM_MB`) | `hy4-flash-fast-code-q4.cmf`, cortiq 0.9.8 | full model (512 experts), cortiq 0.9.7 | | |
| |---:|---:|---:| | |
| | 96 GB (whole) | **67.4** tok/s | 48.0 tok/s | | |
| | 24 GB | **49.5** | 11.9 | | |
| | 16 GB | **39.8** | 8.9 | | |
| | 12 GB | **32.6** | — | | |
| Part of the gap within 24 and 16 GB is the host: its page cache holds the 108.8 GB file but not the 150.5 GB full | |
| model, and there the experts come from host memory. The full model was not measured within 12 GB. | |
|  | |
| ## Server | |
| ```bash | |
| CMF_GPU=cuda cortiq serve hy4-flash-fast-code-q4.cmf --port 8080 --host 127.0.0.1 | |
| curl http://localhost:8080/v1/chat/completions -H 'Content-Type: application/json' \ | |
| -d '{"model":"hy4-fast-code","messages":[{"role":"user","content":"Write a binary search in Python."}],"max_tokens":512}' | |
| ``` | |
| An OpenAI-compatible API (`/v1/chat/completions`, `/v1/completions`, streaming) and a web dashboard on the same | |
| port. | |
| ## License | |
| The weights are Tencent's, under the [Tencent Hy License](LICENSE) (a copy is in this repository). These files are a | |
| modified form: converted to CMF, quantized and cut to 256 routed experts a layer as described above. | |
| --- | |
| ## Документация на русском | |
| [Tencent Hy4-flash](https://huggingface.co/tencent/Hy4-flash), урезанная под код: 256 из 512 маршрутизируемых | |
| экспертов каждого слоя, файлы [CMF](https://github.com/infosave2007/cmf) для `cortiq` — движка инференса на Rust без | |
| Python и ML-фреймворков. | |
| - **Скорость, CUDA:** `hy4-flash-fast-code-q4.cmf` декодирует 67,4 ток/с на RTX PRO 6000, 49,5 ток/с в пределах | |
| 24 ГБ, 39,8 — в пределах 16 ГБ и 32,6 — в пределах 12 ГБ памяти карты; полная модель на 512 экспертов на той же | |
| карте — 48,0 / 11,9 / 8,9 (cortiq 0.9.7). | |
| - **Код:** HumanEval pass@1 92,7 % (полная модель 93,9 %); перплексия на свежем коде 9,63 (8,42). | |
| - **Роутер остаётся целым.** Он по-прежнему выбирает 16 из всех 512 экспертов с весами полной модели; выбор | |
| выброшенного эксперта ничего не добавляет, а оставшиеся выборы сохраняют свои веса. | |
| ### Быстрый старт | |
| ```bash | |
| cargo install cortiq-cli --features cuda | |
| hf download infosave/Hy4-flash-Fast-Code-cmf hy4-flash-fast-code-q4.cmf hy4-flash-fast-code-q4.cmf.sha256 --local-dir . | |
| sha256sum -c hy4-flash-fast-code-q4.cmf.sha256 | |
| CMF_GPU=cuda cortiq run hy4-flash-fast-code-q4.cmf --prompt "Напиши на Rust функцию разбора даты ISO 8601." --greedy --no-think | |
| ``` | |
| Нужен cortiq 0.9.8 или новее, собранный с `--features cuda` (во время работы — `libnvrtc` и `libcublas` из CUDA | |
| 12.x, для сборки CUDA не нужна). Файлы работают на CUDA; Vulkan, DX12 и Metal пока читают их на хосте (медленно). На | |
| картах меньше файла маршрутизируемые эксперты живут в памяти хоста (RAM-уровень), а карта держит горячих; таблицы | |
| Engram читаются из страничного кэша. | |
| ### Файлы | |
| | файл | маршрутизируемые эксперты | внимание, общий эксперт, латентные проекции | размер | когда брать | | |
| |---|---|---|---:|---| | |
| | `hy4-flash-fast-code-q4.cmf` | 256 на слой, 4 бита | 4 бита | 108,8 ГБ | **по умолчанию**: самый быстрый | | |
| | `hy4-flash-fast-code.cmf` | 256 на слой, 4 бита | 8 бит | 111,7 ГБ | чуть точнее, медленнее | | |
| В обоих голова в 8 битах, роутер, таблицы Engram и гиперсвязи — как в релизе. | |
| ### Как урезали | |
| 1. Полная модель `q4tp` прочитала 89 677 токенов: 32 768 токенов кода на Python (Magicoder), длинную задачу по | |
| программированию (интерактивная страница на three.js) с ответами полной модели и ответы урезанной модели на эту | |
| же задачу. Для каждого маршрутизируемого FFN сохранены латентный вход, выборы и веса | |
| (`cortiq hy4-sfq --capture-only`). | |
| 2. В каждом слое посчитан выход каждого эксперта на его выборах; оставлены 256 экспертов с наибольшей энергией | |
| Σ (вес · ‖выход‖)². На отложенных токенах это теряет 5,4 % маршрутизируемого выхода слоя против 8,6 % у 256 | |
| самых часто выбираемых. | |
| 3. `CMF_DEFRAG_ABSENT=1 cortiq moe-defrag --keep 256`: остальные эксперты не попадают в файл, оставшиеся сохраняют | |
| номера, роутер и его смещение выбора остаются целыми (`hy4-flash-fast-code.cmf`). | |
| 4. `cortiq requant --quant q4tp-dense`: 8-битные внимание, общий эксперт и латентные проекции — в 4 бита | |
| (`hy4-flash-fast-code-q4.cmf`): вдвое меньше байт этой части на токен. | |
| Почему роутер целый: обычная нарезка даёт роутеру выбирать только среди оставшихся экспертов — выбор выброшенного | |
| переходит к другому, а веса перенормируются. Эксперты Hy4-flash не заменяют друг друга (лучший оставшийся заменитель | |
| восстанавливает выход выброшенного хуже, чем ноль), и это сильнее бьёт по коду: перплексия на свежем коде 9,75 у | |
| обычной нарезки тех же 256 экспертов, 8,97 здесь. | |
| ### Качество | |
| | модель | свежий код | код на Rust | HumanEval pass@1 | | |
| |---|---:|---:|---:| | |
| | `hy4-flash-fast-code-q4.cmf` | 9,63 | 4,43 | 92,7 % | | |
| | `hy4-flash-fast-code.cmf` | **8,97** | **4,22** | **93,3 %** | | |
| | обычная нарезка тех же экспертов | 9,75 | 4,31 | — | | |
| | полная `q4tp` (512 экспертов) | 8,42 | 3,92 | 93,9 % | | |
| Перплексия, окна по 512 токенов на графе промпта карты: код, написанный после выхода модели (16 окон), исходники на | |
| Rust (8). HumanEval: 164 задачи через `cortiq serve`, жадно, без размышлений. | |
| **Длинный код** (`hy4-flash-fast-code.cmf`). Интерактивный аквариум на three.js одной HTML-страницей (6 400–8 900 токенов): 2 из 4 запусков (жадный и три сида) дали рабочую страницу, полная модель — 6 из 6. Остальные два — корректный JavaScript с ошибками в использовании three.js (импорт модуля без importmap; обращение к несуществующему элементу страницы). | |
|  | |
| ### Скорость · RTX PRO 6000 | |
| Стенд: NVIDIA RTX PRO 6000 Blackwell Server Edition (96 ГБ), 48 ядер, 176 ГБ памяти, бэкенд CUDA (`CMF_GPU=cuda`), | |
| релизная сборка. `cortiq run --greedy --no-think`, 256 токенов после промпта WikiText-2 из 1 000 токенов, файл уже | |
| в страничном кэше; `CMF_GPU_VRAM_MB` ограничивает карту; среднее двух прогонов (в пределах 12 ГБ — один). | |
| | лимит (`CMF_GPU_VRAM_MB`) | `hy4-flash-fast-code-q4.cmf`, cortiq 0.9.8 | полная модель (512 экспертов), cortiq 0.9.7 | | |
| |---:|---:|---:| | |
| | 96 ГБ (вся) | **67,4** ток/с | 48,0 ток/с | | |
| | 24 ГБ | **49,5** | 11,9 | | |
| | 16 ГБ | **39,8** | 8,9 | | |
| | 12 ГБ | **32,6** | — | | |
| Часть разрыва в пределах 24 и 16 ГБ — от хоста: его страничный кэш держит файл на 108,8 ГБ, но не полную модель на | |
| 150,5 ГБ, а там эксперты приходят из памяти хоста. Полную модель в пределах 12 ГБ не мерили. | |
|  | |
| ### Сервер | |
| ```bash | |
| CMF_GPU=cuda cortiq serve hy4-flash-fast-code-q4.cmf --port 8080 --host 127.0.0.1 | |
| ``` | |
| OpenAI-совместимый API (`/v1/chat/completions`, `/v1/completions`, потоковый вывод) и веб-панель на том же порту. | |
| ### Лицензия | |
| Веса принадлежат Tencent и распространяются по [Tencent Hy License](LICENSE) (копия в этом репозитории). Эти файлы — | |
| изменённая форма: конвертированы в CMF, квантованы и урезаны до 256 маршрутизируемых экспертов на слой, как описано | |
| выше. | |
| --- | |
| ## 中文说明 | |
| 为代码裁剪的 [Tencent Hy4-flash](https://huggingface.co/tencent/Hy4-flash):每层 512 个路由专家保留 256 个,[CMF](https://github.com/infosave2007/cmf) 文件,供 `cortiq` 使用——一个不依赖 Python 和机器学习框架的 Rust 推理引擎。 | |
| - **速度(CUDA):** `hy4-flash-fast-code-q4.cmf` 在 RTX PRO 6000 上解码 67.4 tok/s,显存限制在 24 GB 时 49.5 tok/s,16 GB 时 39.8,12 GB 时 32.6;同一张卡上完整的 512 专家模型为 48.0 / 11.9 / 8.9(cortiq 0.9.7)。 | |
| - **代码:** HumanEval pass@1 92.7 %(完整模型 93.9 %);新代码困惑度 9.63(8.42)。 | |
| - **路由器保持完整。** 它仍以完整模型的权重从全部 512 个专家中选出 16 个;选中被删除的专家时不产生任何贡献,其余选中专家保持原有权重。 | |
| ### 快速开始 | |
| ```bash | |
| cargo install cortiq-cli --features cuda | |
| hf download infosave/Hy4-flash-Fast-Code-cmf hy4-flash-fast-code-q4.cmf hy4-flash-fast-code-q4.cmf.sha256 --local-dir . | |
| sha256sum -c hy4-flash-fast-code-q4.cmf.sha256 | |
| CMF_GPU=cuda cortiq run hy4-flash-fast-code-q4.cmf --prompt "用 Rust 写一个解析 ISO 8601 日期的函数。" --greedy --no-think | |
| ``` | |
| 需要 cortiq 0.9.8 或更新版本,并以 `--features cuda` 构建(运行时需要 CUDA 12.x 的 `libnvrtc` 和 `libcublas`,构建时不需要 CUDA)。 | |
| 这些文件在 CUDA 上运行;Vulkan、DX12 和 Metal 目前在主机上读取它们(较慢)。显存小于文件时,路由专家放在主机内存(RAM 层),显卡保留热门专家;Engram 表从页缓存读取。 | |
| ### 文件 | |
| | 文件 | 路由专家 | 注意力、共享专家、潜在投影 | 大小 | 用途 | | |
| |---|---|---|---:|---| | |
| | `hy4-flash-fast-code-q4.cmf` | 每层 256 个,4 比特 | 4 比特 | 108.8 GB | **默认**:最快 | | |
| | `hy4-flash-fast-code.cmf` | 每层 256 个,4 比特 | 8 比特 | 111.7 GB | 略更准确,较慢 | | |
| 两者的输出头均为 8 比特,路由器、Engram 表和超连接保持原样。 | |
| ### 裁剪方法 | |
| 1. 完整的 `q4tp` 模型读取 89 677 个 token:32 768 个 Python 代码 token(Magicoder)、一个较长的编程任务(交互式 three.js 页面)及完整模型的回答,以及裁剪模型对该任务的回答。记录每个路由 FFN 的潜在输入、选择和权重(`cortiq hy4-sfq --capture-only`)。 | |
| 2. 每层计算每个专家在其被选中位置上的输出;保留能量 Σ(权重 · ‖输出‖)² 最大的 256 个专家。在留出的 token 上,这样丢失该层路由输出的 5.4 %,而按选择次数保留 256 个时为 8.6 %。 | |
| 3. `CMF_DEFRAG_ABSENT=1 cortiq moe-defrag --keep 256`:其余专家不写入文件,保留的专家保持编号,路由器及其选择偏置保持完整(`hy4-flash-fast-code.cmf`)。 | |
| 4. `cortiq requant --quant q4tp-dense`:将 8 比特的注意力、共享专家和潜在投影转为 4 比特(`hy4-flash-fast-code-q4.cmf`):这部分每个 token 读取的字节减半。 | |
| 为何保持路由器完整:普通裁剪让路由器只在保留的专家中选择,被删除专家的选择落到其他专家上,权重在其余专家间重新归一化。Hy4-flash 的专家无法互相替代(最佳替代专家重建被删除专家输出的效果比零还差),这对代码影响更大:同样 256 个专家的普通裁剪新代码困惑度为 9.75,本方法为 8.97。 | |
| ### 质量 | |
| | 模型 | 新代码 | Rust 源码 | HumanEval pass@1 | | |
| |---|---:|---:|---:| | |
| | `hy4-flash-fast-code-q4.cmf` | 9.63 | 4.43 | 92.7 % | | |
| | `hy4-flash-fast-code.cmf` | **8.97** | **4.22** | **93.3 %** | | |
| | 相同专家的普通裁剪 | 9.75 | 4.31 | — | | |
| | 完整 `q4tp`(512 专家) | 8.42 | 3.92 | 93.9 % | | |
| 困惑度:显卡提示图上 512 token 窗口,模型发布后编写的代码(16 个窗口),Rust 源码(8 个)。HumanEval:通过 `cortiq serve` 的 164 道题,贪婪解码,关闭思考。 | |
| **长代码**(`hy4-flash-fast-code.cmf`)。单个 HTML 页面的交互式 three.js 水族箱(6 400–8 900 token):4 次运行(贪婪解码和三个随机种子)中有 2 次生成了可运行的页面,完整模型为 6 次中 6 次。另外两次是语法正确的 JavaScript,但误用了 three.js(没有 importmap 的模块导入;引用了不存在的页面元素)。 | |
|  | |
| ### 速度 · RTX PRO 6000 | |
| 测试平台:NVIDIA RTX PRO 6000 Blackwell Server Edition(96 GB),48 个 CPU 核心,176 GB 内存,CUDA 后端(`CMF_GPU=cuda`),发布版构建。 | |
| `cortiq run --greedy --no-think`,1000 token 的 WikiText-2 提示后生成 256 token,文件已在页缓存中;`CMF_GPU_VRAM_MB` 限制显存;取两次运行的平均值(12 GB 为一次)。 | |
| | 限制(`CMF_GPU_VRAM_MB`) | `hy4-flash-fast-code-q4.cmf`,cortiq 0.9.8 | 完整模型(512 专家),cortiq 0.9.7 | | |
| |---:|---:|---:| | |
| | 96 GB(整卡) | **67.4** tok/s | 48.0 tok/s | | |
| | 24 GB | **49.5** | 11.9 | | |
| | 16 GB | **39.8** | 8.9 | | |
| | 12 GB | **32.6** | — | | |
| 24 GB 和 16 GB 限制下的差距部分来自主机:其页缓存能容纳 108.8 GB 的文件,但容纳不下 150.5 GB 的完整模型,而此时专家来自主机内存。完整模型未在 12 GB 限制下测量。 | |
|  | |
| ### 服务器 | |
| ```bash | |
| CMF_GPU=cuda cortiq serve hy4-flash-fast-code-q4.cmf --port 8080 --host 127.0.0.1 | |
| ``` | |
| 同一端口提供兼容 OpenAI 的 API(`/v1/chat/completions`、`/v1/completions`、流式输出)和网页控制台。 | |
| ### 许可证 | |
| 权重归腾讯所有,遵循 [Tencent Hy License](LICENSE)(本仓库附有副本)。这些文件为修改形式:转换为 CMF、量化,并按上述方法裁剪为每层 256 个路由专家。 | |