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 / mojo_engine / TINYLLAMA_QUANT_BENCHMARK.md

73 lines · 3441 bytes Raw Blame History Source

TinyLlama Quantization Benchmark — Real Inference Results

Date: 2026-05-22

Test Setup


Real Inference Results (f16-dequantized weights)

The gguf_extract tool dequantizes some formats to f16 at extraction time. Once in f16, all formats run at the same speed in the forward pass.

FormatWeight SizeExtracted Astok/sStatus
f162.1 GBnative f1627.2✓ Verified correct
Q8_02.1 GBf16 (extract)28.2✓ Same speed
Q6_K2.1 GBf16 (extract)27.5✓ Same speed
Q3_K1.7 GBf16 (extract)26.4✓ Same speed
TQ2_02.0 GBf16 (extract)25.0✓ Same speed

Why same speed? gguf_extract converts these formats to f16 .bin files during extraction. The forward pass sees only f16 weights. The 2-3 tok/s variation is noise (cache state, thread scheduling).


Raw Quantized Formats (on-the-fly dequant)

These formats remain in packed form after extraction. On-the-fly dequantization during matmul would show real speed differences.

FormatWeight SizeFormat After Extracttok/sStatus
Q4_0681 MBraw Q4_0 packed—✗ Garbage output (debugging)
Q2_K1.2 GBraw Q2_K packed—✗ Not yet tested
Q5_01.2 GBraw Q5_0 packed—✗ Not yet tested

Q4_0 bug: On-the-fly dequant matmul produces tokens but output is garbage (not "4" for "2+2="). The Q4_0 block dequantization in the generation pipeline has a bug — likely in how blocks are indexed across rows. Debugging requires stepping through a single matmul and comparing against reference dequantization.

Expected Q4_0 speed if fixed: ~15-20 tok/s (slower than f16 because each load requires nibble extraction + sign-extension + scaling, but faster memory bandwidth due to 4× smaller weights).


Methodology

What counts as "real inference":

  1. Load weights from extracted .bin files (f16 or raw quant)
  2. Full forward pass: 22 layers × (RMS Norm ×2 + QKV proj + RoPE + GQA attn + O proj + FFN gate/up/down + residual)
  3. KV cache stores K/V for each position
  4. Argmax over 32,000 vocabulary logits
  5. Token decode (ID → UTF-8 text, strip ▁ space markers)
  6. Feed output token back as next input

NOT synthetic: This is actual token-by-token generation through the full model, not random-data matmul throughput.


Files

FilePurpose
tinyllama_benchmark.mojoMulti-prompt f16 benchmark
tinyllama_q4_benchmark.mojoQ4_0 on-the-fly dequant (WIP)
tl_gen.cC reference (25.0 tok/s f16)

Next Steps

  1. Fix Q4_0 on-the-fly dequant: Debug block indexing in q4_0_mm, compare against reference
  2. Add Q2_K and Q5_0: Similar on-the-fly kernels once Q4_0 is working
  3. Dequant-at-load option: For faster comparison, dequantize Q4_0 to f16 at load time (proven working in tinyllama_f16.mojo)