ITcompressor IT — compressed and to the point
← Back to articles

Local inference: Qwen3.8-27B on llama.cpp

Why keep a self-hosted LLM stand at all when clouds exist? Three reasons: privacy (code and documents never leave the network), offline/VPN scenarios, and a fixed cost — tokens don't run out. Plus vision tasks, which are handy to run through a local OpenAI-compatible API.

My stand is Qwen3.8-27B on llama.cpp (RTX 3090, 24 GiB VRAM). It is not a «picked by default» choice — the model was selected for a specific resource: maximum context on a single reasonably sized card.

Choosing a model: hybrid architecture instead of squeezing the quant#

A regular 27B model with full attention eats VRAM on the KV cache linearly in context: on 200k tokens an f16 cache doesn't fit anywhere next to the weights. Qwen3.8-27B has a hybrid architecture — most layers (48 of 64) are linear (DeltaNet), with only 16 full attention layers. The KV cache grows with those alone, so:

Component Choice Why
Model Qwen3.8-27B 16 attention layers: a tiny per-token KV cache
Quant UD-IQ4_XS (unsloth, Dynamic 3.0) ~13.3 GiB of weights — fits in 24 GiB along with the context and the projector
Vision mmproj-F16 (0.9 GiB) multimodal projector; without it — text only
KV cache q8_0 200k of context along with the weights; headroom left for activations too
Native context 262k model ceiling; 200k — an operational value with headroom for system prompt and output

Practical conclusion: do the memory math from the KV cache first, then the weights. A model that «fits» with 32k of context doesn't automatically run with 200k — and conversely, architectures with a cheap cache deliver a long context on the same hardware without exotics.

llama-server flags#

The working configuration (OpenAI-compatible /v1):

llama-server \
  -m /opt/llm/models/Qwen3.8-27B-UD-IQ4_XS.gguf \
  --mmproj /opt/llm/models/mmproj-F16.gguf \
  -ngl 999 -c 200000 -fa on \
  -ctk q8_0 -ctv q8_0 \
  --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0 \
  --host 0.0.0.0 --port 8080

What matters here:

  • -ngl 999 — all layers on the GPU (nearly twice the speed of partial offload);
  • -c 200000 — context; the model can't exceed its native ceiling, and there is no need: 200k covers long agent sessions;
  • -fa on — flash attention, saves memory and time on long prompts;
  • -ctk q8_0 -ctv q8_0 — KV cache quantization (f16/q8_0/q4_0): the main lever for long context; q4_0 would squeeze further, but on agent tasks the degradation is more noticeable — q8_0 keeps almost f16 quality;
  • sampling (temp 1.0 / top-p 0.95 / top-k 20 / min-p 0) — Qwen3 defaults for thinking mode; thinking is on by default and controlled per-request (a flag in the request);
  • --host 0.0.0.0 — only where the server is closed from outside networks (a VPN); otherwise use 127.0.0.1 and proxy with authentication.

The vision projector (--mmproj) is optional: without it the model starts as text-only and keeps a bit more context.

Deployment: an idempotent Ansible playbook#

«Deploy from scratch» and «update» are the same run: the playbook stops on-demand competitors for the card (comfyui and the like), checks the driver, builds llama.cpp from the master branch (wiping build/ when CUDA/sm changes — the build is not portable between drivers), downloads the missing models and brings up a systemd service. Idempotency matters more than speed: any re-run at any time must be safe.

