interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / src / mojollama / .coding-memory

30 lines · 1253 bytes Raw Blame History
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
10The `_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
13Replace the 3 clamp loops + memcpy with a fused approach:
141. Change the 3 clamp+rms blocks to use ONLY ONE store (to x, in-place)
152. Then use `memcpy(res, x, N*sizeof(float))` for the residual backup (libc memcpy is highly optimized)
163. rms() stays as original scalar version (fastest)
17
18This reduces the clamp from:
19 load+clamp+store_x+store_res (4 ops per 8 floats)
20to:
21 load+clamp+store_x (3 ops per 8 floats) + memcpy (extremely fast)
22
23## Next: GPT-OSS-20B
24Model: `/tmp/models/gpt-oss-20b-Q4_K_M.gguf`
25Arch: 24 layers, 2880 hidden, 64 heads, 8 KV heads, 32 experts top-4
26Uses 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)