Inkling-2-Mini in 5.4 GB Memory
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
LookAtMyQuant is a quantization compiler. It measures how much each stored piece of a model hurts the output when compressed. It then picks a code for each piece so the whole model fits a size budget with the least damage.
LookAtMyQuant 是一个量化编译器。它会测量模型中每个存储部分在压缩后对输出造成的损害程度,然后为每个部分选择一种编码,以确保整个模型在满足大小预算的同时,将性能损失降至最低。
On Gemma 4 E2B, its GGUF has 12× lower KL than Q4_K_M at the same file size. The method and every result are on the site.
在 Gemma 4 E2B 上,其 GGUF 格式在相同文件大小下,KL 散度比 Q4_K_M 低 12 倍。该方法及所有结果均可在网站上查阅。
The code is under the MIT license.
该代码采用 MIT 许可证。
LookAtMyQuant 2 takes Qwen3.5-4B to 1.23 GB, 2.3 bits per weight. The file solves 330 of 540 exact-answer math problems. Prism ML’s Bonsai 2 Ternary 4B solves 328 at 1.20 GB, and the original solves 359. Its KL from the original on held-out text is 0.45 nats, against 0.59 for Bonsai.
LookAtMyQuant 2 将 Qwen3.5-4B 压缩至 1.23 GB,即每个权重 2.3 位。该文件能解决 540 道精确答案数学题中的 330 道。Prism ML 的 Bonsai 2 Ternary 4B 在 1.20 GB 大小下能解决 328 道,而原始模型能解决 359 道。其在留出文本集上与原始模型的 KL 散度为 0.45 nats,而 Bonsai 为 0.59 nats。
The recipe is post-training quantization with trellis codes, calibrated on the model’s own worked math solutions with digit tokens weighted 10×, and with bits allocated per row by Fisher information. 4,000 steps of distillation follow, in which every layer is re-quantized once from the original weights. The page has the findings, the full recipe and its cost, about $34 of GPU time.
其方案是使用网格编码(trellis codes)进行训练后量化,通过模型自身的数学解题过程进行校准,其中数字标记的权重被加权 10 倍,并根据 Fisher 信息量按行分配位数。随后进行 4,000 步蒸馏,期间每一层都从原始权重重新量化一次。网页中包含了研究结果、完整方案及其成本(约 34 美元的 GPU 时间)。
The recipe’s code is here, and the next section runs it. The 1.23 GB file itself is the lm2-qwen35-4b-1.2gb release, packed for the Apple Silicon runtime.
该方案的代码在此处,下一节将运行它。1.23 GB 的文件本身即为 lm2-qwen35-4b-1.2gb 版本,专为 Apple Silicon 运行时打包。
The same recipe takes Qwen3.8-27B from 53.7 GB to 7.2 GB, 2.1 bits per weight, calibrated and distilled on English prose and chat, code and math. The file solves 401 of the 540 math problems, as many as the original, and Unsloth’s UD-IQ2_XXS GGUF of the same size solves 348. It also scores above that GGUF on HumanEval (73.8% against 67.1%), MMLU (78.8% against 75.0%) and GSM8K (94.5% against 92.7%).
同样的方案将 Qwen3.8-27B 从 53.7 GB 压缩至 7.2 GB,即每个权重 2.1 位,并在英语散文、对话、代码和数学数据上进行了校准和蒸馏。该文件能解决 540 道数学题中的 401 道,与原始模型持平,而相同大小的 Unsloth UD-IQ2_XXS GGUF 能解决 348 道。它在 HumanEval(73.8% 对 67.1%)、MMLU(78.8% 对 75.0%)和 GSM8K(94.5% 对 92.7%)上的得分也高于该 GGUF。
Beside it sits a 4-bit DSpine drafter (1.02 GB, converted from tencent/Qwen3.8-27B-DSpine-b16 with runtime_mlx/convert_dspine.py and packed with pack_drafter.py), which roughly doubles decode speed on math and code on Apple silicon.
旁边还有一个 4 位的 DSpine 草稿模型(1.02 GB,通过 runtime_mlx/convert_dspine.py 从 tencent/Qwen3.8-27B-DSpine-b16 转换并使用 pack_drafter.py 打包),它在 Apple Silicon 上将数学和代码的解码速度提高了约一倍。
Extended to a 26.4B physical / 5.4B active 3×-looped MoE (L6–17 looped 3× = 48 logical visits, 128 experts top-8), the compiler and full-MoE proximal fine-tuning (SQYFR) compress thinkingmachines/Inkling-2-Mini from 18.89 GB of text weights into four Apple Silicon MLX builds: 5.38 GB (1.65 bpp), 8.87 GB (2.72 bpp), 11.18 GB (3.43 bpp), and 12.76 GB (3.92 bpp) — combining 4 KB SRAM hashed block-vector trellis codes (ht2/ht3), row trellis codes (rtr1/rtr4), a tr2 floor on the tail lm_head bucket (head.7), and exact native NVFP4 passthrough (69/192 and 109/192 highest-sensitivity expert buckets kept at 0.0 error in the 11.2 GB and 12.8 GB builds).
扩展至 26.4B 物理参数 / 5.4B 激活参数的 3 倍循环 MoE(L6–17 循环 3 次 = 48 次逻辑访问,128 个专家 top-8),该编译器和全 MoE 近端微调(SQYFR)将 thinkingmachines/Inkling-2-Mini 从 18.89 GB 的文本权重压缩为四个 Apple Silicon MLX 构建版本:5.38 GB (1.65 bpp)、8.87 GB (2.72 bpp)、11.18 GB (3.43 bpp) 和 12.76 GB (3.92 bpp) —— 结合了 4 KB SRAM 哈希块向量网格编码 (ht2/ht3)、行网格编码 (rtr1/rtr4)、尾部 lm_head 桶 (head.7) 上的 tr2 下限,以及精确的原生 NVFP4 直通(在 11.2 GB 和 12.8 GB 构建中,69/192 和 109/192 个最高敏感度专家桶保持 0.0 误差)。
Evaluated untruncated (max_new_tokens = 1,536, greedy, reasoning_effort=“none”) on the same BF16 teacher, openai/gsm8k (test[:200]), all 164 executable openai/openai_humaneval problems, 4 Vision VQA tests (with the untouched 637 MB BF16 vision tower), and 16+13-language TextMix windows:
在相同的 BF16 教师模型、openai/gsm8k (test[:200])、全部 164 个可执行的 openai/openai_humaneval 问题、4 个视觉 VQA 测试(使用未改动的 637 MB BF16 视觉塔)以及 16+13 语言的 TextMix 窗口上进行无截断评估(max_new_tokens = 1,536,贪婪搜索,reasoning_effort=“none”):
At 12.76 GB, Inkling-2-Mini-LookAtMyQuant-12.8GB matches 100.0% of the untouched BF16 teacher on every benchmark (349 / 349 pooled) in 32.5% less text weight memory. Both 11.18 GB and 8.87 GB retain 99.2–99.3% 3-task mean (345 / 349 = 98.9% pooled), with 8.87 GB cutting KL 2.34× on English/chat/code (0.0208 vs 0.0486) and 29.6% across all 13 languages (0.0571 vs 0.0811) below Unsloth’s 9.14 GB UD-Q2_K_XL GGUF, while 5.38 GB scores 88.0% GSM8K and 70.7% HumanEval (105/164 = 64.0% strict <|content_text|>; also beating 7.76 GB UD-IQ1_S and 9.14 GB UD-Q2_K_XL under an identical 384-token harness). All four run through lamq and runtime_mlx via unified single-launch Metal kernels (UnifiedMoESide mixing unrotated NVFP4 and Hadamard-rotated trellis experts across decode, speculative verify, and M5 MetalPerformancePrimitives prefill + FlashAttention-2 SDPA + exact unbiased temp > 0 speculative sampling), optionally paired with the 178.9 MB 4-bit DSpark drafters: on Apple M5 Max, 12.8 GB reaches 2,016 tok/s T=512 prefill, 60.5 tok/s serial, and 112.7 tok/s median lossless drafted decode (119.2 tok/s math, 106.2 tok/s code; 12.72 GB active RAM); 11.2 GB reaches 2,032 tok/s prefill, 62.4 tok/s serial, and 103.7 tok/s median (111.7 tok/s math; 11.13 GB active RAM); 8.9 GB decodes at 63.5 tok/s serial and 106.0 tok/s median (125.8 tok/s reasoning, 123.8 tok/s math; 9.41 GB active RAM); and 5.4 GB reaches 1,807 tok/s prefill, 75.3 tok/s serial, and 124.4 tok/s median (142.9 tok/s math, 126.5 tok/s reasoning, 122.2 tok/s code; 5.98 GB active RAM).
在 12.76 GB 时,Inkling-2-Mini-LookAtMyQuant-12.8GB 在所有基准测试中(汇总 349/349)均达到未改动 BF16 教师模型的 100.0% 水平,且文本权重内存减少了 32.5%。11.18 GB 和 8.87 GB 版本均保持了 99.2–99.3% 的 3 任务平均值(汇总 345/349 = 98.9%),其中 8.87 GB 在英语/对话/代码上的 KL 散度比 Unsloth 的 9.14 GB UD-Q2_K_XL GGUF 低 2.34 倍(0.0208 对 0.0486),在所有 13 种语言上低 29.6%(0.0571 对 0.0811);而 5.38 GB 版本在 GSM8K 上得分为 88.0%,在 HumanEval 上得分为 70.7%(105/164 = 64.0% 严格 <|content_text|>;在相同的 384-token 框架下也优于 7.76 GB UD-IQ1_S 和 9.14 GB UD-Q2_K_XL)。所有四个版本均通过 lamq 和 runtime_mlx 使用统一的单启动 Metal 内核运行(UnifiedMoESide 在解码、推测验证和 M5 MetalPerformancePrimitives 预填充 + FlashAttention-2 SDPA + 精确无偏 temp > 0 推测采样中混合了未旋转的 NVFP4 和 Hadamard 旋转的网格专家),并可选择搭配 178.9 MB 的 4 位 DSpark 草稿模型:在 Apple M5 Max 上,12.8 GB 版本达到 2,016 tok/s (T=512 预填充)、60.5 tok/s (串行) 和 112.7 tok/s (中位数无损草稿解码;119.2 tok/s 数学,106.2 tok/s 代码;12.72 GB 活动内存);11.2 GB 版本达到 2,032 tok/s 预填充、62.4 tok/s 串行和 103.7 tok/s 中位数(111.7 tok/s 数学;11.13 GB 活动内存);8.9 GB 版本以 63.5 tok/s 串行和 106.0 tok/s 中位数解码(125.8 tok/s 推理,123.8 tok/s 数学;9.41 GB 活动内存);5.4 GB 版本达到 1,807 tok/s 预填充、75.3 tok/s 串行和 124.4 tok/s 中位数(142.9 tok/s 数学,126.5 tok/s 推理,122.2 tok/s 代码;5.98 GB 活动内存)。
On Apple silicon, install the runtime package directly (this installs mlx, mlx-lm, numpy, and huggingface-hub without the PyTorch compiler dependencies):
在 Apple Silicon 上,直接安装运行时包(这将安装 mlx、mlx-lm、numpy 和 huggingface-hub,而无需 PyTorch 编译器依赖):
From a local clone, pip install -e . installs the lamq command, or run python -m runtime_mlx without installing.
从本地克隆中,使用 pip install -e . 安装 lamq 命令,或者在不安装的情况下运行 python -m runtime_mlx。
Command line. Pass either a local model folder or a Hugging Face repo ID:
命令行。传入本地模型文件夹或 Hugging Face 仓库 ID:
lamq generate reads stdin when -p is omitted, supports —raw, —system, —thinking, —temp, —mode linear|chat-fork|copy-wide, —no-adaptive, and —json. lamq info
当省略 -p 时,lamq generate 会读取标准输入,支持 —raw、—system、—thinking、—temp、—mode linear|chat-fork|copy-wide、—no-adaptive 和 —json。lamq info <model> 可在不加载权重的情况下检查打包模型的格式和维度。
Python integration. runtime_mlx.load returns an (model, tokenizer) pair compatible with mlx_lm.generate and mlx_lm.stream_generate (auto-detecting opgraph-packed-1 models such as Qwen3.5-4B / Qwen3.8-27B, inkling2-packed models such as Inkling-2-Mini, and lamq.json exports such as Gemma 4 E2B):
Python 集成。runtime_mlx.load 返回一个与 mlx_lm.generate 和 mlx_lm.stream_generate 兼容的 (model, tokenizer) 对(自动检测 opgraph-packed-1 模型,如 Qwen3.5-4B / Qwen3.8-27B;inkling2-packed 模型,如 Inkling-2-Mini;以及 lamq.json 导出文件,如 Gemma 4 E2B):
For streaming, multi-turn chat, or speculative decoding through one interface, use Runtime:
如需通过单一接口进行流式传输、多轮对话或推测解码,请使用 Runtime:
Install the dependencies and download the model and WikiText-2. The code reads SmolLM2-360M’s config when it starts, so do this first.
安装依赖项并下载模型和 WikiText-2。代码在启动时会读取 SmolLM2-360M 的配置,因此请先执行此操作。
Measure. This compresses one piece at a time, leaves the rest exact, and records the KL to the original model. The full set for this model, 2,312 measurements, took about 50 minutes on an L40S.
测量。此步骤每次压缩一个部分,其余部分保持精确,并记录与原始模型的 KL 散度。该模型全套 2,312 次测量在 L40S 上耗时约 50 分钟。
Allocate. This picks one code per piece, with the least summed KL inside the budget. It needs no GPU. This command uses the SmolLM2-360M measurements in this repository, with a budget of 3.044 bits per weight.
分配。此步骤为每个部分选择一种编码,以在预算内实现最小的 KL 散度总和。它不需要 GPU。此命令使用本仓库中的 SmolLM2-360M 测量数据,预算为每个权重 3.044 位。
The plan it writes has the same widths as results/compiler/plans/sm_lin_3044.json.
它写入的计划与 results/compiler/plans/sm_lin_3044.json 具有相同的宽度。
Build and score. This quantizes the model t
构建并评分。这将量化模型 t