MojoLlama
Archived Mojo/MAX quantizer and serving research repository (read-only history)
Brought by drakestapleton
MojoLlama / src / mojollama / .coding-memory
| 1 | # MojoLlama — C Engine NaN Fix Progress |
| 2 | |
| 3 | ## Current State (Qwen3-30B-A3B) |
| 4 | - NaN: 0/151936 ✅ |
| 5 | - Speed: 11.6 tok/s (baseline: 25 tok/s) |
| 6 | - Logits: non-zero, valid range |
| 7 | - Fix: SIMD clamp x in-place + copy to res + memcpy for residual |
| 8 | |
| 9 | ## Performance Bottleneck |
| 10 | The `_mm256_storeu_ps` to xb AND rb (double store) for every 8 elements causes 2.5x speed regression. The stores to xb break the compiler's ability to auto-vectorize the subsequent rms() call because of memory aliasing. |
| 11 | |
| 12 | ## Performance Fix Strategy |
| 13 | Replace the 3 clamp loops + memcpy with a fused approach: |
| 14 | 1. Change the 3 clamp+rms blocks to use ONLY ONE store (to x, in-place) |
| 15 | 2. Then use `memcpy(res, x, N*sizeof(float))` for the residual backup (libc memcpy is highly optimized) |
| 16 | 3. rms() stays as original scalar version (fastest) |
| 17 | |
| 18 | This reduces the clamp from: |
| 19 | load+clamp+store_x+store_res (4 ops per 8 floats) |
| 20 | to: |
| 21 | load+clamp+store_x (3 ops per 8 floats) + memcpy (extremely fast) |
| 22 | |
| 23 | ## Next: GPT-OSS-20B |
| 24 | Model: `/tmp/models/gpt-oss-20b-Q4_K_M.gguf` |
| 25 | Arch: 24 layers, 2880 hidden, 64 heads, 8 KV heads, 32 experts top-4 |
| 26 | Uses MXFP4 (type 39), NOT Q4_K_M despite filename! |
| 27 | |
| 28 | ## Files |
| 29 | - `kernels/cengine_batch_instr.c` — C engine (modified) |
| 30 | - `test_fixed.py` — test harness (unmodified) |