72-logical-layer 4-bit Qwen4-35B-A3B (UD-IQ4_XS + Open-Channel Looped v4 T=3) with native 256K (262 144) K8V4 context, single-read NVMe SSD expert streaming, and persistent subagent prefix caching — running comfortably on a 24 GB Apple Silicon Mac.
This is a performance-focused Metal 4 fork of Niko1221/Strata (v0.2.28, original README preserved in README.upstream.md). Every optimization in this fork is 100% lossless (verified bit-exact on decode and numerically lossless on prefill) and tailored for everyday 24 GB+ Apple Silicon Macs (tested on MacBook Pro Apple M4 Pro, 16-core GPU, 24 GB Unified Memory, macOS 26+/27).
All measurements on Qwen4-35B-A3B UD-IQ4_XS + Looped v4 T=3 (72 logical layers, core=[12,28)), native 262 144 K8V4 context, --spec 2 suffix drafting, inside the 18.8 GB macOS working-set cap (15.6 GB footprint, zero swap):
| Metric | Baseline (6.5 GB LRU) |
Wave 1 (STRX + Core-LFU) |
Wave 2 (Split-MoE + F16) | Wave 3 (Current) | Total Gain |
|---|---|---|---|---|---|
| Long Prefill (9 790 tok, 72L) | 178.9 tok/s (54.7 s) |
213.5 tok/s (45.9 s) |
254.0 tok/s (38.5 s) |
325.3 tok/s (30.1 s) |
+81.8% (-24.6 s) |
| Equivalent 40-layer prefill | 322 tok/s | 384 tok/s | 457 tok/s | ~586 tok/s (peak 635) |
+82% |
| Short Prefill (247 tok) | 68.7 tok/s | 79.6 tok/s | 70.7 tok/s | 90.1 tok/s | +31.1% |
| Decode: RU Prose | 19.2 tok/s | 21.0 tok/s | 23.6 tok/s | 23.1 tok/s | +20.3% |
| Decode: Python Code | 15.9 tok/s | 18.3 tok/s | 21.0 tok/s | 20.8 tok/s | +30.8% |
| Decode: Math (CoT) | 17.6 tok/s | 19.8 tok/s | 22.2 tok/s | 22.4 tok/s | +27.3% |
| Decode: Logic / Rust | 19.2 tok/s | 21.8 tok/s | 24.6 tok/s | 24.7 tok/s | +28.6% |
| Decode @ 10K ctx (cold) | 17.7 tok/s | 20.3 tok/s | 22.8 tok/s | 22.8 tok/s | +28.8% |
| Decode @ 10K ctx (cached turn) | 18.7 tok/s (1.70 s TTFT) |
20.8 tok/s (1.69 s) |
21.8 tok/s (1.50 s) |
22.7 tok/s (1.59 s) |
+21.4% |
| Mean Decode (6 benchmarks) | 18.05 tok/s | 20.33 tok/s | 22.67 tok/s | 22.75 tok/s | +26.0% |
| Subagent Prefix Reuse (9.8K sys) | 44.5 s TTFT |
1.18 s RAM / 1.40 s SSD |
1.18 s / 1.40 s |
1.18 s RAM / 1.40 s SSD |
31–37× faster |
| Decode SSD Traffic / Step | ~114.8 MB/win | 57.0 MB/win | 48.3 MB/win | 48.7 MB/win (95.5% hit) |
-58% SSD I/O |
| Total SSD Moved (7-prompt suite) | — | 328.5 GB | 191.8 GB | 149.9 GB | -54.4% vs W1 |
- Files:
engine/metal/src/engine/loop.inc,engine/metal/src/engine/window.cpp,engine/metal/src/gpu/runtime.cpp - Full
v4open-channel recurrence (core=[12,28), 3 passes = 72 logical layers) in both decode windows and streamingprompt_chunkprefill, plusT=3K8V4KV cache, core-wrap prefetch, and early purge of unused host-side Metal allocations (8.59 GBfreed before window init) so 256K context fits cleanly on 24 GB unified memory.
- Files:
engine/metal/src/engine/window.cpp,engine/metal/src/mtl_rt.mm - Split-MoE overlap (
STRATA_METAL_SPLIT_MOE=1): runs the entire shared expert across[Cut 1, Wait 1)whilebegin_layer()submits SSD misses, runs all resident routed experts across[Wait 1, Wait 2)whilefinish_layer()completes SSD reads, and dispatches only the newly arrived experts afterWait 2(hardware no-op when 0 misses). VerifiedBIT-EXACT PARITY: Trueagainst non-split decode. - Dual unidirectional
MTLSharedEvents + multi-CB chunking (kMaxCutsPerCb = 48): eliminates an Apple Silicon Metal 4 bidirectional event race on fast 0-miss cuts (kIOGPUCommandBufferCallbackErrorTimeouton 144-cutT=3graphs). - F16 dense GEMV +
Q6_KLM head (STRATA_METAL_F16=1) unlocked for streaming decode +STRATA_METAL_SEG_FILL=cutto keep GPU clocks up across 72 cuts.
- Files:
engine/metal/kernels/moe_mm.metal,engine/metal/kernels/dense_mm.metal,engine/metal/kernels/qsa_prompt.metal,engine/metal/src/engine/loop.inc,engine/metal/src/engine/window.cpp - FP32
matmul2dLooped v4 Mixers (gemm_f32_64_64_4,gemm_f32_ws_64_64_4): kernel profiling (PG-KPROF) revealed that scalar decode-style mixer kernels burned616 ms/chunk(~3.1 son 9.8K prefill) despite representing only1.2%of FLOPs. Moving them to FP32matmul2dforn_tok >= 32cut them to~18 ms(34× faster) with full FP32 accuracy. - M4-Native Ragged Multi-Subtile MoE GEMMs (
v2-r4):mm_gu2_r(IQ4_XS64×32×4, parallel 64+64 gate/up decode) andmm_down2_r(Q4_K64×64×2) reusemm_scan6(MS = 4) so each expert weight is dequantized 1× per 64 tokens instead of 4×, with a fused64×64fast path whennsub == 4and zerocoop_k4(M5-only) dependency — cuttingQ4_Kdown GEMM from1 028 ms → 525 ms(1.96× faster,4.7 TFLOPSincl. dequant). - TG-Staged
qsa_flash+ 32-Lane SIMD Parallel Online Softmax: replaces scalar per-element!coop_k4K/V loads with coalescedchar4K (2 cells/lane) +uchar4int4 V staged into idlesp[sg](0extra TG memory) and parallelizes online softmax across all 4 simdgroups (-1.0 s/chunkat full QSA budget,-140 MBscratch RAM). - Fused
gdn_scanf_8(fixes"Apple M4 Pro"chip match + fuses GDN scan & post), promptat_cut()overlap with MoE planning + shared expert, and full-chunk wraplayer 0prefetch (missedrate1.47% → 0.32%).
- Files:
engine/metal/tools/stream_experts.py,engine/metal/src/engine/stream.h,engine/metal/src/engine/stream.cpp - Auto-shape
STRX(40×256): packs each expert's(gate, up, down)into a single contiguousF_NOCACHENVMe read (4.38 GB/speak on M4 Pro). - Core-Weighted LFU +
STRPProfile Collector (STRATA_METAL_DUMP_PROFILE): protects the[12,28)core experts executed 3× per token;7.2 GBwired (mlock) arena holds4 225slots (> all4 096core experts). - Core-Pinned Prompt Eviction: keeps core experts at LRU head during prefill (
44.5% → 64.6%prompt arena hit rate,-22%total SSD wear). - Standalone Prefill Scratch + Darwin
MADV_FREE_REUSABLE/MADV_FREE_REUSE+ 64 MiB StripemlockRetry: steals0arena slots during2048-token prefill (2.12 GB), immediately reclaims scratch from macOSphys_footprintafter prefill, and reliably wires all7.2 GBeven right after restart.
- Files:
engine/src/program/generate.cpp,engine/src/program/conversation_state.cpp,engine/src/program/conversation_spill.cpp ConversationSpill::put_streamed+spill_direct()writes large checkpoints straight to SSD across server restarts (6 144 MiBpersistent tier).- Fixed Qwen4
root_atboundary detection past the 15-tokenReasoning effortheader and preserved the root system-prompt checkpoint alongside the deepest turn — giving subagents 37.6× faster TTFT in RAM (1.18 s) and 31.5× faster TTFT from SSD even after a full restart (1.40 s).
git clone https://github.com/qoder3/Strata.git
cd Strata
# 1. Build Metal engine (q4_lite), download UD-IQ4_XS + PLE-Q4 + Looped v4 T=3,
# build trunk40.gguf + pack + STRX + RAM-tuned config.json
./presets/qwen4-looped-metal/setup.sh
# 2. Start OpenAI-compatible server on http://127.0.0.1:10101/v1
./presets/qwen4-looped-metal/run.sh start
# 3. Check status & memory pressure
./presets/qwen4-looped-metal/run.sh statusAlready have the GGUF / PLE / loop adapter on disk? Symlink them instead of re-downloading, or inspect every planned command with --dry-run:
./presets/qwen4-looped-metal/setup.sh --dry-runFor full requirements, custom STRP routing profiles, environment knobs, and Z-Code / OpenAI client setup, see presets/qwen4-looped-metal/README.md.
- LoopSpec (
T=1/T=2 → T=3self-speculative drafting): despite97.4%(T=1→3) /100.0%(T=2→3) teacher-forced agreement, drafting is0.67×–0.78×slower on SSD-streamed MoE because each draft step still pays SSD misses while multi-token verification scales linearly with misses. Free suffix drafting (--spec 2) stays ON. - Adaptive Tail-Skip (
STRATA_METAL_TAIL_SKIP): implemented in Split-MoE with exact renormalization, left0.0(lossless) by default because Qwen4's top-8 router weights are flat (~0.08–0.18), so safe thresholds (0.03–0.05) skip< 1.6%of misses with no latency gain. - Chunked WY/UT GDN (
gdn_cprep2 + gdn_cstate2): wired (STRATA_METAL_GDN_CHUNK=1) and benchmarked at461.6 msvs212.5 msforgdn_scanr_4_8/gdn_scanf_8on 16-core M4 Pro (2.17× slower), so fusedgdn_scanf_8is default. PROMPT_CHUNK=4096on 24 GB Mac:4.0 GBstandalone scratch pushes total footprint over the18.8 GBcap into macOS swap;2048(2.12 GB) is the swap-free sweet spot on 24 GB (render_config.pyautomatically enables4096on 48+ GB Macs).
Built on top of Niko1221/Strata (MIT License — see LICENSE and README.upstream.md). Model weights by Unsloth, Strata Engine, and sliderforthewin.