Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/kernels/CHANGES.md # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / kernels / CHANGES.md` 38 lines · 2290 bytes Raw Blame History Rendered 1 # MojoLlama Optimizations — May 21 2 3 ## Changes Made 4 5 ### 1. Q4_K MoE Down Path Q8_0 Activation (quant_kernels_omp.c) 6 - **Before**: MoE down matmul for Q4_K weights used `q4_k_row_dot_avx2` (dequant weights to F32 → FMA with F32 activation) 7 - **After**: Pre-quantizes the siLU*up buffer to Q8_0, then uses `q4_k_row_dot_q8` (VPMADDUBSW integer dot product on packed weights) 8 - **Impact**: Keeps Q4_K weights packed (144 bytes/256 values vs 1024 bytes dequantized), reduces cache pressure, saves dequantization FMA cost 9 - **Triggered**: For all MoE models with Q4_K expert down weights (Qwen3-30B, Qwen3.6, GPT-OSS MoE variant) 10 11 ### 2. Static OMP Scheduling (quant_kernels_omp.c) 12 - **Before**: Both gate+up and down phases used `schedule(dynamic, 64)` — dynamic work-stealing with 64-iteration chunks 13 - **After**: `schedule(static)` — static iteration distribution 14 - **Impact**: Eliminates thread-safe work-stealing overhead. Uniform work per iteration (same quant type, same dimensions) makes static distribution optimal. Chunks are perfectly divisible by 32 threads (5760÷32=180, 5760÷32=180). 15 16 ### 3. prealloc_q8 Buffer Size (turbo_engine_v7_moe.py) 17 - **Before**: Allocated only `n_blocks_x * 34` bytes (single Q8_0 block set for the norm input) 18 - **After**: Allocates `top_k * FF_expert * 34 // 32` bytes (enough for all top_k experts' Q8_0 activation buffers) 19 - **Impact**: Enables the Q4_K Q8_0 down path (change #1) which needs per-expert Q8_0 workspace 20 21 ## Expected Impact 22 - **MoE models (Qwen3-30B, Qwen3.6)**: ~5-10% improvement on MoE FFN portion 23 - **Overall speedup**: ~3-5% on total throughput for MoE models 24 - **Dense models (GPT-OSS)**: Minimal impact (non-MoE path was already optimized) 25 26 ## Current Status vs llama.cpp 27 28 | Model | MojoLlama | llama.cpp | Ratio | Status | 29 |-------|:---------:|:---------:|:-----:|--------| 30 | Qwen3.6-35B | 19.5 tok/s | 16.36 | 119% | ✅ BEATS | 31 | GPT-OSS-20B | 27.3 agg | 27.69 | 99% | 🔥 Near parity | 32 | Qwen3-30B | ~23.3 agg | 27.89 | ~83% | ⚠️ Needs work | 33 34 ## Next Frontier 35 The remaining gap (especially Qwen3-30B) is bandwidth utilization: 36 - **MojoLlama**: ~46 GB/s DDR4 bandwidth 37 - **Llama.cpp**: ~70 GB/s (52% higher) 38 - **Root cause**: Less efficient memory pipeline (no prefetch, OMP barrier overhead between regions)