Skip to content
paragontasxPublic

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

Ferro

Ferro

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 bpw effective): copies 95.3% of the official release's main weight bytes (98.2% of parameters, 97.6% of this pack's bytes — 1,243 of 1,244 tensors) bit-for-bit unchanged from thinkingmachines/Inkling-2-Mini — native NVFP4 routed experts (L0–L19), native MXFP8 routed experts (L20–L23), all 24 layers of native BF16 attention, BF16 embeddings & vision tower — quantizing only model.llm.unembed (BF16 → T8, 0.863 → 0.432 GiB) and omitting optional mtp.safetensors. Defaults to FP32 KV + FP32 linear activations (99.88% top-1, 0.000014 nats 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.

Numbers

HRNAX-N1 Long-Context & FP16 vs FP32 KV (2 × 262,144, M5 Max Studio, DFlash2 ON)

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).

Studio vs MacBook Pro Baseline (2 × 131,072 F32 KV + F32 acts, DFlash2 ON)

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 at 100.00% incl. 9,131-tok chat-long), 100.00% top-5, 0.0000 overall KLD, 0 non-finite.
    • --kv-dtype f16 --act-dtype f32: 99.19% top-1, 100.00% top-5, 0.0010 overall KLD, 0 non-finite (vs 98.85% / 0.0012 KLD with --kv-dtype bf16 --act-dtype f16).
    • Both F32 and FP16 KV pass strict 0-ULP chunk check (2048 vs 256, 9,131 rows: 0/288 state diffs), row check (1/2/7/15/16 rows + side-branch: 41/41 byte-equal), and W4 lossless speculative identity (4/4 PASS).
  • Whole-model full-vocabulary evaluation (test_256: 234 seqs / 173,971 tokens incl. multi-turn agent & tool traces): 0.000014 nats mean KL ([0.00001, 0.00002]), 99.88% top-1.
  • Agreement with mlx-lm BF16 reference captures (ei-v1):
    • W1 text (7/7 pass, 861 positions): 98.61% top-1, 100.00% top-5, 0.0016 mean KLD.
    • W2 vision (3/3 pass, 360 positions): 99.17% top-1 (357/360), 100.00% top-5, 0.0007 mean KLD, image-rows rel_rms 0.0187–0.0210.
    • Chunk invariance (2048 vs 512 text, 2048 vs 16 vision): 0/288 state diffs. Row invariance (1/2/7/15/16): 41/41 byte-equal.
  • HTTP conformance (2 × 131K F32 KV + DFlash2 + API key auth): 16 of 16 PASS, including 130,010-token full-context prompt at 724.6 tok/s, peak memory 41.33 GiB (42,322.4 MiB), clean SIGTERM exit 0.
  • Cross-machine disk prefix parity: 1,014.0 MiB F32 checkpoint restores across server restarts with identical output SHA-256 (3256073c...) and exact speculative trace (15 rounds / 48 accepted) on both M5 Max and M5 Pro.
  • Loaded weights and K/V match the preflight memory bill to the byte.

Deployment

Requires an Apple Silicon Mac (Apple M5 / Metal 4 NAX recommended) with Rust (cargo) and the Hugging Face CLI (hf).

1. Download the model pack (and optional DFlash2 drafter)

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)

2. Build hivengine

cargo build --release -p serve --bin hivengine

The static binary is at target/release/hivengine.

3. Preflight memory check (nothing loaded)

target/release/hivengine preflight \
  --model ./Inkling-2-Mini-HRNAX-N1 \
  --ctx-size 131072 \
  --slots 2 \
  --max-resident-mem 48GB

4. Start the OpenAI-compatible server

target/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 8GB

Useful flags:

  • --ctx-size <N>: maximum tokens per concurrent slot (up to 262144).
  • --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 (fp16 accepted as alias for f16) and --act-dtype f32|f16: hrnax-v3 BF16-attention packs (HRNAX-N1) default to f32 KV and f32 linear activations (99.88% top-1 vs FP32). Pass --kv-dtype f16 for native FP16 KV (99.19% top-1 / 0.0010 KLD, cutting 2 × 262K bill from 61.265 to 43.043 GiB and boosting 196K prefill/decode by +20%–+48%), or --kv-dtype bf16 --act-dtype f16 for 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>: require Authorization: Bearer <token> using the secret in $VAR (required for non-loopback --host; optional on loopback).

5. Query the server

# 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
  }'

Offline CLI commands

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

What is supported

  • Text. Inkling 2 Mini's looped forward (24 layers, 48 visits, fused decode barriers, native NVFP4/MXFP8 and T4/T8 routed MoE, native BF16 and T8 dense attention), greedy or sampled, built-in chat template, reasoning, schema-typed tool calls, and reasoning_effort as a word or a number 0..0.99.
  • Images. OpenAI image_url parts as data: 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, exit 78. 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=6 slots) reuse shared prefixes byte-identically even after mid-history edits; --prefix-cache-disk stages 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 on HRNAX-N1), native 16-bit (f16) K/V store with 1-plane half × half NAX attention, and bf16 K/V store + FP16 activations, selectable via --kv-dtype and --act-dtype.

The memory bill

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 GiB billed (2 × 131,072, kv=f16, act=f32: 35.043 GiB billed).
  • 1 × 16,384, kv=f32, act=f32: 27.726 GiB billed (kv=f16, act=f32: 26.115 GiB billed).

Crates

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

Offline Packer & PTQ/QAD Toolkit (tools/hrnax/)

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.

Development & verification

./check.sh

Runs 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.

Documents

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.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages