A clean-room HR-NAX inference engine in Rust and Metal for Inkling 2 Mini on Apple Silicon. It serves
paragonX/Inkling-2-Mini-HRNAX-N1 (hrnax-v3, near-lossless
native NVFP4/MXFP8 + BF16 attention) with text, vision, persistent disk prefix caching, and optional
incoai/Inkling-2-Mini-DFlash2 speculative decoding as one
static binary, hivengine.
- Model pack (
HRNAX-N1):paragonX/Inkling-2-Mini-HRNAX-N1(17.754 GiB,hrnax-v3,5.78 bpweffective): copies 95.3% of the official release's main weight bytes (98.2%of parameters,97.6%of this pack's bytes —1,243of1,244tensors) bit-for-bit unchanged fromthinkingmachines/Inkling-2-Mini— nativeNVFP4routed experts (L0–L19), nativeMXFP8routed experts (L20–L23), all 24 layers of nativeBF16attention,BF16embeddings & vision tower — quantizing onlymodel.llm.unembed(BF16 → T8,0.863 → 0.432 GiB) and omitting optionalmtp.safetensors. Defaults to FP32 KV + FP32 linear activations (99.88%top-1,0.000014nats KL vs exact FP32; Apache-2.0). - Optional drafter:
incoai/Inkling-2-Mini-DFlash2(0.923 GiB, 5-layer BF16 block drafter, placed in<pack>/dflash2/; Apache-2.0). - No weights are in this repository. Every Metal kernel, CPU oracle, packer, and offline quantization/evaluation tool
(
tools/hrnax/) is built from scratch.
Measured on paragonX/Inkling-2-Mini-HRNAX-N1 (hivengine 0.5.0,
9cb3deb) on Apple M5 Max (128 GiB) at 2 × 262,144 context (act=f32, DFlash2 speculative trees ON).
| Metric | kv=f32, act=f32 (default) |
kv=f16, act=f32 (--kv-dtype f16) |
|---|---|---|
Preflight bill / ready phys_footprint |
61.265 GiB / 57.57 GiB |
43.043 GiB / 39.19 GiB (-18.4 GiB) |
Agree vs PyTorch FP32 (868 pos) |
99.88% top-1 · 0.0000 KLD |
99.19% top-1 · 0.0010 KLD |
0-ULP chunk check (2048 vs 256) / row check |
0/288 diffs · 41/41 byte-equal |
0/288 diffs · 41/41 byte-equal |
Short decode (0K, DFlash2 ON, T=1.0 / T=0.0) |
100.8–129.0 / 127.9–140.9 tok/s |
92.3–96.5 / 126.1–139.1 tok/s |
Short 2-slot pair (2×1024, T=1.0) / plain (drafter=off) |
94.4 agg / 58.3–62.1 tok/s |
— / 57.7–64.4 tok/s |
Prefill (3.2K / 25.5K cold) |
1,998 / 1,828 tok/s |
— / 1,975 tok/s |
Prefill (64K / 128K / 196K cold) |
1,508 / 1,176 / 959 tok/s |
— / 1,376 / 1,151 tok/s (+20%) |
Decode @ 64K (1-slot / 2-slot) |
55.3–91.5 / 56.7 agg tok/s |
— |
Decode @ 128K (1-slot, T=1.0..T=0.0) |
45.4–66.9 tok/s |
— |
Decode @ 196K (think T=1,p=1 / p=.95 / code / greedy) |
42.8 / 47.1 / 44.1 / 58.0 tok/s |
51.6 / 69.8 / 48.9 / 70.6 tok/s |
Decode @ 196K (2-slot concurrent think T=1,p=1) |
43.2 agg (22.4 + 20.8 tok/s) |
— |
Deep-context Metal 4 stack (9cb3deb): packed-butterfly FP32 SIMD decode/tree attention (510 GB/s at r=1, 413 GB/s
at r=8, 2.5× faster sliding visits), slab-fused 32×128 4K-slab L2/SLC-resident NAX2 prefill (18.0 TF/s F32 /
25.9 TF/s 16-bit), native 1-plane half × half FP16 KV cache (taking advantage of Inkling 2 Mini's L2-clipped K and
gamma-free RMSNorm V for 8× finer precision than BF16 with zero overflow risk), lossless DFlash2 tree branching with
depth-scaled cost calibration, min-gap spread checkpoints (CKPT_KEEP=6), opportunistic per-slot disk prefix staging
while peer slots run, and depth-aware busy prefill slicing (1024 / 512 / 256).
Every figure below was measured on paragonX/Inkling-2-Mini-HRNAX-N1
on the 0.5.0 (c40bd09) release build over direct loopback at identical 2 × 131,072 context with
32-bit (F32) K/V store and F32 linear activations (43.825 GiB preflight bill before CKPT_KEEP=6). tok/s is the
median of 3 runs (1,024 generated tokens for decode, thinking tokens counted; T = 1.0 uses top_p = 0.95, top_k = 20).
| Workload | Apple M5 Max Mac Studio (128 GiB) | Apple M5 Pro MacBook Pro (20-GPU, 64 GiB) |
|---|---|---|
Shape (slots × ctx, KV / acts) |
2 × 131,072, kv=f32, act=f32 (43.825 GiB bill) |
2 × 131,072, kv=f32, act=f32 (43.825 GiB bill) |
| Boot (cold / warm cache) | 12.2 s (9.4 s upload + 2.52 s warm-up) |
17.3 s (4.1 s upload + 12.94 s warm-up; warm 5.9 s) |
Ready / post-25K phys_footprint |
39.93 GiB / 42.70 GiB |
39.84 GiB / 42.64 GiB |
Prefill (3.3K tokens) |
2,031.5 tok/s (1.626 s TTFT, dec 107.8) |
959.0 tok/s (3.443 s TTFT, dec 49.0) |
Prefill (25.5K tokens) |
1,753.6 tok/s (14.5 s TTFT, dec 72.3) |
812.6 tok/s (31.4 s TTFT, dec 50.7) |
1024² image TTFT / decode |
0.893 s TTFT (802.3 tok/s) / 101.5 tok/s decode |
1.791 s TTFT (400.3 tok/s) / 62.6 tok/s decode |
Short prompt TTFT (~53 tok) |
133–142 ms |
217–237 ms |
Plain decode (drafter=off, 1×32K, code / prose) |
50.9 / 50.9 tok/s |
36.3 / 35.6 tok/s (warm chassis) |
DFlash2 T = 0.0, code (1024 tok) |
126.1 tok/s (peak 140.9) |
83.0 tok/s (peak 83.1) |
DFlash2 T = 0.0, prose (1024 tok) |
107.0 tok/s (peak 117.9) |
70.0 tok/s (peak 73.4) |
DFlash2 T = 0.0, 2-stream pair (2×1024 tok) |
101.2 agg / 102.5 sum tok/s |
63.7 agg / 64.8 sum tok/s (peak 70.2 agg) |
DFlash2 T = 1.0, canary (3/3 pass) |
138.2 tok/s (peak 184.5) |
83.9 tok/s (peak 99.4) |
DFlash2 T = 1.0, code (1024 tok) |
127.5 tok/s (peak 128.7) |
73.2 tok/s (peak 83.6) |
DFlash2 T = 1.0, prose (1024 tok) |
97.2 tok/s (peak 106.2) |
58.9 tok/s (peak 65.0) |
DFlash2 T = 1.0, 2-stream pair (2×1024 tok) |
84.4 agg / 84.9 sum tok/s (peak 95.0 agg) |
55.6 agg / 58.2 sum tok/s |
Prefill (130.0K full ctx, W3) |
724.6 tok/s (179.4 s TTFT) |
— |
Disk prefix cache (4,428 tok restart) |
3.094 → 0.267 s (11.57× TTFT) |
5.827 → 0.334 s (17.42× TTFT) |
Metal 4 NAX prefill stack (hivengine 0.5.0): split-half×2 BF16 attention projections (30.9 eff TF), cooperative
4-SG NAX v2 FlashAttention (32×64 tiles, 8 KiB smem, multi-slab <=16K), fused NAX message gates and single-launch
fused NAX router+top-k, register-fused gate_up + softcap_swiglu -> mid (8 KiB smem, 0-ULP vs unfused), and
double-buffered MTLEvent-ordered visit pipelining — lifting 3.3K / 25.5K F32 prefill by +28.5% / +33.3% on M5
Max Studio (1,580.5 → 2,031.5, 1,315.9 → 1,753.6 tok/s) and +24.3% / +28.5% on M5 Pro MacBook Pro
(771.7 → 959.0, 632.5 → 812.6 tok/s) with zero weight changes.
Verified correctness on paragonX/Inkling-2-Mini-HRNAX-N1:
- Exact PyTorch FP32 agreement (
ei-v1-fp32/text,allow_tf32=False, 7 prompts / 868 positions):--kv-dtype f32 --act-dtype f32(default):99.88%top-1 (867/868, 6/7 prompts at100.00%incl.9,131-tokchat-long),100.00%top-5,0.0000overall KLD,0non-finite.--kv-dtype f16 --act-dtype f32:99.19%top-1,100.00%top-5,0.0010overall KLD,0non-finite (vs98.85%/0.0012KLD with--kv-dtype bf16 --act-dtype f16).- Both F32 and FP16 KV pass strict 0-ULP chunk check (
2048vs256,9,131rows:0/288state diffs), row check (1/2/7/15/16rows + side-branch:41/41byte-equal), and W4 lossless speculative identity (4/4PASS).
- Whole-model full-vocabulary evaluation (
test_256: 234 seqs / 173,971 tokens incl. multi-turn agent & tool traces):0.000014nats mean KL ([0.00001, 0.00002]),99.88%top-1. - Agreement with
mlx-lmBF16 reference captures (ei-v1):- W1 text (7/7 pass, 861 positions):
98.61%top-1,100.00%top-5,0.0016mean KLD. - W2 vision (3/3 pass, 360 positions):
99.17%top-1 (357/360),100.00%top-5,0.0007mean KLD,image-rows rel_rms 0.0187–0.0210. - Chunk invariance (
2048vs512text,2048vs16vision):0/288state diffs. Row invariance (1/2/7/15/16):41/41byte-equal.
- W1 text (7/7 pass, 861 positions):
- HTTP conformance (
2 × 131KF32 KV + DFlash2 + API key auth):16 of 16 PASS, including130,010-token full-context prompt at724.6 tok/s, peak memory41.33 GiB(42,322.4 MiB), cleanSIGTERMexit0. - Cross-machine disk prefix parity:
1,014.0 MiBF32 checkpoint restores across server restarts with identical output SHA-256 (3256073c...) and exact speculative trace (15rounds /48accepted) on both M5 Max and M5 Pro. - Loaded weights and K/V match the preflight memory bill to the byte.
Requires an Apple Silicon Mac (Apple M5 / Metal 4 NAX recommended) with Rust (cargo) and the Hugging Face CLI (hf).
hf download paragonX/Inkling-2-Mini-HRNAX-N1 --local-dir ./Inkling-2-Mini-HRNAX-N1
# Optional: download the DFlash2 speculative drafter into <pack>/dflash2/
hf download incoai/Inkling-2-Mini-DFlash2 --local-dir ./Inkling-2-Mini-HRNAX-N1/dflash2
# Verify pack checksums
(cd ./Inkling-2-Mini-HRNAX-N1 && shasum -a 256 -c SHA256SUMS.txt)cargo build --release -p serve --bin hivengineThe static binary is at target/release/hivengine.
target/release/hivengine preflight \
--model ./Inkling-2-Mini-HRNAX-N1 \
--ctx-size 131072 \
--slots 2 \
--max-resident-mem 48GBtarget/release/hivengine --serve \
--model ./Inkling-2-Mini-HRNAX-N1 \
--host 127.0.0.1 \
--port 18650 \
--ctx-size 131072 \
--max-concurrent 2 \
--max-resident-mem 48GB \
--prefix-cache-disk 8GBUseful flags:
--ctx-size <N>: maximum tokens per concurrent slot (up to262144).--max-concurrent <S>: number of concurrent request slots billed and allocated.--max-resident-mem <SIZE>: hard cap checked against the exact preflight memory bill before loading.--kv-dtype f32|f16|bf16(fp16accepted as alias forf16) and--act-dtype f32|f16:hrnax-v3BF16-attention packs (HRNAX-N1) default tof32KV andf32linear activations (99.88%top-1 vs FP32). Pass--kv-dtype f16for native FP16 KV (99.19%top-1 /0.0010KLD, cutting2 × 262Kbill from61.265to43.043 GiBand boosting196Kprefill/decode by+20%–+48%), or--kv-dtype bf16 --act-dtype f16for minimum memory.--prefix-cache-disk <N>GB/--prefix-cache-disk-dir <PATH>: CRC-32C verified persistent checkpoint cache on disk (default dir$HOME/.hivengine/prefix/v1-inkling).--no-drafter: disable DFlash2 even when<pack>/dflash2/is present (individual requests can also pass"enable_drafter": false).--api-key-env <VAR>: requireAuthorization: Bearer <token>using the secret in$VAR(required for non-loopback--host; optional on loopback).
# Health check
curl -s http://127.0.0.1:18650/health
# Prometheus metrics
curl -s http://127.0.0.1:18650/metrics
# Live dashboard: open http://127.0.0.1:18650/dashboard (data from GET /stats; see docs/dashboard.md)
# Chat completion
curl -s http://127.0.0.1:18650/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "Inkling-2-Mini-HRNAX-N1",
"messages": [{"role": "user", "content": "What is 19 * 23? Reply with just the number."}],
"temperature": 0.0,
"max_tokens": 128
}'PACK=./Inkling-2-Mini-HRNAX-N1
# Pack admission (header-only, zero weight reads)
target/release/hivengine admit "$PACK"
# Load verification (weights measured against the memory bill)
target/release/hivengine load --model "$PACK" --ctx-size 8192 --max-resident-mem 32GB
# Text and vision canaries
target/release/hivengine generate --model "$PACK" --canary --max-new 1024 \
--ctx-size 8192 --chunk 2048 --max-resident-mem 32GB
target/release/hivengine generate --model "$PACK" --canary \
--image fixtures/prompts/ei-v1/img-digits.png \
--max-new 256 --ctx-size 8192 --chunk 2048 --max-resident-mem 32GB- Text. Inkling 2 Mini's looped forward (24 layers, 48 visits, fused decode barriers, native
NVFP4/MXFP8andT4/T8routed MoE, nativeBF16andT8dense attention), greedy or sampled, built-in chat template, reasoning, schema-typed tool calls, andreasoning_effortas a word or a number0..0.99. - Images. OpenAI
image_urlparts asdata:URLs (PNG, JPEG, or WebP, byte-exact against Pillow);http(s)URLs are refused by name. - DFlash2 drafter. Automatically enabled when
<pack>/dflash2/is present and valid; absent, served without it; present and invalid, exit78. Verifies a tree of up to 16 rows (drafter candidates plus a prompt-lookup chain) and commits the accepted path while keeping every output token sampled from the target's logits. A per-request gate falls back to plain decoding when drafting does not pay. - Prefix reuse (in-slot and disk). Checkpoints taken during prefill (every 8,192 tokens, a pinned early anchor
before the first user turn, plus min-gap spread retention across
CKPT_KEEP=6slots) reuse shared prefixes byte-identically even after mid-history edits;--prefix-cache-diskstages idle slots opportunistically while peer slots run and persists checkpoints across restarts with CRC-32C verification and KV-dtype fingerprint isolation. - K/V & activation precision. Full 32-bit (
f32) K/V store with split hi+lo NAX attention and multi-plane FP32 prefill (default onHRNAX-N1), native 16-bit (f16) K/V store with 1-planehalf × halfNAX attention, andbf16K/V store + FP16 activations, selectable via--kv-dtypeand--act-dtype.
hivengine preflight prints every term before allocating GPU memory. For
paragonX/Inkling-2-Mini-HRNAX-N1 at 2 × 262,144,
act=f32, with DFlash2 present:
| term | kv=f32 (GiB) |
kv=f16 (GiB) |
notes |
|---|---|---|---|
weights.text |
17.167 |
17.167 |
native NVFP4 (L0–19), MXFP8 (L20–23), all-24 BF16 attn, BF16 embed, T8 head (exact to the byte) |
weights.vision |
0.596 |
0.596 |
native BF16 vision tower (exact to the byte) |
drafter.weights |
0.923 |
0.923 |
81 BF16 tensors |
kv.full + kv.rings + kv.tails + drafter.rings |
32.758 |
16.440 |
2 × 262,144 full KV (32.0 F32 / 16.0 F16) + 40 sliding rings + tails + drafter rings |
checkpoints |
4.320 |
2.416 |
2 slots × 6 min-gap checkpoints (0.360 F32 / 0.201 GiB F16 each) |
scratch + safety |
5.500 |
5.500 |
3.500 F32 text scratch + 1.000 vision scratch + 1.000 safety |
| total billed | 61.265 |
43.043 |
M5 Max ready phys_footprint: 57.57 GiB (f32) / 39.19 GiB (f16) |
Other common shapes on HRNAX-N1 (with DFlash2, CKPT_KEEP=6):
2 × 131,072,kv=f32, act=f32:45.265 GiBbilled (2 × 131,072,kv=f16, act=f32:35.043 GiBbilled).1 × 16,384,kv=f32, act=f32:27.726 GiBbilled (kv=f16, act=f32:26.115 GiBbilled).
| crate | job | GPU? |
|---|---|---|
safetensors-mmap |
Minimal mmap safetensors header & shard reader (Shard, Dtype, TensorMeta, PackError) and test shard writer. |
no |
hrnax-format |
Read and admit hrnax-v1 (INT4/INT8) and hrnax-v3 (native NVFP4/MXFP8 experts + BF16 attention) packs by mmap with exact tensor classification and memory billing. |
no |
hrnax-ref |
CPU reference decoder, Hadamard rotation, NVFP4/MXFP8 exact f64 decoders, and manifest oracle for hrnax-v1/v3 packs. |
no |
gpu-rt |
Minimal GPU runtime behind a Backend trait: buffers, pipeline cache, command batching with byte-range barrier tracking, memory accounting. Metal first (objc2-metal, shaders compiled at runtime). |
yes |
hrnax-kernels |
Clean-room Metal NAX/SIMD kernels for hrnax-v1 (T4/T8) and hrnax-v3 (native NVFP4/MXFP8 experts, exact BF16 attention, F32 decode/verify, multi-plane F32 prefill) plus microbench tests. |
yes |
ops |
Generic GPU operations, each with a CPU twin: matmul, norms, activations, conv1d, gather, depth attention, L2 clip, softcap, top-k, argmax, sort, cast. | yes |
model-common |
Shared model pieces: weight source, uploader, plain, BF16 & HR-NAX linears, sigmoid router, and fused router_topk_bucket planner. |
yes |
model-inkling2 |
Inkling 2 Mini: config pins, manifest, memory bill, the looped forward (fused decode barriers, message gates, relative-bias attention, short convs, HR-NAX/native MoE), BF16, F16 & F32 K/V stores, min-gap checkpoints, vision tower, and Pillow-exact image preprocessing. FP64 CPU twins. | yes |
dflash |
DFlash2 block drafter: admission of <pack>/dflash2/, CPU twin, GPU forward, readout and selector, draft tree, prompt lookup, per-request gate. |
yes |
chat |
GPU-free serving logic: request validation, Inkling 2 chat template via minijinja, caller-text marks, output state machine (reasoning, answer, schema-typed tool calls), sampler. |
no |
hrnax-eval |
Capture reader and writer (hivengine-capture-v1, torch-fp32 & mlx-lm), KLD / top-k / rel-RMS metrics, agreement verdicts. |
no |
serve |
hivengine: --serve (OpenAI-compatible HTTP on axum, scheduler & slots, persistent disk prefix cache, Prometheus metrics, graceful shutdown) and subcommands admit, preflight, load, generate, agree. |
yes |
tools/hrnax/ contains the stdlib-only hrnax-v3 native packer (tools/hrnax/native_pack.py, used to assemble
paragonX/Inkling-2-Mini-HRNAX-N1 byte-for-byte from thinkingmachines/Inkling-2-Mini with full SHA-256 provenance)
and the from-scratch Python offline PTQ, calibration, KL evaluation, layer-sensitivity planner, and Direct-STE QAD
toolkit. Core rotation, packing, and native decoders are cross-verified byte-for-byte against crates/hrnax-ref
(tools/hrnax/tests/test_oracle_parity.py). See tools/hrnax/README.md for CLI usage and
Colab notebooks.
./check.shRuns cargo fmt --check, cargo clippy -D warnings across all feature sets, Python unit suites (ei_bench,
e4_conformance, and tools/hrnax/tests), and the full Rust test suite including end-to-end toy hrnax-v1/v3 pack
preflight, load, generate, vision, disk prefix cache, DFlash2 drafted-vs-plain identity, FP32 Option A parity,
and HTTP conformance.
| doc | what |
|---|---|
docs/HRNAX-V3-format.md |
hrnax-v3 pack format specification (native NVFP4/MXFP8 experts + BF16 attention) |
docs/HRNAX-N0-gate.md |
Gate N0 native NVFP4/MXFP8 & BF16 attention silicon microbenchmark results on M5 Max |
docs/HRNAX-H0-gate.md |
Gate 0 silicon microbenchmark results on M5 Max (root-causing block-break exits) |
docs/HRNAX-H0b-gate.md |
Gate 0b per-row scaling (s[n]) + full-row Hadamard rotation silicon results on M5 Max |
docs/HRNAX-H1-ptq.md |
Offline PTQ calibration and sealed 256-context KL results on Inkling 2 Mini |
docs/inkling2-forward-notes.md |
Inkling 2 text forward verified line by line against mlx-lm |
docs/dflash2-notes.md |
Exact forward specification of Inkling-2-Mini-DFlash2 |
Licence: MIT (see LICENSE). Third-party credits are in NOTICE.