DOCS · START HERE

What did not work

Everything that was tried on the native runtime and not kept, every trap that cost time, and every target that was not reached, in one place, with the measurement that decided it. All on the Apple M4 Max 48 GiB unless stated. Each entry links the milestone document with the details.

Method behind every "no gain": the change passed the parity gates, then an A/B against the previous build (cooled runs, alternated in the same session) did not beat run-to-run noise or was slower. Reverted changes leave no code behind; their environment switches were removed with them.

Performance attempts that were reverted#

milestone attempt measurement why it failed (best understanding)
dev20 experts read in place from the mmap (RL_PREFILL_MAPPED_EXPERTS=1, still opt-in) numerically identical, 4–10× slower prefill Metal re-established residency of each layer's ~350 MB expert window for every command buffer (~3.3 s per 48-layer chunk). Not re-tried since dev30's residency set (DEV20)
dev20 batched expert kernel layouts: 8-pair register tile / adaptive 4-2-1 tiles / 4-row tile / grid over pairs 981 / 370 / 295 / 256 ms vs 312 baseline (96-token chunk) padding waste and load imbalance between experts; kept: slices of 4 pairs (DEV20)
dev22 fewer Metal encoders alone (≈1 200 → 1 per token) +1.9 % (57.6 → 58.7 tok/s) encoder boundaries are cheap on this GPU; the time is inside kernels (DEV22)
dev23 spin-waiting on MTLCommandBuffer.status instead of waitUntilCompleted 4 GiB decode 44.6 → 27.5 tok/s polling contends with the driver's completion path (DEV23)
dev23 per-layer early-out as the only 4 GiB decode path 8.3 tok/s 45–87 % of tokens miss in every layer; no always-hit layers to chain (DEV23)
dev23 periodic probing (32 synchronous tokens, then one GPU-routed try) 39.5 tok/s vs 44+ probes cost more than they gain; replaced by the load-free-token rule
dev26 split-K decode attention at every length short context 68.47 vs 70.20 tok/s one block has the single-threadgroup kernel's parallelism plus a merge dispatch; split only above 256 positions (DEV26)
dev30 router selection on the GPU (batched rl_route arithmetic) prefill 1100: median 571 vs 567 tok/s (runs 571/482/614 vs 577/567/513) the CPU step fell 70–115 → 45 ms, but the gain is inside run-to-run spread (DEV30)
dev30 matrix expert kernels: skip the empty 8-pair block of small slices variable loop bound: experts 1 729 ms (accumulators spilled); constant bound + break: 901 ms vs 750–850 the extra branch and register pressure cost more than the saved MACs (DEV30)
dev30 matrix expert kernels: split accumulators summed through threadgroup memory experts 966 vs 777 ms 26 KB of threadgroup memory per group cut occupancy; kept: summed in registers with an exact x·I + y (DEV30)
dev33 IQ codebooks staged in threadgroup memory, 256-thread GEMV groups (what llama.cpp does) IQ2_S 35.7 vs 33.2 µs, IQ3_XXS 38.2 vs 37.9 µs divergent constant-memory reads were not the bound once the GPU was warm (DEV33)
dev33 uchar4 codebook loads in the IQ2_XXS dense GEMV 25.6 / 27.5 vs 27.3 / 25.1 µs not the bound; the IQ2_XXS GEMV stays at ~169 GB/s (DEV33)
dev36 IQ2_XXS dense GEMV with two rows per lane (one activation load serves both rows) 25.4 vs 25.5 µs (8192 × 2048, warm kernel-bench) third attempt on this kernel without gain; activation loads are not the bound. The IQ2_XXS dense GEMV stays at ~169 GB/s
dev37 smarter expert replacement than LRU (simulated on routing traces, 4 GiB): decayed frequency (the Mira-style score), segmented LRU best 60.9 vs 64.1 misses/token (−5 %); long half-lives and a 95 % protected segment are worse than LRU decode routing is recency-dominated; the real waste was slot padding, fixed instead (dev37)
dev38 two more concurrent-encoder groups ({ssm_out, conv-state copy}, {layer-output copy, next RMSNorm}) 83.72 vs 83.77 tok/s the removed barriers were not on the critical path
dev38 (bound, not a change) concurrent decode encoder with no barriers at all 74 → 118 tok/s, wrong output most dispatches depend on the previous one; the kept version gains 2–6 %
dev39 expert tail + next RMSNorm in one single-threadgroup kernel (−3 barriers per layer) 79.1 vs 84.4 tok/s (5 pairs) the 10-expert weighted sum on one GPU core costs more than the barriers; the parallel tail without the RMSNorm is kept (+1.6 %)
dev40 prefill expert tiles of 32 (expert, token) pairs instead of 16 (each 32-row weight tile decoded once for twice the pairs), 128 threads with doubled per-thread accumulators IQ3_XXS 1100 / 8192 tokens 400 / 404 vs 872 / 914 tok/s, bit-identical logits register spills
dev40 same with 256 threads (simdgroups 0-3 pairs 0-15, 4-7 pairs 16-31, per-thread work unchanged) 1100: 886.5 / 866.2 / 878.0 vs 875.4 / 874.8 / 726.1; 8192: 921.6 / 906.8 / 909.2 vs 914.0 / 914.8 / 901.7 (medians 878.0 vs 874.8, 909.2 vs 914.0), bit-identical re-decoding weights per 16-pair slice is not the prefill bound at these sizes
dev41 decode expert kernels (gate/up, down) in threadgroups of 64 / 128 / 256 threads instead of 32 80.97 / 80.80-81.30 / 80.74-80.93 vs 81.30 / 81.51 tok/s (IQ2_XXS, full residency, two passes) scheduling of the 5120-20480 one-row groups is not the bound
dev50 32-pair prefill expert tiles, 256 threads, simdgroups 4-7 skip empty pairs (bit-identical) experts 4.21 vs 3.97 s (M4 Max, 8192 tokens) the halved decode per pair did not pay for the larger threadgroup
dev50 32-pair tiles, 128 threads, two partial accumulators (register count of the 16-pair kernel); with outputs aliased on the weight tiles; with the branch unrolled; without the empty-pair skip experts 6.87 / 8.01 / 8.00 / 9.57 vs 3.86 s on this GPU 32-pair tiles lose with every accumulator layout tried (dev40 too); cause not understood
dev45 relying on the compiler to share the weight decode between two dot calls (2-row verify) 1.74x one vector instead of ~1.06x not shared; explicit two-vector functions are used
dev45b MTP draft through the trunk's Q5_K head instead of the MTP file's Q8_0 head draft 1.56 → 1.51 ms, decode +0.3-0.8 % inside noise; the head is not the draft's bound
dev35 grouped decode attention, 4 threads per position for the scores attention 175 vs 165 ms per 64 tokens at ~8400 positions more threads per row did not add memory parallelism that mattered
dev35 grouped decode attention with blocks of 256 / 64 / 32 positions 164 / 146 / 180 ms vs 113 ms with 128 256: too few threadgroups (66); 64 and 32: more merge work and shorter loops (DEV35)
  • Decode kernel attempts that did not pay (dev74, M4 Max, CF2, alternated pairs). dev74 kept six decode changes (see DEV74); these were measured and reverted:

    • rl_route as one barrier-free SIMD group (the profiler gave the router 7–8 % of a token): decode 82.7 against 82.6 tok/s. The profiler inflates tiny kernels; the selection was never on the critical path.
    • IQ2_XS signs as an XOR of the float sign bit (with or without reading the shared scale byte once): the decode expert bench went from 2.8 to 3.6–4.1 ms. A select of ±1 followed by a multiply is cheaper on this GPU, probably because negation is a free operand modifier.
    • IQ1_M grid as a half table (exact: values −1, 0, 1, no int8 → float conversions): 2.65 → 3.09 ms. The 32 KB table misses the cache where the 16 KB int8 table does not.
    • Grids in the constant address space (as llama.cpp's program-scope tables): no change (2.65 against 2.64 ms).
    • x read once for four dot products (gate and up of two rows per lane group): 2.65 against 2.63 ms. The activation reads are not what limits the expert kernels.
    • One block type compiled into the kernel (IQ1_M only, no IQ2_XS / IQ3 paths): no change. The 156 registers do not come from the unused decoders.
    • Q4_K GEMV with four rows per SIMD group (x chunk and its sums read once for four rows): qkv 30 → 34 µs, gate 15 → 20 µs. A quarter of the SIMD groups hides less latency.
    • Q4_K GEMV with 16 or 8 lanes per row instead of 32: within ±1 µs.
    • Threadgroups of 64–256 threads for the GEMV and expert dispatches (all are 32): no change for the GEMVs, 1–5 % slower for the experts. The kernels do not run out of threadgroup slots.
    • Half KV, wider loads in the decode attention (16 contiguous bytes per lane for keys, half2 values): 4.6 → 4.8–5.0 ms at 64K in kernel-bench. The half-cache kernel reads about 350 GB/s against 480 for float; that gap is left.
    • Measured on the way: a dependent dispatch costs about 1.7 µs of decode time (8 extra trivial stages per DeltaNet layer: +0.48 ms per token), and an expert call (gate/up, down, sum) about 15 µs of fill and drain on top of its weights (12 calls of 40 experts against 48 of 10: 2.05 against 2.6 ms). Experts reach about 160 GB/s.
  • Prefill attempts (dev74, M4 Max, CF2, alternated).

    • Dense GEMM with weight tiles first in the grid (consecutive threadgroups sharing a weight tile): 880 against 899 tok/s on a 1.4K prompt. The 64 MB dequantized weight is not re-read from DRAM as feared.
    • Dense GEMM with 64 × 64 tiles (each SIMD group 32 × 32, 16 accumulators): 2.0 against 10.4 TFLOPS in the new prefill-gemm-bench, prompt ingestion 383 against 899 tok/s. rl_gemm_tg already runs at 64 % of the float32 peak.
    • The DeltaNet recurrence loading token t+1's inputs while token t computes: 944 against 945 tok/s.
  • dev75, M4 Max, CF2.

    • IQ2_XS decoded two groups at a time in the batched expert matrix kernels, in the same pipeline variant as IQ1_M: IQ2_XS layers 19.97 → 19.75 ms, IQ1_M layers 18.88 → 19.98 ms (the second decoder cost registers). A third, IQ2_XS-only pipeline was not worth 1 %.
    • The paired remap for every type, before it became a function-constant variant: IQ2_XS layers 20.07 → 20.5–21.1 ms.
    • 8 gate/up lanes per decode row: decode expert bench 2.50 ms against 2.38 (32 lanes) and 2.27 (16, kept).
    • Gate and up as two passes over 32-pair slices (each decoded weight tile serves twice the pairs, still 16 accumulators per simdgroup, bit-identical by construction): IQ1_M layer 18.89 → 20.95 ms, IQ2_XS layer 19.97 → 20.84 ms. With about 40 pairs per expert per 2048-token chunk, a 32-pair slice leaves an 8-pair one whose tile wastes three quarters of its matrix work; halving the decode per pair does not pay for that. Fifth layout of larger expert tiles that loses (dev40, dev50, dev69, dev72).
  • dev77, short prefill chunks on the quantized row kernel (rl_rowsb_* instead of dequantize + GEMM): dense stage 60 → 23 ms at 8 tokens, but 61 → 103 ms at 32, 72 → 233 at 64 and 95 → 507 at 128. Short chunks are 6 % of an agent session's prefill time; not kept.

  • dev77, a 128K agent window: no compactions, but longer sessions, slower decode and 9 / 12 tasks against 11 / 12 at 64K in two runs each. The default stays 64K (DEV77).

  • dev78, the next layer's dense part encoded while the CPU waits for the GPU (synchronous decode with a bounded expert cache; committed after the layer's experts, so the GPU order and the output are unchanged): 57.3 against 57.0 tok/s (CF2, 4 GiB cache, M4 Max, three pairs). CPU encoding is not on the critical path. On the 48 GiB M4 Max the "SSD" expert reads of repeated runs come from the macOS file cache (37 tok/s on the first run, 57 after), so the bounded path has to be studied on the 24 GiB M4 Pro.

  • dev78, the bounded-cache decode in one command buffer with an event hand-off per layer (commit 0c1ddf0, reverted; RL_ENGINE_EVENTS=1). Measured on the 24 GiB M4 Pro, CF2, 2026-10-09.

    • Where the bounded path's time goes. With every expert resident:

      • GPU-routed decode: 16.7 ms per token;
      • the synchronous path (forced): 24.1 ms. Its 48 commit-and-wait round trips cost 7.4 ms per token.
      • With the 4 GiB cache, 27.4 ms.
    • The idea. After each layer's rl_route the GPU signals an MTLSharedEvent and waits. The CPU, spinning on the event:

      • loads the layer's missing experts and writes their slot addresses into the plan;
      • prefetches the next layer's predicted experts;
      • releases the GPU, which waits for the prefetch to end before its next selection, so the residency table never changes under rl_route.
    • Correctness. Greedy output was identical to the synchronous path and to full residency.

    • What it saved. A model-free test measured one hand-off at 75 µs against 100–120 µs for a commit and a wait. With every expert resident the event path took 20.4–20.7 ms per token, 3.5 ms less than the synchronous path.

    • What it cost. On the six prompts of small_mac_ab.sh (median decode, alternated twice):

      Cache Synchronous Events
      4 GiB 37.8 / 37.4 tok/s 36.6 / 33.3 tok/s
      12 GiB 35.8 / 35.4 tok/s 32.0 / 31.7 tok/s

      Only one prompt gained (+11 %). Expert misses were identical.

    • Why. The expert reads cost the event path more than the synchronous one. A hand-off that follows a long CPU load costs ~150 µs (the GPU idles inside the command buffer), more than a commit and a wait. Without the prefetch the reads were fully exposed (28.6 against 32.3 tok/s).

    • What would be needed. A pool that loads experts without touching the residency table until the next hand-off, so that the prefetch need not stop the GPU. dev79 tried it (next entry): the wait was not the problem.

  • dev79, variants of the dev78 event decode (commit b7d8571, reverted). Measured on the 24 GiB M4 Pro, CF2, 4 GiB cache, 2026-10-09, prompt 2 of cache_trace_prompts.txt, 256 tokens, alternated with 25 s of cooling. The synchronous path did 38.0–38.1 tok/s.

    • The variants:

      Variant tok/s
      dev78: the GPU waits for the prefetch before its next selection 35.6–36.7
      No wait; the LRU never evicts the predicted layer's experts during the prefetch (protect_layer) 29.3–30.0
      Only the encoder boundary of that wait 29.3–29.9
      A wait on an event value already reached 34.2–34.4
      One hand-off per layer: misses and prefetch both while the GPU waits 23.0–23.3
      dev78 with a yield in the CPU spin 35.9–36.6
      dev78 with RL_POOL_NOCACHE=1 35.5

      Every variant gave greedy output identical to the synchronous path, with the same misses.

    • The per-token split (timers in the CPU loop, dev78 variant):

      • waiting for the GPU: 19.5 ms;
      • hand-off (misses loaded, slots patched): 1.3 ms;
      • prefetch: 3.2 ms;
      • encoding the token before the commit: 0.6 ms;
      • after the last hand-off: 1.6 ms.

      In the other variants the CPU work was the same, but the GPU took longer between two hand-offs: 25.4 ms without the wait, 34 ms with a single hand-off. That is about 0.7 ms per layer against 0.4, for the same kernels.

    • Reading. The GPU runs the same kernels more slowly when it has waited longer, or when it ran during the CPU's expert reads. A clock that drops while the GPU idles would explain it; Metal exposes no control over it.

    • A GPU-side conditional wait (a kernel that spins on a shared-memory flag only after a miss) does not work:

      • in a model-free test, the CPU never saw the GPU's flag before the end of the command buffer (6 of 6 layers);
      • CPU writes to expert slots are guaranteed visible to the GPU only after an event wait, not after a flag.
    • A separate read thread was not tried. The pool is single-threaded, so the next hand-off would wait for the prefetch anyway.

    • The best variant (dev78 kind, RL_ENGINE_EVENTS=3) on the six prompts (median decode, sync / events / events / sync, 25 s of cooling):

      Cache Synchronous Events
      4 GiB 37.4 / 37.4 tok/s 34.7 / 34.6 tok/s (−7 %)
      12 GiB 36.0 / 35.5 tok/s 32.3 / 32.0 tok/s (−10 %)

      One prompt of six gains (41.7–41.9 against 38.7–38.8 tok/s); the others lose up to 17 %.

    • With every expert resident the event path is not used: decode-bench gave 59.9 tok/s with and without the variable (two pairs).

  • dev80, three rewrites of the prefill attention for long contexts (attn_fa_b2; M4 Max, CF2, prefill-kernel-bench, 512 tokens, one attention layer).

    • Why attention matters here. At position 0 attention takes 2.0 ms against 16.9 ms of routed experts per layer. At 8K it is 19.4 against 20.0, and at 32K 48.7 against 15.4. With 12 attention layers and 48 expert layers, attention is about 44 % of the prefill at 32K, the contexts coding agents work at.

    • Not memory-bound. The kernel runs at ~6 TFLOPS. The half-precision KV cache (RL_KV_F16=1) changed 32K only from 42.5 to 41.1 ms.

    • The variants:

      Variant 32K 8K
      attn_fa_b2 (kept) 42.2–44.3 ms 17.0–22.0 ms
      Query rows read from device memory instead of a 16 KiB threadgroup copy (more threadgroups per core) 46.6–50.9 ms 18.0 ms
      No rescale product when no row's maximum moves (bit-identical) 42.2 ms 18.4 ms
      64-position key blocks, 16 × 16 score blocks per simdgroup (half the barriers and softmax passes per key) 44.8–48.8 ms 17.5–21.7 ms

      The variants were alternated in pairs with 15 s of cooling, and back-to-back runs vary by up to 25 % at 8K.

    • The GPU counters (dev83). A model-free capture (prefill-attn-bench 512 32768, M4 Max, Xcode profiler, full mode) gave:

      • F32 limiter 76 % (utilization 62 %) and instruction throughput limiter 70 %;
      • kernel occupancy 18 %, with the L1 94 % full (42 % threadgroup memory, 49 % buffer data);
      • last-level cache limiter 16 % and MMU limiter 29 %.

      The kernel is bound by the float32 ALUs, which is why the half KV cache did not speed it up.

    • Half operands in the matrix products (dev83, attn_fa_b5, half KV cache only). Half query, key, probability and value tiles with float accumulation (simdgroup_half8x8 operands, simdgroup_float8x8 accumulators) made the kernel three times slower: 97–102 ms against 31–32 ms at 32K, and 22–24 against 7.7 ms at 8K. On the M4 Max, mixed products are evidently not native. The float kernel, which already converts the half cache on load, stays.

    • What is left. Only the work besides the products, at most about 10 %:

      • the diagonal rescale product (16 of 144 products per key block);
      • the softmax exponentials.

      A faster prefill attention than MLX's would need fewer float32 operations, not a different layout.

  • dev81, the half-cache decode attention:

    • 16-byte key loads (eight halves per load, as float4 for the float cache) took 5.95 against 5.52 ms at 32K (M4 Pro, kernel-bench).
    • Sixteen value loads in flight took 4.94 against 4.74 ms with eight.
    • Eight value loads in flight were kept (REDLITE_DEV80_24GB_LONG_CONTEXT.md, section 5).

