AI generated

Confident
Model stylome-1.2-large
stylo.me/be24826cfc679956

I've been using my Gemini subscription to help get the most out of my Macbook M2 Max 64gb and Neon seems to have hit it out of the park with integrating different approaches to this model. All of the kernel stuff is beyond me, I simply pointed it at different references for useful information. This may or may not be of interest to any Apple Silicon users >M2 and comes with No Warranties whatsoever. If I can't understand what the robot wrote I cannot give any guarantees. Let the slop begin. **Title:** Experimental MLX M1/M2 kernels + W4W8 quant for Inkling-2-Mini (500+ tok/s prefill, 30–43 tok/s decode, 512k NIAH in 38 GB on M2 Max) --- I put together a vibe-coded experimental set of MLX Metal kernels and a matching mixed-precision quant for **Inkling-2-Mini** specifically targeting **M1/M2 Macs** (tested on a 64 GB M2 Max). No guarantees or production claims here—just sharing the code, weights, and benchmarks in case they're useful to other M1/M2 users. - **GitHub (kernels, PR #2086 patch, CLI, offline KV cache, benchmarks):** https://github.com/ofnordo/inkling-2-mini-mlx-m1-2 - **Hugging Face (`5.52 bpw`, `18 GB`, bundled DSpark MTP):** https://huggingface.co/ofnordo/Inkling-2-Mini-MLX-W4W8 ### Why a separate quant + kernel pass for M1/M2 1. **Affine instead of NVFP4/MXFP8:** Inkling-2-Mini trains and ships natively in NVFP4 (layers `0..19` experts) and MXFP8 (last 4 readout layers `20..23`). M1/M2 has no hardware microscaling decode, so unpacking NVFP4/MXFP8 in software costs ~30–40% decode speed vs MLX's `affine` (`gs=64`) kernels. 2. **Keep the last 4 layers at 8-bit:** Uniform 4-bit (`W4A16`) gets trapped in thinking loops on long coding tasks (`0/12` on a 64k DAG workflow test), and crushing layers `20..23` to 4-bit drops accuracy (`10/12`). Mirroring the training split—`4-bit affine` on layers `0..19` experts, `8-bit affine` on layers `20..23` experts + attention/embed/`lm_head`, `FP32` on AttnRes/routers—recovers `12/12` in `18 GB`. 3. **FP16 activation path + fused kernels:** On M1/M2, recasting BF16 leaves to FP16 alongside fused Metal kernels (`short_conv`, `moe_short_conv`, `dynamic_conv`, `qkv_post`, Split-K relative attention) and projection fusion gives a large prefill and decode jump over base `mlx-lm` PR #2086 (`e2b5bbd`) and `oMLX 0.8.3`. 4. **Adaptive DSpark MTP + `SpeculativeRotatingKVCache`:** Adds 16 tokens of tail slack to the 40 sliding-window visits so MTP rollback stays capped instead of growing all 48 visits (cutting 512k MTP KV memory by 6x), plus an adaptive depth controller that backs off to `d=0` on high-entropy prose while staying speculative on code/tool JSON. ### Benchmarks (64 GB M2 Max) **Up to 32k context (256 generated tokens):** | Context | Base PR #2086 (`e2b5bbd`) | oMLX `0.8.3` (M1/M2 FP16, NVFP4) | **This (`W4W8` + FP16)** | | :--- | :--- | :--- | :--- | | `512` tok | `365 tok/s` pre / `25.9 tok/s` dec | `301 tok/s` pre / `24.0 tok/s` dec | **`549 tok/s` pre / `30.9` (`33.2` d=2) dec** | | `4,096` tok | `417 tok/s` pre / `26.7 tok/s` dec | `498 tok/s` pre / `21.0 tok/s` dec | **`603 tok/s` pre / `29.9` (`30.9` adapt) dec** | | `16,384` tok | `407 tok/s` pre / `25.2 tok/s` dec | `504 tok/s` pre / `20.5 tok/s` dec | **`543 tok/s` pre / `28.2 tok/s` dec** | | `32,768` tok | `374 tok/s` pre / `23.6 tok/s` dec | `466 tok/s` pre / `19.0 tok/s` dec | **`501 tok/s` pre / `26.1 tok/s` dec** (`21.2 GB` peak) | - **Coding / tool-calling (`Adaptive MTP d<=2`):** `37–48 tok/s` (`75–89%` acceptance). - **512k NIAH (`512,444` tokens, *The Man Who Was Thursday* + *The Count of Monte Cristo*):** `5/5` verbatim recall across 5%–95% depth, **`8.56 tok/s`** decode, **`37.99 GB` peak RAM** (`90.8 min` cold prefill; only 8 of the 48 visits are full-attention, so KV grows at `32 KB/tok`). - **Offline KV caching:** Included in `inkling_mlx.py` (`--build-cache` / `--cache`, 16-bit or 8-bit `.safetensors` including conv + drafter state, `<1 ms` in-memory branching). A 128k cache is `4.3 GB` (`2.3 GB` at 8-bit) and reloads in under a second. - **Capability checks:** `12/12` on a 64k one-shot DAG workflow engine test, `12/12` on a fictional-world tool-calling suite (including a 9-file refactor and 28.6k pure long-context log debugging with `0/116` malformed tool calls), plus clean one-shot Three.js and Web Audio apps. All converter scripts, benchmark harnesses, and the diff against PR #2086 are in the GitHub repo if anyone wants to test or pull pieces into upstream `mlx-lm`.