CPU inference engine · plain C · MIT
Gwenedeg
Dense Qwen models on AVX-512 VNNI CPUs (Zen 4, Ice Lake and later).
A library, a CLI and an OpenAI-compatible server in plain C. Fast paths: x86-64 with AVX-512 VNNI (developed and measured on AMD Zen 4) and Apple Silicon (NEON). Other CPUs run the generic C kernels: the same results, but slower.
Qwen3.8-27B
vs 5.2 tok/s on llama.cpp*
vs 78 tok/s on llama.cpp*
vs 218 s on llama.cpp*
* Same ISTA-DASLab IQ3_S file in both, 16-vCPU AMD EPYC (Zen 4), 14 threads, 2026-11-22. Decode: 1 client, thinking on. Prefill: prompts of 0.8–2.5k tokens, best of each. Agent turn: ~2.5k new tokens on a 32k-token session, wall time. llama.cpp in its best measured setup (f16 KV cache, no MTP). One run per cell; ik_llama.cpp and the details in the benchmark below.
Qwen3-0.6B
Q4_K_M, 16-vCPU AMD EPYC, 12 threads, 2026-10-26, best of 2.
128 tokens after a short prompt. 278 at 8 threads.
451-token prompt. 1,721 at 8 threads.
Q8_0, 8 / 12 threads: prefill 1,813 / 2,287, decode 207 / 165. All models in BENCHMARKS.md.
Qwen3.5-0.8B
Q8_0, 16-vCPU AMD EPYC, 12 threads, best of 2.
128 tokens after a short prompt, 2026-10-26. 141 at 8 threads.
451-token prompt, 2026-10-27. 1,506 at 8 threads.
Numbers on the small-model tabs come from other sessions than the 27B ones: don’t compare across tabs.
Coming from llama.cpp?
Switch to Gwenedeg when (dense Qwen models, measured on Qwen3.8-27B)
- you run dense Qwen models (Qwen3, Qwen3.5, Qwen3.8-27B) on an AVX-512 VNNI CPU: it loads the same GGUF files and decodes Qwen3.8-27B at 17.5 tok/s where llama.cpp does 5.2;
- you run agents or long chats: at 32k context it decodes at 14.8 tok/s against 3.88, and a follow-up turn takes 72 s against 218 s;
- you serve several users: four clients share each pass, 26.2 tok/s in aggregate against 5.3 (thinking off);
- you need reproducible output: the same logits, bit for bit, whatever the thread count, batch or chunk size.
Stay on llama.cpp when
- you use a GPU: Gwenedeg is CPU only;
- you need MoE models, non-Qwen models, images or other GGUF types (Q4_0, IQ4_NL, F16 matrices);
- your CPU has no AVX-512 VNNI (and isn’t Apple Silicon): Gwenedeg falls back to generic C kernels, with the same results but much slower.
Same quality either way: perplexity within 0.2% on the same file.
Same file, same CPU: Gwenedeg against llama.cpp
Qwen3.8-27B, one 12.1 GB IQ3_S GGUF, served by gwenedeg serve, mainline llama.cpp and ik_llama.cpp, measured on the same day, on the same VM, with the same prompts and the same benchmark script. Against llama.cpp, Gwenedeg decodes up to 4.4× faster at one client, up to 5.7× at four and up to 3.9× at 32k context; it prefills up to 1.5× faster on short prompts and 1.7× faster on the cold 32k prompt, and a 32k follow-up turn finishes about 3× sooner. Against ik_llama.cpp: decode up to 1.9× / 3.6× / 7.2× faster, but ik prefills faster.
Decode speed tok/s, higher is better
An agent turn on a 32k-token session seconds, lower is better
How each engine was run. llama.cpp is shown in its best measured configuration: an f16 KV cache, faster for it than 8-bit K / 4-bit V in every row (at an 8k depth its prompt processing runs at 14.3 tok/s with 8/4-bit and 62.7 with f16), and no MTP: mainline runs this file’s MTP block, but every draft length from 1 to 6 decoded slower than none on this CPU. Gwenedeg and ik_llama.cpp use an 8-bit K / 4-bit V cache with MTP. Both other engines were configured by us from their docs. One run per cell on a shared VM; caveats below.
Quality is the same
Perplexity on the same tokens, same file, all three with an 8-bit K / 4-bit V cache: within 0.2%.
| Gwenedeg | llama.cpp | ik_llama.cpp | |
|---|---|---|---|
| prose (Beagle ch. I) | 9.483 | 9.480 | 9.493 |
| code (the 32k source’s head) | 7.133 | 7.141 | 7.145 |
4 clients, raw runs
Aggregate tok/s, greedy / seeded (T 1, top-p 0.95, top-k 20, seed 42). The charts show the mean of the two.
| Gwenedeg | llama.cpp, 4 slots | ik, 1 slot + MTP | |
|---|---|---|---|
| thinking on | 23.0 / 23.0 | 4.7 / 5.7 | 8.0 / 6.6 |
| thinking off | 27.0 / 25.4 | 4.8 / 5.8 | 7.6 / 9.6 |
ik_llama.cpp drops its MTP stage with more than one slot, so its four clients queue behind one MTP slot.
Where ik_llama.cpp wins: prefill
ik_llama.cpp prefills faster than Gwenedeg: 125 against 111 tok/s on short prompts (best of each), and a cold 31.8k-token prompt in 309 s against 391 s: ik is up to 27% faster. Gwenedeg still prefills faster than llama.cpp: up to 1.5× on short prompts and 1.7× on the cold 32k prompt (391 s against 682 s). On a follow-up turn’s ~2.5k new tokens the cached prefix makes it close: Gwenedeg 37.4 s, ik 35.0 s, llama.cpp 83.9 s (best of two turns).
Prefill speed tok/s, higher is better
Gwenedeg’s prefill got 1.24× faster on 2026-11-21 with an i-quant tiled GEMM, with bit-identical output (BENCHMARKS.md). The numbers above already include it.
Setup
- Machine
- AMD EPYC Genoa (Zen 4), 16 vCPUs, 32 MB L3, 30 GB RAM, AVX-512 VNNI / VBMI / BF16. A KVM VM shared with other workloads (1-minute load 1–20 over the day). 14 threads for every engine, 2026-11-22.
- Model
Qwen3.8-27B-GSQ-RCO-IQ3_S-mtp.gguf(ISTA-DASLab, 3.44 bpw, 12.1 GB, with its MTP block). Thinking on and off.- Workload
- The same
scripts/s9c_bench.pyfor all three. Two LiveCodeBench-shaped and two agent-shaped prompts, 512 new tokens; a 31,755-token cold prompt plus two follow-up turns of ~2,500 new tokens. Greedy and seeded requests. - Gwenedeg
50ba538, gcc 14.2.0:gwenedeg serve --ctx 98304 --draft mtp -G 6 --tau 0.5 --repack -k q4-dot --slots 6 --parallel 4 --admit bound. The binary was calledrunquntil 2026-11-22 (README), so this commit and the raw benchmark data use that name.- llama.cpp
225a5345bbb0(master of 2026-11-22), Release,-DGGML_NATIVE=ON(AVX-512, VNNI, VBMI, BF16 on):llama-server -t 14 -fa on -ctk f16 -ctv f16 -ub 512 -b 2048 -lm none --no-repack --ctx-checkpoints 4 -cram 512 --jinja,-np 1/-np 4, at-c 98304(long run:-c 49152). Also run with an 8-bit K / 4-bit V cache, which was slower. Tuned withllama-bench.- ik_llama.cpp
ac8d544b(2026-11-19):llama-server -fa on -ctk q8_0 -ctv q4_0 -rtr -ub 1024 -b 2048 -t 14 --spec-type mtp:n_max=6,p_min=0.5 --ctx-checkpoints 4 --jinja -cram 512, 1 slot,-c 16384/-c 49152.- Raw data
- bench/llamacpp-2026-11-22/, method and every configuration in BENCHMARKS.md.
Caveats, read before quoting a number
- One run per cell, on a shared box. Differences of a few tens of percent are noise; the 3–9× ones are not. Each run’s load is in the raw data.
- llama.cpp and ik_llama.cpp were configured by us, from their docs, and tuned with
llama-bench. Their authors may know better settings. Mainline’s MTP slowdown is measured, not explained. - KV caches differ. Gwenedeg and ik use 8-bit K / 4-bit V with equal bit widths but different quantizers. llama.cpp’s f16 cache, its faster setting, holds 2.6× Gwenedeg’s KV bits. Its perplexity was measured with the 8/4-bit cache only (f16 can only be as good or better).
- Contexts differ. Gwenedeg and llama.cpp ran their short requests at 98,304 positions; ik_llama.cpp at 16k (short) and 48k (long), because at 98k its server ran out of memory in a 20 GB cap on 2026-11-21.
- Not measured: vLLM’s CPU backend, other engines, other CPUs.
What is different inside
The things that matter to someone who has read an inference engine before.
Bit-exact, any shape
Logits are bit-identical whatever the thread count, the prefill chunk size or the batch composition. Batched prefill equals token-by-token; a batched decode row equals decoding that sequence alone; speculative output equals plain decoding's. The test suite checks all of it.
i-quants on AVX-512 VNNI
AVX-512 VNNI kernels for the GGUF i-quants (IQ1_S … IQ4_XS, Q2_K) and K-quants, NEON on AArch64, generic C elsewhere: all bit-identical. --repack stores IQ3_S / IQ3_XXS weights as 4-bit codes at load: lossless, less decode work per weight for +0.75 / +1.0 bit per weight of RAM. Prefill runs a tiled GEMM that decodes each weight tile once per chunk: 1.24× faster on Qwen3.8-27B IQ3_S at 14 threads, bit-identical.
MTP + continuous batching
The model's own multi-token-prediction block drafts up to 6 tokens, the model verifies them in one batched pass. In gwenedeg serve the guesses of every running request are batched together, so several clients speculate at once. The output is plain decoding's, whatever the draft.
Compact KV cache
K and V are Walsh-Hadamard rotated and quantized per 32 dims: q8 (8-bit), q4 (8-bit K + 4-bit V), q4k4 (4-bit both, Qwen3.5 / 3.8). Qwen3.8-27B at 98k positions: 6.0 GiB in f16, 3.19 / 2.44 / 1.69 GiB. Still bit-exact across batches and threads.
Reuse, with a disk tier
A new request takes the idle slot with the longest common prefix and prefills only the rest. --kv-disk DIR saves evicted slots and loads them back bit-identical, also after a restart: a 27k-token Qwen3.8-27B Q4_K_M conversation took 408–418 s to prefill and 0.58–0.61 s to load back (16 threads, 2026-10-31).
Tool calls for harnesses
tools, tool messages and earlier tool_calls are rendered exactly as the model's chat template does (tested against Hugging Face). The model's XML calls come back as OpenAI tool_calls with typed JSON arguments, streamed too. pi runs its agent loop against it. Qwen3.5 / 3.8 only.
Exact, and constrained
Byte-level BPE matching Hugging Face tokenizers, NFC included; chat templates built in. JSON-schema decoding for finite sets of outputs: forced tokens are not decoded at all, so a classification is a single prefill.
Plain C, nothing to install
make and gcc (or Xcode's command-line tools). No third-party libraries (libc, libm, pthreads); Python 3's standard library only for the model download script. The CLI and the server use only the public API in src/gwenedeg.h.
Architecture
One C library, two front ends. Everything numeric lives in a few files, and every kernel family follows one arithmetic definition: int8 activations in groups of 32, with the float folds in a fixed order and without FMA contraction.
src/cli.c)serve.c engine.c http.c tools.c constrain.c)rq_forward_batch, rq_generate, rq_generate_spec, rq_seq_save / rq_seq_load, …max_batch rows, logits.Quick start
Linux with gcc is the main platform; macOS on Apple Silicon builds with NEON kernels. The server is POSIX only.
Build and chat
# make + gcc, nothing else $ make # -> ./gwenedeg $ scripts/download_models.py q8gguf # Qwen3-0.6B Q8_0, pinned + checksummed $ G=models/Qwen3-0.6B-GGUF/Qwen3-0.6B-Q8_0.gguf $ ./gwenedeg $G -c 4096 # interactive chat $ ./gwenedeg $G -c 4096 -t 0 -n 200 -i "Why is the sky blue?"
Serve an OpenAI-compatible API
$ ./gwenedeg serve $G # http://127.0.0.1:8080/v1, no auth, no TLS $ curl -s localhost:8080/v1/chat/completions \ -d '{"messages": [{"role": "user", "content": "Hi!"}], "max_tokens": 32}'
By default it binds 127.0.0.1 with no authentication (--api-key KEY requires a bearer token) and has no TLS: keep it on localhost or a trusted network.
The benchmark's configuration
# Qwen3.8-27B, IQ3_S with its MTP block, 4 requests batched, 98k context $ ./gwenedeg serve Qwen3.8-27B-GSQ-RCO-IQ3_S-mtp.gguf \ --ctx 98304 --draft mtp -G 6 --tau 0.5 --repack \ -k q4-dot --slots 6 --parallel 4 --admit bound \ --kv-disk ./kv-cache # prefix cache that survives eviction and restarts
The IQ3_S file is ISTA-DASLab's, from Hugging Face; the repo's download_models.py fetches the sets it lists (--list). Memory: the loader estimates what a run needs before reading any weight and refuses with a one-line message if it does not fit.
Library
RqModel *m = rq_model_load("Qwen3-0.6B-Q8_0.gguf", NULL, err, sizeof(err));
RqCtx *c = rq_ctx_new(m, 512, 0, &e);
RqSeq *s = rq_seq_new(m, 4096, RQ_KV_DEFAULT, &e);
RqSampling cfg = { 0.7f, 0.9f, NULL };
rq_generate(c, s, t.v, t.n, &cfg, 256, &cb, &stats);
Models and formats
Models
Qwen3 dense 0.6B, 1.7B, 4B, 8B, plus 4B-Instruct-2507 and Thinking-2507. Qwen3.5 0.8B and 4B (hybrid: Gated DeltaNet + gated attention). Qwen3.8-27B, and Underdog Saluki 27B (Qwen3.8-27B in 7.9 GB, an i-quant mix tuned for tool calling). No model weights are included; scripts/download_models.py fetches them from Hugging Face at pinned revisions, checked by hash.
Formats and platforms
GGUF Q8_0, Q4_K_M, Q5_K_M, Q3_K_M and the i-quant / Q2_K mixes (IQ1_S … IQ4_XS), loaded directly: weights, tokenizer and hyperparameters come from the file. Also qwen3.c's Q8_0 .bin.
Linux (gcc) is the main platform; macOS on Apple Silicon (NEON) builds and runs. The Windows code paths inherited from qwen3.c are kept but untested.
Limitations
From the README and docs/usage.md. Gwenedeg is narrow on purpose.
- Models: Qwen3 dense and dense Qwen3.5 / 3.8 only. No MoE models, no images, no RoPE scaling (YaRN), no other quantization types (Q4_0, Q4_1, IQ4_NL, F16 / BF16 matrices are rejected with a clean error). Qwen3-14B and larger are untested.
- Fast paths need hardware: x86-64 with AVX-512 VNNI (chosen at compile time with
-march=native) and AArch64 with the dot-product extension. Other CPUs run the generic C kernels: the same results, but for K-quant files ~10× slower prefill and ~3–4× slower decode. - CPU only. One model per process (plus its draft for speculation).
- Server: no TLS, no images,
n= 1, no free-form string constraints; tool calls only with the Qwen3.5 / Qwen3.8 templates,tool_choiceauto / none only; the KV memory is a fixed pool of slots, no paging. - Apple Silicon: the NEON port was tested on macOS only; 8 of the tests that compare generated text with goldens recorded on x86 fail there, because the compilers round some Q8_0 sums differently.
- Benchmarks: one 27B comparison against two other engines on one CPU, on a shared VM (see the caveats above). Numbers elsewhere in the repo come from other sessions and are not comparable with it.
Read the source
--repack
docs/kv-quant.mdquantized KV caches, measurements
bench/llamacpp-2026-11-22/raw per-request data of the comparison