Correctness traps (found, fixed or guarded)#

  • redlite-engine tokenize --text output is not just ids (dev81). It prints at most 16,384 ids on its first line, then one line per token with its id and its text. Taking every number in that output built a 34K-token text whose second half repeated the first. A KV-cache comparison on it gave perplexity 1.06 and meaningless agreement. Read only the first line, and tokenize texts longer than 16K tokens in pieces.

  • Single accumulator in the matrix expert kernel (dev30). Rounding along the 2048-column reduction flipped an argmax at position 1135 of the long-context check (two logits 0.012 apart, after the documented router near-tie at 1035). Fixed with four partial accumulators; the gate caught it before commit.

  • A stale dump passed a parity check (dev24). quick_parity.sh compared an old file after a crash; the script now deletes its outputs first. In dev26 compare_dumps.py was found to accept an empty native dump; it now needs equal, non-zero token counts.

  • Silent truncation (dev26). redlite-engine --tokens cut lists at 4 096 ids; now 65 536 and longer lists are rejected.

  • The 8192-position logit bound (dev30). The 4.0 max-logit bound set in dev26 from a 4096-position measurement is below the native self-consistency floor at 8192: the 0.3.0 binary's own token-by-token path differs by 4.29 from llama.cpp and 4.45 from its batched prefill there. The bound is 5.0 at ≥ 8192 positions; argmax and KL gates did not change.

  • The logits CLI default chunk (dev30). Without --batch it ran token by token, so a "default chunk" parity run silently tested another path. It now uses the engine's chunk.

  • Benchmark artifacts. GPU clock ramp: the first kernel-bench numbers were 2–3× off until a warm-up pass was added (dev33). Thermal state: the same binary measured 64.7–71 tok/s at different hours of one night, and back-to-back prefill runs throttled to a third of the speed (dev24): only cooled, alternated, same-session A/B numbers are compared.

  • Page cache state. 4 GiB-cache numbers depend on whether the GGUF is still cached: after runs that allocate 22–29 GiB of expert slots, the first 4 GiB run read from SSD (IQ3_XXS 8192 tokens: 169 vs ~600 tok/s). bench_m4.sh warms up before 4 GiB prefill runs.

  • Ad-hoc parity token lists (dev39). redlite-engine parity --tokens 9707,11,1879,0,785,12884,13,151645,198 --cache-mib 2048 fails at position 7 with a 2-id router mismatch and ~1e-5 logit errors, identically with the dev37 engine: a router near-tie on that sequence. Use the regression token lists.

  • redlite-engine prefill on long IQ3_XXS sequences (dev39) reports BATCHED PREFILL PARITY: NO at 1100 tokens (worst 0.027, 0 router mismatches, same argmax; dev37: 0.040). Its bound is sized for short sequences; the long-context check against llama.cpp is the gate.

  • Shared GPU (dev39). With other applications using the GPU, the same binary measured 30–45 tok/s decode and 335 tok/s prefill (instead of ~85 and ~800). Pairs run in such a window are excluded.

  • A stale binary in a release benchmark (0.4.1). After reverting the dev40 kernels in the source, .deps/redmetal was not rebuilt, and the first 0.4.1 table was measured on the experimental build (IQ2_XXS prefill 854.3 / 858.3 tok/s instead of 0.4.0's 891.9 / 926.9). The table was re-measured after rm -rf .deps/redmetal and a clean build. Rule: rebuild from a clean tree before any benchmark that goes into a record.

  • Battery power (dev47). On battery at 6 % the same binary decoded at 32 tok/s instead of ~81 and a 33.5K-token prompt took 17 minutes; every measurement of that window was discarded. pmset -g batt before benchmarks.

  • The token-by-token llama.cpp oracle at long positions (dev47). redlite-ref-llama logits dumps every position one decode at a time: 16K positions took about 2 hours, 32K would take about 5 and 60K 9. The 32K / 60K comparisons were not run.

  • The llama.cpp oracle on 24 GiB (dev47). redlite-ref-llama puts the whole 18 GiB model on Metal and fails with kIOGPUCommandBufferCallbackErrorOutOfMemory on the M4 Pro. Correctness there is shown by bit-identity with the M4 Max's native outputs.

  • Command Line Tools with an SDK newer than their linker (dev47). On the M4 Pro (CLT 26.6, ld-1267) the MacOSX27 SDK's .tbd files read as "unknown architecture arm64e.x1"; REDLITE_SDK points the builds at MacOSX26.5.

  • Chunk-parallel DeltaNet prefill (dev44): not built. Measured ceiling: the recurrence is at most 6.7 % of an 8387-token prefill, so the published 1.3–1.45× would give about 2 %.

  • Float16 KV cache (dev53): built, measured, not kept. Every Metal attention kernel was switched to float16 storage (attn_fa_b with simdgroup_half8x8 K/V tiles, mixed-precision multiply-accumulate), and the CPU oracle rounded K/V to float16 (identical to the hardware conversion on 4.3 M bit patterns). Model-free self-test, quick_parity.sh IQ2_XXS and the 4K/8K/16K comparisons with llama.cpp passed. The median KL vs llama.cpp was slightly better (16K: 6.9e-9 vs 9.0e-9); single-logit outliers moved (16K: 9.66 vs 6.21, at positions with KL ~1e-7).

    • Gain: half the KV memory (64K context: footprint 21,567 → 20,030 MiB on the M4 Max). On the M4 Pro 24 GiB with every expert resident, MTP + a 32K context fit only with float16 (20.4 GiB; float32 ran out of GPU memory). But MTP there decoded 32.6 tok/s against 37.2 without it, and float32 without MTP already fit (19.9 GiB).
    • No speed gain: M4 Max 33.5K-token prompt, decode 56.1 / 56.8 vs 54.5 / 57.4 tok/s; prefill 465* / 620 vs 566 / 587 tok/s (*disturbed run).
    • Gates failed:
      • engine.parity.steered: 2 router id mismatches CPU vs Metal; logits 1.5e-4 vs 5.7e-6. The unsteered parity passed but its logits diff rose from ~1.5e-5 to 1.0e-4.
      • IQ3_XXS: prefill.parity.96 (6 router mismatches), and logits.long_context_vs_llama / long_context_full_residency (argmax disagreement; KL 2.9e-3 within its bound).
    • Why: CPU (double) and Metal (float) compute nearly equal K/V values. Float16 storage turns a tiny difference that straddles a rounding boundary into one float16 step (~1e-3 relative). Next to the router near-ties of these fixtures, that flips expert choices. A CPU/Metal router divergence is a hard failure, and the gain is memory alone, so it was reverted.
  • The Qwen API as a greedy reference (dev48). temperature: 0 alone gave a different text in one run of three; top_k: 1 is needed. Its logprobs are misaligned: the chosen token was missing from its own top 5 at 23 of 30 positions. Only text is compared.

  • A first single run overstated a gain (dev49). The vectorized expert decode measured −10 % expert time in one run against an earlier baseline run (4.40 → 3.94 s); alternated pairs gave −3.4 % (4.105 → 3.968 s). The baseline had been measured in a hotter state. Only alternated pairs are reported.

  • Removing the multiplications to bound a kernel (dev49). With the simdgroup MACs deleted, the expert time fell to 266 ms because the compiler also dropped the now-unused weight decode. Only the "decode replaced by constants" variant (2.45 s of 4.40 s) is a valid bound.

  • Steering doses (dev52). A difference-of-means vector at strength 1 over 16 layers, or 0.6+ over 8 layers, breaks the text into repeated tokens: the vector (|v| 4.35) is added at every steered layer, against a residual norm of about 10. Usable doses were 0.2–0.5 over 8–12 layers.

  • Two GPU jobs at once (dev54). An API comparison at full residency (17 GiB) started while llama-perplexity held another 19 GB file on the GPU. Request 8 failed with kIOGPUCommandBufferCallbackErrorOutOfMemory. GPU-heavy runs are chained, never overlapped.

  • The pinned llama.cpp's IQ2_XXS recipe is not Bartowski's (dev54). It makes IQ2_XXS experts (not runnable in the engine) and Q4_K attention. Custom mixes copy every tensor type from Bartowski's file (scripts/dev/quant_mix.py --like).

  • Expert mixes that did not help (dev54). IQ2_XS down projections on every layer with IQ1_M gate/up: +3 % size and perplexity 16.423 vs 16.370 (t = +1.13), and the engine cannot run it (type word 0x111d). Keeping layers 0–2 precise (E3b): no measurable gain (t = −1.28).

  • Kernel panics in the GPU driver (2026-10-04, M4 Max 48 GiB, macOS 27.0.1).

    • What happened. At 01:50:34, during regress_m4.sh (check engine.parity.gpu_routed: every expert resident, ~16 GB on the GPU), macOS panicked: "Kernel data abort" at address 0x10 inside com.apple.iokit.IOGPUFamily (offset 0x2a31c, reached from 0xabd0), in a system call of redlite-engine. Its second thread was in the kernel outside the driver. A user process cannot dereference a kernel null pointer, so this is a driver bug that our workload reached.
    • Not reproducible after a reboot. The same check passed 5 times in a row, and the whole regression passed 52/0/0 in the same order.
    • State at the time (not proven to matter): 3 days of uptime with dozens of 17–29 GiB GPU load/unload cycles, swap in use, and a GPU out-of-memory error four hours earlier (two overlapped GPU jobs, dev54).
    • It happened again at 12:37, 5 hours after a fresh boot, in redlite-server during server_check.py (1.6 GB resident; llama-quantize and the local CI were running at the same time).
    • Same signature: the same driver offsets (0xabd0 → 0x2a31c), the same null address, and kernel stacks identical frame by frame. In both, two threads of our process were in the kernel: ours at default priority, in the driver, and a priority-46 thread outside it.
    • macOS 27.0.1 (build 26A434) was installed on that Mac on 2026-09-30. The same checks had run hundreds of times on macOS 26 without a panic. The M4 Pro (macOS 26.7) has never panicked. A driver regression in 27.0.1 is the likely cause. Not proven: the kernel has no symbols, and the bug does not reproduce on demand.
    • Practice.
      • Never overlap GPU-heavy jobs.
      • On macOS 27.0.1, run long Metal gates one at a time, and prefer a Mac on macOS 26 when available.
      • Filed with Apple as FB25130929 (2026-10-10), with /Library/Logs/DiagnosticReports/panic-full-2026-10-04-113143.0002.panic, panic-full-2026-10-04-123737.0002.panic and a sysdiagnose.
      • Issue #80: a MacBook Pro M5 16 GB on 27.0.1 (26A434) panicked with the same IOGPUFamily offset during a ~26.5K-token prefill at a 32K context (Red Lite 0.9.3); its 4K-context runs on 0.9.4 did not panic.
  • zsh word splitting broke two benchmark loops (set -- $var does not split in zsh); the measurement scripts run under bash.

  • Agent checks that depend on the machine (dev63). On the M4 Pro 24 GiB the repository suite of agent_eval.py never passed more than 2 of 4 tasks per run (4/12, 6/12, 3/12 for three sampling settings), against 10/12 for the same model file on the M4 Max. Two tests in tests/test_native_defaults.py patched the RAM but read the machine's real GPU limit, raised to 21,741 MiB there, so they failed in a clean copy of the repository. The fix_planner and long_session checks run them, so those tasks could not pass, and long fix_planner sessions (150 and 321 requests) were partly the model trying to fix failures it had not caused. Found by running the suite in a clean git archive copy on the M4 Pro; pi's version (1.0.2 against 0.84.4) was ruled out first. The tests now patch gpu_wired_limit_mib. Lesson: before reading an agent pass rate, run the task checks on an untouched copy on the same machine.

  • A 25 W charger on the M4 Max (dev65). Under GPU load the battery fell from 80 % to 7 % in one night, and macOS slowed the Mac: 256K-token decode measured 5.0 tok/s instead of 16.0, ingestion 44.9 tok/s instead of 182. A decode bench without the prefill disagreed, which led to the cause (pmset -g batt, system_profiler SPPowerDataType). Check the charger's wattage before long runs; the scripts now pause below 30 % battery.

  • llama.cpp's batched path as the oracle (dev65). To make the long-context comparison faster, the oracle first decoded the prefix in batches of 256. It then disagreed with its own token-by-token output already at 1,200 ids (KL 0.094, top token different), so it was not a reference. Decoding the prefix token by token with nothing captured (--prefix-batch 1) is byte-identical to the full oracle and still fast enough (13 minutes at 32K).

  • A decode attention kernel with one simdgroup per position (dev65). Coalesced key reads made it 6–7 % faster in kernel-bench with one shared KV buffer, but 34 % slower at 256K with distinct buffers per layer, as the engine has them. Not kept.

  • redlite-engine tokenize --text truncated to 16,384 ids silently, which turned a "64K" test prompt into 32K. It now warns.

  • Prefill attention shared across the 8 query heads of a KV head (dev66). A kernel with threadgroups of (KV head, 4 tokens), 32 rows per key/value block instead of attn_fa_b2's 16, Q read from device memory. Results were byte-identical (the 1/16 scale is exact), but the attention part of a 32K prefill (CF2, M4 Max, on AC) took 22.4 s against 17.0 s, and 35 s once the four P tiles were held in registers to load each V tile once. The premise was wrong: attn_fa_b2 already runs about 6 TFLOPS at 32K, so it is limited by the matrix units, not by key/value reads, and the larger per-thread state only cost occupancy. Not kept.

  • Two agent suites on one server (dev67, a trap). A remote start that seemed to fail had started; the second start ran a second copy of the hard suite against the same redlite-server. The two pi sessions alternated, so no request extended the held prompt: 0 % prefix reuse instead of 93 %, every turn re-read 15K tokens (80 s on the M4 Pro), 16 of 18 tasks hit the time limit, 1 / 18 passed. Each result line appeared twice in the log. The run was discarded and repeated alone (11 / 18). Check pgrep -f for a single suite, and the server log's cached counts.

  • Decode attention variants that did not add to the kept change (dev66). In attn_gqa_split_g, two threads per key row with interleaved reads in the score pass (all 256 threads busy instead of 128): −2 to −4 % alone, nothing once the value pass had four loads in flight, and it changes the summation order, so it was dropped. Eight value loads in flight instead of four: the same time at 32K–256K (34.9 vs 34.9 ms at 256K). The value pass, not the score pass, was the limit.

  • Prefill attention without the 16 KiB Q staging (dev66). attn_fa_b2 reading Q straight from device memory (threadgroup memory 18.6 → 2.6 KiB, for more threadgroups per core), output stored straight to the result buffer. Byte-identical, but slower at 32K: attention 19.9 / 18.7 s against 16.5 / 17.5 s (alternated, on AC). Occupancy is not the limit either; Q from threadgroup memory is cheaper than from device memory. Not kept.

  • Prefill attention on 8 simdgroups (dev71). attn_fa_b2 with 256 threads: each simdgroup one 8×8 S tile, two softmax rows and 32 of the 256 output dimensions, so half the accumulators per thread. Bit-identical, but the attention of a 32K prefill took 18.5 / 24.3 s against 16.5 / 17.3 s (alternated, CF2, M4 Max). Not kept.

  • The 3-bit Coder for agents on 48 GiB (dev71). Bartowski's IQ3_XXS with prompt lookup at 64K: 15 / 18 tasks in 49 minutes, decode 13–14 % slower than CF2 at the same context. CF2 with lookup passed 18 and 15 / 18 in two sets, so this suite sees no quality gain for the larger file.

  • Expert-kernel tuning from the Xcode profile (dev73). The profile of redmetal_topk_gateup_mm showed 178 registers and 21 % occupancy, bound by instruction throughput (72 %), with 34.5 % of the instructions integer (weight decoding).

    • One accumulator per product (instead of four partial sums combined exactly): +1 %, within spread.
    • The same with 32-pair tiles: no spill any more, but 4 % slower, because partial tiles waste matrix work.

    Registers and tiles are not what limits these kernels; the instruction count per decoded weight is. Not kept.

  • The IQ1_M / IQ2_XS block scale decoded once per block (dev73). Each thread of the expert matrix kernels rebuilds the block scale (four 16-bit loads and bit shuffling for IQ1_M) for every group of 8 weights, 8 times in a row per block. Caching it per block was bit-identical, but 3 % slower (23.2 against 22.5 ms on an IQ1_M layer, three alternated pairs): the added branches cost more than the decode they saved. Not kept.

  • Several drafted tokens per verify, simulated first (dev71): not built. A K-row verify would mean K-row versions of every decode kernel (bit-identical to one row), the DeltaNet state saved after each row, and the experts of every row. It was simulated on real traffic before any of that: 643 server requests of the hard agent suite (122K answer tokens, RL_SERVER_TRACE, scripts/dev/lookup_sim.py).

    • Cost model: a pass of R rows costs 1 + c (R − 1) plain steps; the 2-row verify measured c = 0.35.
    • The model matches the real run: with one draft (K = 1, what 0.9.0 does) it gives 1.30 tokens per unit of cost, in line with the +15–25 % measured.
    • Fixed K: 1.40× at K = 2 and 1.43× at K = 4, then 1.28× at K = 8, because a wrong draft mid-chain wastes the rows after it.
    • Adaptive K (double while every draft is accepted, back to 1 on a miss): 1.49× at up to 8 drafts against 1.30×.
    • The limit: each extra row brings its own ten experts, so c cannot drop much below about 0.3. At c = 0.5 the best policy gives 1.24× against 1.19×.
    • Verdict: at most +5–14 % on decode, about half of an agent's time (+3–7 % overall), for a rewrite of the decode path.
  • The DeltaNet convolution shift made in place for every caller (dev74). Plain decode shifts conv_state itself and skips the copy back. The 2-row verify and the paired-slot step call the same mid-layer emitter but copy next_conv into conv_state afterwards, so they wrote a stale window over the shifted one. verify-check passed (the verify uses its own 2-row kernel), engine.pair and server.parallel_greedy failed in the regression. The in-place shift is now a parameter that only plain decode sets.

  • The polyglot harness dropped bare code blocks (dev85). The model often answers an Exercism exercise with a fenced block and no file name before it, or with the name in backticks or bold. The first parser of scripts/dev/polyglot_eval.py wrote only blocks preceded by a plain file name, so CF2 passed almost nothing on the first try. That run was discarded; a single unnamed block now goes to the only solution file, and tests/test_polyglot_eval.py covers the formats.

Not reached, blocked or not attempted#

  • GitHub CI green (dev28): not reached, then removed (2026-10-03). GitHub refused to start hosted jobs on this account ("recent account payments have failed or your spending limit needs to be increased"). The project does not pay for hosted runners. The same steps run locally with scripts/dev/local_ci.sh.
  • IQ3_XXS prefill vs llama.cpp: 837 vs 861 tok/s at 1100 tokens with full residency (dev33). Re-measured 2026-10-01 at 547539f on an idle machine: native 859.4 (3 runs), 871.1 / 876.7 / 872.5 / 875.4 / 874.8 / 872.4 (A/B baselines), llama.cpp 878.8 (3 runs) on the same ids: about 0.6 % behind, inside run-to-run spread.
  • 4 GiB-cache prefill on a 24 GiB Mac: measured in dev47. 280.8 tok/s (1100 tokens) and 349.8 tok/s (8192 tokens) on the M4 Pro 24 GiB. The dev34 gain alone (3.3× fewer expert bytes loaded) was not isolated there.
  • Dense stage tools on the IQ3_XXS GGUF. The dev11–dev17 per-stage parity tools only accept the IQ2_XXS dense layout; regress_m4.sh reports 13 SKIPs on the IQ3_XXS file.
  • IQ3_M on this Mac (dev36): runs, but is not worth it. The file is supported since dev36 (its Q4_K expert down projections got a decoder). Measured on the 48 GiB M4 Max:
    • Full residency (34944 MiB) does not hold: GPU-routed decode ran at 46.8 tok/s, then 6.0 tok/s on the next run, then failed with kIOGPUCommandBufferCallbackErrorOutOfMemory (footprint 35.2 GiB). The planner's 75 % rule admitted it; the rule is now 70 %.
    • A 28 GiB cache gives 28.7 tok/s (97 % hits), against ~70 tok/s for IQ3_XXS with full residency.
    • Perplexity on the frozen corpus is 14.05 ± 0.26 against 14.29 for IQ3_XXS: inside the error bar.
    • Correctness is not the problem: with bounded caches it matches llama.cpp (logits, 24 greedy tokens, 1200-token long context). It is left out of the automatic model choice because on this Mac it is slower than IQ3_XXS for no measurable quality gain.
  • IQ3_XS, IQ4_XS: not run. Header reads (no download) show IQ3_XS needs no new type and would fit at full residency only under the old 75 % rule; IQ4_XS (39168 MiB of experts) does not fit this Mac.
  • Speculative decoding (dev37): not started then, done in dev45 with the MTP block from a separate file (DEV45). The 2026-09 reasoning, still valid for 24 GiB Macs: the IQ2_XXS / IQ3 GGUFs carry no Qwen3-Next multi-token-prediction layers (48 blocks, no nextn keys), so the MTP-based methods do not apply. Training-free drafts (prompt lookup, a reduced-expert self-draft) need a cheap multi-token verification, and the batched prefill path is slower than decode at small batches: 8-token chunks 137 ms against 8 decode steps 98 ms (full residency, redlite-engine prefill --batch 8). Papers on MoE speculation (EcoSpec 2607.12696, MoE-Spec 2602.16052, DraftExpert 2607.24434) also report that verifying several tokens loads the union of their experts, which is the 24 GiB bottleneck.
  • LensVLM (dev37): not implemented. apple/lensvlm-9b reads text rendered as compressed images (5–15× fewer tokens) and expands relevant pages on demand. It is a different model (Qwen3.5-9B + Qwen3-VL vision encoder, BF16 safetensors); Qwen3-Next-80B is text-only and cannot consume vision tokens, so the idea cannot be applied to this model without a second model family in the runtime.
  • OLED-MoE (2609.33385): not applicable. Its inter-iteration expert retention targets diffusion LLMs.
  • Overlapping CPU encoding with GPU execution (dev38): not attempted. At full residency the CPU gap between GPU-routed tokens is 0.44 ms of 12.1 ms.
  • 32-pair tiles in the batched expert matrix kernels (dev69). redmetal_topk_gateup_mm / down_mm serve 16 (expert, token) pairs per decoded weight tile; with 2048-token chunks an expert gets about 40 pairs, so 32 would halve the decode work per multiply. Bit-identical (each pair's sums keep their order), but the expert stage of an 8,191-token prefill went from 4.0 s to 20.3 s (CF2, M4 Max): twice the accumulators (32 8×8 tiles per simdgroup in gate/up) do not fit in registers. 16 pairs (dev30) stays. Not kept.
  • 4096- and 8192-token prefill chunks (dev68, measured). dev34 left them untried (they exceed the 32,768 pairs one expert plan accepts, a sanity bound; the pair buffers grow on demand). With the bound raised, an 8,191-token prompt (CF2, every expert resident, M4 Max, alternated) took 8.69 / 8.99 s in chunks of 2048, 8.51 / 8.74 s in 4096 and 8.43 / 8.57 s in 8192: 3–5 %, all in the expert stage (4.0 → 3.7 s), for about 0.5 / 1.6 GB more scratch. The expert kernels are not starved of tokens per expert at 2048; they are bound by their own arithmetic. Dumps were byte-identical across chunk sizes. Not kept.
  • llama-perplexity in the oracle build tree. Rebuilding it there failed (OpenSSL target) after relinking one oracle library from the same pinned source; it is built in its own tree (.deps/llama.cpp/build-ppl) by scripts/dev/perplexity.sh (dev31).
  • redlite gpu-limit on 48 GiB Macs (dev85): written, then reverted. The idea was to raise the GPU limit so that CG2 keeps every expert resident at 128K, beyond what the planner's 70 % rule admits (about 96K with the half KV cache). On the M4 Max, macOS already lets the GPU use 38,339 MiB (Metal's recommendedMaxWorkingSetSize), more than CG2 needs at 128K (36,209 MiB), so a computed limit would only have lowered it. What stops 128K is the 70 % rule, and it stays: in dev36 IQ3_M with every expert resident (footprint 35.2 GiB) ran out of GPU memory on its third run, below macOS's limit. At 128K the planner uses the 4 GiB cache.

SOURCE docs/WHAT_DID_NOT_WORK.md · updated 2026-10-21 · EDIT ON GITHUB