---
# llama.cpp + Qwen3.8-27B on the GPU host (RTX 3090, 24 GiB VRAM).
# "Deploy" and "update" are the same run; the playbook is idempotent.
#   ansible-playbook llamacpp.yaml --key-file meta/gpu.key
- name: "llama.cpp + Qwen3.8-27B"
  hosts: [gpu_host]
  become: yes
  vars:
    llamacpp_ref: master             # tracked version: a branch or a tag
    llamacpp_dir: /opt/llama.cpp
    cuda_arch: "86"                  # sm_86 = RTX 3090
    cuda_min_version: "12"           # older — llama.cpp won't build with gcc-11
    models_dir: /opt/llm/models
    hf_url: https://huggingface.co/unsloth/Qwen3.8-27B-GGUF/resolve/main
    llamacpp_models:                 # only the missing ones are downloaded
      - Qwen3.8-27B-UD-IQ4_XS.gguf   # 13.3 GiB — along with 200k of context
      - mmproj-F16.gguf              # 0.9 GiB — the vision projector
    llamacpp_model: "{{ models_dir }}/Qwen3.8-27B-UD-IQ4_XS.gguf"
    llamacpp_mmproj: "{{ models_dir }}/mmproj-F16.gguf"
    llamacpp_ctx: 200000             # the model's native ceiling — 262144
    llamacpp_kv_k: q8_0              # KV-cache quant: f16 / q8_0 / q4_0
    llamacpp_kv_v: q8_0
    llamacpp_port: 8080
    llamacpp_api_key: ""             # empty = no auth (the host is VPN-only)
  tasks:
    - name: "Stop on-demand competitors for the card"
      ansible.builtin.systemd:
        name: "{{ item }}"
        state: stopped
      loop: [comfyui, unsloth]
      ignore_errors: true

    # ... nvidia-smi check → build dependencies (git, cmake, build-essential)
    # → CUDA toolkit 12+ from the NVIDIA repo (if nvcc is older) → clone/pull llama.cpp
    # → wipe build/ when nvcc/sm changes → cmake -DGGML_CUDA=ON → build → models:

    - name: "llama-server service"
      ansible.builtin.copy:
        dest: /etc/systemd/system/llama-server.service
        mode: "0644"
        content: |
          [Unit]
          Description=llama-server (Qwen3.8-27B, llama.cpp)
          After=network-online.target
          Wants=network-online.target

          [Service]
          ExecStart={{ llamacpp_dir }}/build/bin/llama-server \
            -m {{ llamacpp_model }} \
            --mmproj {{ llamacpp_mmproj }} \
            -ngl 999 \
            -c {{ llamacpp_ctx }} \
            -fa on \
            -ctk {{ llamacpp_kv_k }} -ctv {{ llamacpp_kv_v }} \
            --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0 \
            --host 0.0.0.0 --port {{ llamacpp_port }}{% if llamacpp_api_key %} \
            --api-key {{ llamacpp_api_key }}{% endif %}
          Restart=on-failure
          RestartSec=5

          [Install]
          WantedBy=multi-user.target
      notify: "Restart llama-server"

    - name: "Start llama-server"
      ansible.builtin.systemd:
        name: llama-server
        state: started
        enabled: yes
        daemon_reload: yes

    - name: "Wait for the model (/health)"
      ansible.builtin.uri:
        url: "http://127.0.0.1:{{ llamacpp_port }}/health"
      register: llamacpp_health
      until: "llamacpp_health.status == 200"
      retries: 60
      delay: 5

  handlers:
    - name: "Restart llama-server"
      ansible.builtin.systemd:
        name: llama-server
        state: restarted
        daemon_reload: yes

Health is checked via /health — the retries with a delay are needed: a cold start (loading weights + cache warm-up) takes minutes.

Pitfalls#

  • A nvcc/architecture change breaks the build: build/ is not portable between CUDA versions and sm — wipe the directory and let it rebuild.
  • llama.cpp backends change often (flags, model aliases): I follow master, but before updating the stand I skim the changelog — breaking changes in flags and GGUF formats do happen.
  • /v1/models of llama.cpp reports the model id as the full gguf path — clients with direct access will see paths; a proxy level fixes this with auto-aliases (see the hybrid inference article).
  • KV cache quantization is not free: a long context together with an aggressive q4_0 sometimes degrades instruction-following — measure on your own tasks.
  • VRAM competitors (comfyui and other on-demand services) — stop them in the playbook, or use a separate card.

What else this is good for#

A local model is a good «elastic reserve» for a hybrid fleet: when cloud relays are down or the quota is spent, chat/embeddings keep working locally. How it all becomes one API is in the article Hybrid inference: a single endpoint via any-router; the router itself — open binaries from any-router.e7.by.

← Back to articles