Guided tour · 3 of 3
Run it
Linux with gcc is the main platform; macOS on Apple Silicon builds with NEON kernels. You need make, a C compiler and Python 3's standard library for the model download script. The server is POSIX only.
Build and chat
$ git clone https://github.com/j3k0/gwenedeg.git $ cd gwenedeg $ 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?"
Use scripts/download_models.py --list for the other pinned model sets, or pass a supported GGUF you already have.
Serve an OpenAI-compatible API
$ ./gwenedeg serve $G # http://127.0.0.1:8080/v1 $ curl -s localhost:8080/v1/chat/completions \ -H 'Content-Type: application/json' \ -d '{"messages": [{"role": "user", "content": "Hi!"}], "max_tokens": 32}'
The server streams SSE chat completions. It binds 127.0.0.1 with no authentication by default; --api-key KEY or GWENEDEG_API_KEY requires a bearer token.
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
For Qwen4-35B-A3B, use ./launch-server qwen4-35b: it selects the measured 128K context, 8-bit KV cache, MTP and one active sequence. The loader estimates memory before reading weights and refuses with a one-line error if the run does not fit.
Serving notes
Long conversations
A new dense-model request takes the idle slot with the longest common prefix and prefills only the remainder. --kv-disk DIR saves evicted slots and restores them bit-identically, including after a restart.
K and V are Walsh-Hadamard rotated and quantized per 32 dimensions: q8, q4 (8-bit K + 4-bit V), or q4k4 for Qwen3.5 / 3.8.
Agent harnesses
Qwen3.5 / 3.8 tool calls are rendered with the model's chat template and returned as OpenAI tool_calls with typed JSON arguments, streamed too. JSON-schema constraints can force a finite output set without decoding impossible tokens.
The tokenizer matches Hugging Face byte-level BPE, including NFC. Chat templates are built in.
Server limits
- No TLS: keep the server on localhost or a trusted network, or put it behind your own TLS endpoint.
n= 1, no images and no free-form string constraints. Tool calls require Qwen3.5 / 3.8 templates;tool_choicesupports auto / none only.- KV memory is a fixed slot pool, not paged. Qwen4 runs one active sequence and does not support
--kv-disk.
Embed the C library
The CLI and server use only the public API in src/gwenedeg.h. A model is read-only and shared; a sequence owns its tokens, KV cache and sampling state; a compute context owns activation buffers and logits.
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);
Architecture
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, and logits.