Skip to content

Instantly share code, notes, and snippets.

@ryan4yin
Last active August 29, 2026 06:16
Show Gist options
  • Select an option

  • Save ryan4yin/19db9fa44972c5735c1d181e8888d4fe to your computer and use it in GitHub Desktop.

Select an option

Save ryan4yin/19db9fa44972c5735c1d181e8888d4fe to your computer and use it in GitHub Desktop.
Qwen3.8-27B best llama.cpp config on RTX 4090 24GB (BeeLlama, UD-Q4_K_XL v3.0, kvarn6 + kv-tail 2048 @ 165K, MTP n-max 3, fit off)

Best llama.cpp config for Qwen3.8-27B (RTX 4090 24GB)

Quality-first setup (current 2026-08-28, matches docker-compose.qwen3.8-27b-xl.yml), measured on:

  • CPU: Intel Core Ultra 7 270K Plus (24C/24T, no HT)
  • RAM: 96GB DDR5-5600 (2x48GB dual channel, ≈89.6 GB/s theoretical bandwidth)
  • GPU: RTX 4090 24GB Use the BeeLlama fork image (server-cuda13-v0.4.3) — mainline llama.cpp silently falls back to CPU for non-q4 KV caches on Qwen3.x hybrid architecture (no error is reported).

Recommended config

docker run -d --name llama-server \
  --gpus all --shm-size=1gb -p 8001:8001 \
  -v "$PWD/models:/models" \
  ghcr.io/anbeeld/beellama.cpp:server-cuda13-v0.4.3 \
  --model /models/unsloth/Qwen3.8-27B-GGUF/Qwen3.8-27B-UD-Q4_K_XL.gguf \
  --mmproj /models/unsloth/Qwen3.8-27B-GGUF/mmproj-F16.gguf \
  --alias Qwen3.8-27B \
  --ctx-size 165000 \
  --cache-type-k kvarn6 --cache-type-v kvarn6 \
  --kv-tail-tokens 2048 \
  --fit off \
  --flash-attn on \
  --n-gpu-layers auto \
  --load-mode mmap \
  --cont-batching \
  --host 0.0.0.0 --port 8001 \
  --metrics \
  --spec-type draft-mtp --spec-draft-n-max 3 \
  --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0 --presence-penalty 0.0 \
  --image-max-tokens 4000 --image-min-tokens 1024 \
  --reasoning-budget 4000 \
  --chat-template-kwargs '{"reasoning_effort": "low"}' \
  --reasoning-preserve \
  --reasoning-budget-message "... reasoning budget exceeded, need to answer.\n"

Model: unsloth/Qwen3.8-27B-GGUF (UD-Q4_K_XL mixed precision v3.0 + mmproj-F16), download links at the bottom.

Why these flags

Flag Reason
UD-Q4_K_XL (v3.0) dynamic mixed-precision quant; v3.0 update shrank it ~364MB, buying +35K ctx at the same VRAM
kvarn6/kvarn6 KVarN supersedes stock quants: better quality at the same VRAM
--kv-tail-tokens 2048 last 2K tokens kept full-precision F16 (~55 MiB); fixes "attention drift / missing details" in long contexts
--ctx-size 165000 150K/160K/165K pass restorable-continuation tests (fill to ~97%); 170K crashes during prefill (flash-attn kvarn segfault)
--fit off CUDA graphs conflict with MTP draft; fit on randomly drops speed to 9–20 t/s
MTP n-max 3 measured best: n=1 → 60 t/s, n=2 → 37 t/s, n=3 → best
--flash-attn on required for quantized V, loader refuses otherwise
mmap / n-gpu-layers auto BeeLlama has no auto load mode
temp/top_p/top_k/min_p thinking-mode sampling recommended by unsloth
reasoning budget/preserve effort low keeps thinking short; preserve keeps multi-turn thinking context

Typical performance

Both read from response timings (prompt_n/prompt_ms, predicted_n/predicted_ms), not completion_tokens / total time (dragged down by prefill). Prefill numbers are measured on closely matching KV settings (kvarn5/kvarn6 prefill differ by <5%); TTFT ≈ input tokens / prefill (160K input ≈ 100 s).

Input ctx Prefill Decode
<32K (typical use) ~2400-2500 t/s ~60-70 t/s
160K (~97% fill) ~1500-1600 t/s 41-47 t/s

Context ceiling: 150K/160K/165K pass restorable-continuation tests (~97% fill); 170K crashes during single-shot prefill (flash-attn kvarn segfault).

Pitfalls (all hit in practice)

  • BeeLlama required: non-q4 KV on mainline = silent CPU fallback (GPU 0–30%).
  • f16/bf16 KV + 27B on 24GB OOMs outright.
  • OOM depends on request batch shape, not just ctx depth: a restorable-prefix multi-turn continuation (KV only 66.8K) can OOM even when a 150K prefill passes. Validate ctx ceilings with restorable-continuation traffic, not single-shot prefill.
  • Throughput: read response timings (predicted_n/predicted_ms), not completion_tokens / total time (dragged down by prefill).

KV quant selection: Anbeeld benchmarks · llama.cpp #23470 · BeeLlama

Model download

ModelScope (best for China, much faster than HF mirror):

modelscope download --model unsloth/Qwen3.8-27B-GGUF --local_dir models/unsloth/Qwen3.8-27B-GGUF \
  Qwen3.8-27B-UD-Q4_K_XL.gguf mmproj-F16.gguf

# direct URLs:
# https://modelscope.cn/models/unsloth/Qwen3.8-27B-GGUF/resolve/master/Qwen3.8-27B-UD-Q4_K_XL.gguf
# https://modelscope.cn/models/unsloth/Qwen3.8-27B-GGUF/resolve/master/mmproj-F16.gguf

Hugging Face:

hf download unsloth/Qwen3.8-27B-GGUF --local-dir models/unsloth/Qwen3.8-27B-GGUF \
  --include "Qwen3.8-27B-UD-Q4_K_XL.gguf" --include "mmproj-F16.gguf"

# direct URLs:
# https://huggingface.co/unsloth/Qwen3.8-27B-GGUF/resolve/main/Qwen3.8-27B-UD-Q4_K_XL.gguf
# https://huggingface.co/unsloth/Qwen3.8-27B-GGUF/resolve/main/mmproj-F16.gguf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment