# Qwen3.5-4B-3D-Coder, tuned for decode speed

A 4B three.js scene writer that fits in VRAM at any quant. Q5_K_M without speculation ships at 77.5 tok/s task-weighted, 1.28x the Q8_0 baseline; the restored MTP head reaches 101.7 and stays opt-in.

- Recipe id: `qwen35-3d-coder`  ·  status: measured  ·  updated 2026-11-22
- Model: [Qwen3.5-4B-3D-Coder](https://huggingface.co/ccore/Qwen3.5-4B-3D-Coder) (4B dense hybrid, 32 layers: 8 full-attention and 24 Gated DeltaNet)
- Weights: GGUF Q5_K_M, from https://huggingface.co/ccore/Qwen3.5-4B-3D-Coder, revision `4b9f05f`
- Engine: [llama.cpp](https://github.com/ggml-org/llama.cpp) b12242 (3b4d6ab3f); CUDA 12.8
- Hardware: NVIDIA GeForce RTX 3060 12 GB, 62 GB RAM, Intel Core i5-12500, NVMe SSD
- Context: 65,536 tokens
- Placement: Everything in VRAM (7.1 GB of the card while serving at 64k).
- Contributor: [David Hatley](https://github.com/davidghatley)

## Run it

From `qwen35-3d-coder/` in a clone of https://github.com/davidghatley/3060-recipes:

```sh
tools/download.sh && tools/build_quants.sh && ./serve.sh
```

API: OpenAI-compatible on port 8083

Key flags: `-ngl 99 -fa on -ctk f16 -ctv f16`, `-c 65536 -np 1`, `-ub 2048`, `no speculation by default; QC_SPEC=draft-mtp to opt in`, `sampling from the model card: T 0.6, top-p 0.95, top-k 20`

The script itself (`qwen35-3d-coder/serve.sh`, machine paths shown as `$MODELS`, `$SCRATCH`, `~`; set them to where your weights and builds live):

```sh
#!/usr/bin/env bash
# Qwen3.5-4B-3D-Coder on llama-server, tuned for single-user decode on the RTX 3060. Evidence: PLAN.md, RESULTS.md.
# Weights: our Q5_K_M with the MTP head restored (tools/download.sh + tools/build_quants.sh).
# Q4_K_M is faster but its pages throw errors twice as often in the render eval (RESULTS.md).
# Speculation is off by default: MTP is 1.41x faster on real answers and its pages pass as often, but more of its
# finished pages fail on syntax errors (RESULTS.md, "Does MTP break long answers?"). Opt in with QC_SPEC=draft-mtp.
set -euo pipefail
BIN=${QC_BIN:-$SCRATCH/llama.cpp/b12242/bin/llama-b12242}
MODEL=${QC_MODEL:-$MODELS/qwen3.5-4b-3d-coder/own/Qwen3.5-4B-3D-Coder-MTP-Q5_K_M.gguf}
CUDA_LIB=${QC_CUDA_LIB:-$SCRATCH/llama.cpp/b12242/cudart/cudart-llama-b12242-bin-ubuntu-cuda-12.8-x64}
export LD_LIBRARY_PATH="$BIN:$CUDA_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export GPU_RUN_MEM=${GPU_RUN_MEM:-24G}
UB=${QC_UBATCH:-2048}
exec "$HOME/anime-pipeline/tools/gpu_run" --need 7000 --wait "${QC_GPU_WAIT:-120}" \
  "$BIN/llama-server" -m "$MODEL" --alias qwen35-3d-coder \
  -ngl 99 -fa on -ctk f16 -ctv f16 -c "${QC_CONTEXT:-65536}" -np 1 -b "$UB" -ub "$UB" \
  --spec-type "${QC_SPEC:-none}" --spec-draft-n-max "${QC_DRAFT_MAX:-2}" --spec-draft-p-min "${QC_DRAFT_PMIN:-0}" \
  --jinja --reasoning-format deepseek \
  --temp 0.6 --top-p 0.95 --top-k 20 --repeat-penalty 1.0 \
  --host 127.0.0.1 --port "${QC_PORT:-8083}" "$@"
```

## Measured results

| Metric | Conditions | Value | Stock | Ceiling | Source |
|---|---|---|---|---|---|
| decode | task-weighted (55% reasoning, 45% writing code) | 77.5 tok/s | 60.6 |  | [qwen35-3d-coder/RESULTS.md:34](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L34) |
| decode | while reasoning | 80.7 tok/s | 62.5 |  | [qwen35-3d-coder/RESULTS.md:34](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L34) |
| decode | while writing the page | 74.0 tok/s | 58.3 |  | [qwen35-3d-coder/RESULTS.md:34](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L34) |
| decode | opt-in: restored MTP head, n=2, task-weighted | 101.7 tok/s | 60.6 |  | [qwen35-3d-coder/RESULTS.md:36](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L36) |
| decode | Q4_K_M without speculation (rejected: fails the render eval) | 84.8 tok/s | 60.6 |  | [qwen35-3d-coder/RESULTS.md:33](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L33) |
| prefill | 32k prompt, 12.9 s | 2480 tok/s |  |  | [qwen35-3d-coder/RESULTS.md:43](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L43) |
| prefill | 62k prompt, 29.9 s | 2070 tok/s |  |  | [qwen35-3d-coder/RESULTS.md:43](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L43) |
| vram_peak | whole card while serving, no speculation (8.0 with MTP) | 7.1 GB |  |  | [qwen35-3d-coder/RESULTS.md:150](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L150) |
| quality | mean KL divergence, Q5_K_M | 0.00732 KLD |  |  | [qwen35-3d-coder/RESULTS.md:85](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L85) |
| quality | render eval: pages that work out of 20 (Q8_0: 10, Q4_K_M: 5) | 9 pages |  |  | [qwen35-3d-coder/RESULTS.md:51](https://github.com/davidghatley/3060-recipes/blob/main/qwen35-3d-coder/RESULTS.md#L51) |

## Caveats

- MTP is opt-in. No engine bug was found and the page pass rate is the same (10/16 vs 9/16), but 5 of 19 finished MTP pages failed on syntax errors against 0 of 35 without speculation; the cause is unknown and may be chance.
- Q4_K_M is faster but 62% of its finished pages throw an error.
- DFlash is the fastest while writing code (163 tok/s) and loses while reasoning (acceptance 4-7%), so it is not used.
- The decode baseline is the official Q8_0 without speculation.

## Findings from this recipe

- [The desktop session holds about 0.95 GB of the card and that decides several fits](https://davidghatley.github.io/3060-recipes/findings/desktop-holds-a-gigabyte-of-vram.md)
- [A port-based health check can be answered by someone else's server](https://davidghatley.github.io/3060-recipes/findings/health-check-answered-by-another-server.md)
- [A one-sample-per-prompt check wrongly blamed an engine bug for MTP failures](https://davidghatley.github.io/3060-recipes/findings/one-sample-per-prompt-misled-on-mtp.md)
- [On a small all-VRAM model decode is already at 74-93% of the bandwidth ceiling](https://davidghatley.github.io/3060-recipes/findings/custom-cuda-kernel-not-worth-it-yet.md)
- [A drafter trained on the base model loses on a fine-tune that reasons tersely](https://davidghatley.github.io/3060-recipes/findings/dflash-loses-on-a-terse-finetune.md)
- [Greedy-output identity is the wrong quality gate when placement changes](https://davidghatley.github.io/3060-recipes/findings/greedy-hash-is-the-wrong-gate.md)
- [Q4_K_M is the fastest 3D-coder quant and breaks twice as many pages](https://davidghatley.github.io/3060-recipes/findings/q4-k-m-breaks-generated-pages.md)
- [A fine-tune that dropped its MTP head can take the base model's head back](https://davidghatley.github.io/3060-recipes/findings/restore-a-finetunes-missing-mtp-head.md)
- [q8_0 KV costs 29% decode at 32k on a model with few full-attention layers](https://davidghatley.github.io/3060-recipes/findings/q8-kv-slows-decode-with-few-attention-layers.md)

## Credits

- ccore: The fine-tune we serve; the render eval's prompts come from the dataset's validation split. (https://huggingface.co/ccore/Qwen3.5-4B-3D-Coder)
- Qwen: The 15 mtp.* tensors grafted back into the 3D coder came from Qwen3.5-4B; Kintsugi-27B is built on Qwen3.8-27B. (https://huggingface.co/Qwen/Qwen3.5-4B)
- z-lab: Measured against MTP on the 3D coder: fastest while writing code (163 tok/s), not used because acceptance falls to 4-7% while reasoning. (https://huggingface.co/z-lab/Qwen3.5-4B-DFlash)
- llama.cpp (ggml-org and contributors): The engine for Flint, the 3D coder and Inkling-2-Mini, and the base of the Kintsugi fork. (https://github.com/ggml-org/llama.cpp)
- ggml-org: Flint-Q4_K_M.gguf and Inkling-2-Mini-IQ4_NL.gguf are the files the two recipes serve; the Q8_0 files are the KLD references. (https://huggingface.co/ggml-org/Flint-GGUF)
- Hugging Face: Every model, quant and drafter in these recipes is fetched from the Hub at a pinned revision and checked against the API's sha256; the base model's MTP tensors were fetched with HTTP range requests. (https://huggingface.co)
- NVIDIA: Every recipe runs on CUDA on this card; cuBLAS SGEMV is our VRAM bandwidth probe (342 GB/s), nvidia-smi dmon is the telemetry, and Inkling's experts ship in NVFP4. (https://www.nvidia.com/en-us/geforce/graphics-cards/30-series/rtx-3060-3060ti/)

## Reproductions

None yet. Ran it on your own 3060? Report your numbers: https://github.com/davidghatley/3060-recipes/issues/new?template=reproduction.yml

## Machine-readable

- https://davidghatley.github.io/3060-recipes/recipes/qwen35-3d-coder/recipe.json
- Folder with scripts and raw runs: https://github.com/davidghatley/3060-recipes/tree/main/qwen35-3d-coder
- Full results log: https://raw.githubusercontent.com/davidghatley/3060-recipes/main/qwen35-3d-coder/RESULTS.md

## Full write-up (README)

Serving [ccore/Qwen3.5-4B-3D-Coder](https://huggingface.co/ccore/Qwen3.5-4B-3D-Coder) as fast as possible on the RTX 3060 12 GB.
The model is a Qwen3.5-4B fine-tune that reasons, then writes a complete three.js page.

It fits in VRAM at any quant. So this recipe is about decode speed on a model that already fits:

- choosing a quant;
- bringing back the base model's multi-token-prediction (MTP) head, which the release dropped;
- tuning speculation for a task that switches from prose (reasoning) to code.

Numbers, the quality eval and the CUDA-kernel analysis are in [RESULTS.md](RESULTS.md). The experiment log is [PLAN.md](PLAN.md). Raw data is in `runs/`.

### Result

| Single user, 64k context | Q8_0 official, no speculation | **This recipe: Q5_K_M** |
|---|---:|---:|
| Decode while reasoning | 62.5 tok/s | **80.7 tok/s** |
| Decode while writing the page | 58.3 tok/s | **74.0 tok/s** |
| Task-weighted decode | 60.6 tok/s | **77.5 tok/s (1.28×)** |
| Prefill, 32k prompt | | 12.9 s (2,480 tok/s) |
| KL divergence vs F16 | 0.001 | 0.007 |
| Render eval, pages that work (20 prompts) | 10 | 9 |

The restored MTP head takes Q5_K_M to **101.7 tok/s (1.68×)** on the speed sessions, and 105.7 vs 75.0 tok/s median on real 8-prompt answers. It is opt-in, not the default. Its first check, one answer per prompt, failed (1 page of 8 worked against 6) and looked like an engine bug in rolling back DeltaNet state. The follow-up did not bear that out. MTP's state matches a clean prefill through 12k tokens. It loops no more often (0/16 vs 2/16 on the prompts that looped). With 2 seeds on the same 8 prompts, 10/16 pages worked against 9/16. What keeps it off by default: 5 of its 19 finished pages failed on syntax errors (mostly a name declared twice), against 0 of 35 for Q5_K_M without speculation. A re-score of every token on a no-spec server found nothing MTP picked that plain decoding couldn't (2 of 116k tokens vs 2 of 103k), so the excess has no known cause and may be chance; a default change waits for a render comparison sized to settle it (RESULTS.md, "Does MTP break long answers?"). To use it: `QC_SPEC=draft-mtp ./serve.sh`.

Q4_K_M is faster again (84.8 tok/s without speculation), but 62% of its finished pages threw errors (`THREE.Object33D`, duplicate declarations), and it passed 5 of 20 prompts.

### Use it

```bash
tools/download.sh       # pinned GGUFs, base-model MTP tensors, DFlash drafter, eval data (sha256-checked)
tools/build_quants.sh   # CPU only: graft the MTP head, convert to F16, quantize Q8_0/Q6_K/Q5_K_M/Q4_K_M
./serve.sh              # llama-server on 127.0.0.1:8083 through gpu_run, OpenAI-compatible
```

The defaults in `serve.sh` are:

- our Q5_K_M (the file carries the MTP head, unused unless `QC_SPEC=draft-mtp`);
- no speculation;
- `-fa on`, f16 KV, 64k context, one slot;
- `-ub 2048`;
- the model card's sampling (T 0.6, top-p 0.95, top-k 20).

Overrides: `QC_MODEL` (e.g. our Q4_K_M for 5% more speed and more broken pages), `QC_SPEC=draft-mtp`, `QC_DRAFT_MAX`, `QC_CONTEXT`, `QC_PORT`.

### Why the MTP head had to be restored

The config declares `mtp_num_hidden_layers: 1`, but the released safetensors (723 tensors) and the official GGUFs (`nextn_predict_layers = 0`) have no MTP weights.

`tools/fetch_mtp.py` fetches the 15 `mtp.*` tensors of base [Qwen/Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B) with HTTP range requests (241 MB). `tools/make_src.py` then adds them to the fine-tune's checkpoint. llama.cpp's converter turns that into `blk.32.nextn.*`.

The base head was never trained on the fine-tune's hidden states. Even so, it is accepted 86% of the time while the model writes code. While it reasons, the rate drops to 37%. The speed-up is real; the output-quality problem above has to be fixed in the engine before it can ship.

### Tools

| Script | What it does |
|---|---|
| `tools/ceiling.py` | per-category bytes per token and the decode ceiling of a GGUF |
| `tools/gpubw.py` | VRAM bandwidth probe (cudart memcpy + cuBLAS SGEMV), no nvcc needed |
| `tools/benchsession.sh` | a plan of llama-bench runs inside one `gpu_run` session, with telemetry |
| `tools/ab.py` | llama-server A/B sessions with interleaved controls, appended to `runs/ledger.jsonl` |
| `tools/ledger_summary.py` | per-config medians and the task-weighted rate |
| `tools/kld.sh` | KL divergence of every quant against our F16 on held-out answers |
| `tools/evalrun.sh`, `gen.py`, `render.mjs`, `score.py` | the render eval: generate, render in headless Chromium on the CPU (SwiftShader), score |
| `tools/qualify.sh` | acceptance gates for `serve.sh`: chat, scenes (`--scene-only --ids`), needles at 32k and 62k |
| `tools/eval_table.py`, `loop_check.py` | side-by-side render-eval table; flags answers that loop |

### Credits

- llama.cpp b12242 for the engine, the converter, MTP and DFlash.
- The model's author ccore, for the fine-tune and the [ThreeJS-3D-Scenes](https://huggingface.co/datasets/ccore/ThreeJS-3D-Scenes) dataset. The eval prompts come from its validation split.
- Qwen, for the Qwen3.5-4B base model and its MTP head.
- z-lab, for the [Qwen3.5-4B-DFlash](https://huggingface.co/z-lab/Qwen3.5-4B-DFlash) drafter.

### The race video

`promo/` holds a side-by-side time-lapse: the same prompt (a voxel bonsai) sent to the Q8_0 baseline and the tuned Q5_K_M server, each scene growing mesh by mesh as its code streams in. Both sides run on one clock at the same speed-up, so the gap at the finish is the real gap.

- `promo/session.sh` + `promo/capture.py` stream each answer with per-chunk timestamps into `promo/captures/<prompt>/`.
- `promo/tools/buildseq.mjs` replays each page in headless Chromium and saves a frame per batch of meshes; `promo/tools/prep.py` maps every mesh to the moment its code arrived.
- `promo/src/Race.tsx` is the Remotion composition (render with the Flint promo's `node_modules`).

The two quants write different code from the same seed, so the pages differ. The bonsai pair was picked because the token counts are close (14,097 stock, 15,213 tuned), so the finish gap understates the decode speedup rather than inflating it.
