← All guides AI Release
RU Subscribe to @ai_releaseorg

How to Run Qwen4 Locally: VRAM Requirements, GGUF Quantization, llama.cpp and Ollama Setup

Updated: 05.12.2026 · AI Release · @ai_releaseorg
How to Run Qwen4 Locally: VRAM Requirements, GGUF Quantization, llama.cpp and Ollama Setup

🤖 AI summary

Which topics does it cover?
Qwen4 запуск локально, Qwen4 VRAM требования, Qwen4 GGUF квантизация →

TL;DR

What you will get

Quick start

huggingface-cli download <hf-repo> <gguf-file> --local-dir ./models
cmake -B build -DGGML_CUDA=ON && cmake --build build --config Release -j
./build/bin/llama-server -m ./models/<gguf-file> -c 8192 -ngl 99 --host 127.0.0.1 --port 8080
curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{"messages":[{"role":"user","content":"Hello"}]}'

Details and checks are in the steps below.

Requirements and setup

Illustration: Requirements and setup
Illustration: Requirements and setup

Check: huggingface-cli whoami prints your username, and nvidia-smi prints a table with your GPU name and total memory.

Step 1. Size the model against your VRAM and pick a quantization

What to do: Compute the memory budget before downloading, then choose the largest quantization that fits.

Why: A GGUF file is loaded almost entirely into VRAM when you offload all layers. If the file plus the context cache exceeds your GPU memory, llama.cpp falls back to system RAM or aborts with an allocation error. Sizing first saves a second download.

The budget is:

VRAM ≈ model file size + KV cache + runtime overhead (~0.5–1 GB for the CUDA/Metal context)
KV cache ≈ 2 × n_layers × n_kv_heads × head_dim × ctx_len × 2 bytes (f16 cache)

Rough file size from the parameter count, for any N-billion-parameter model: 4-bit ≈ 0.5 bytes/parameter, 5-bit ≈ 0.65, 6-bit ≈ 0.75, 8-bit ≈ 1.0. So a 7B model at 4-bit lands near 3.5–4 GB. These are definitional bit-widths, not measured benchmarks.

QuantizationApprox. bytes/paramUse it when
Q8_0~1.0VRAM is plentiful; you want the closest match to the original weights
Q6_K~0.75You have headroom and want better quality than 4-bit
Q5_K_M~0.65The middle ground when Q4_K_M fits but leaves little room for context
Q4_K_M~0.5Default choice for consumer GPUs; best size/quality trade-off
Q3_K_M and below<0.5Only when nothing larger fits — quality drops noticeably

Example: you have a 12 GB GPU. A 4-bit file of about 8 GB leaves roughly 3 GB for the KV cache and overhead — enough for a moderate context, not for a very long one. Verify the real numbers from the file itself.

How to check: load the model with generation disabled and read the metadata llama.cpp prints on startup:

./build/bin/llama-cli -m ./models/<gguf-file> -n 0 2>&1 | grep -E "block_count|head_count_kv|head_count|embedding_length|file type"

You should see lines such as llama_model_loader: - kv ... block_count u32 = <N> and ... head_count_kv .... Put those values into the KV-cache formula above with your intended -c value.

Step 2. Build llama.cpp and start the OpenAI-compatible server

Illustration: Step 2. Build llama.cpp and start the OpenAI-compatible server
Illustration: Step 2. Build llama.cpp and start the OpenAI-compatible server

What to do: Compile llama.cpp with GPU support, then serve the GGUF over HTTP.

Why: llama-server gives you an OpenAI-style endpoint, so existing client code that talks to /v1/chat/completions works by changing only the base URL.

git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
cmake -B build -DGGML_CUDA=ON # macOS: -DGGML_METAL=ON instead
cmake --build build --config Release -j

Start the server:

./build/bin/llama-server \
 -m ./models/<gguf-file> \
 -c 8192 \
 -ngl 99 \
 -fa \
 --host 127.0.0.1 \
 --port 8080

Example: on a machine where the file fits comfortably, the server prints llama server listening at http://127.0.0.1:8080 and stays in the foreground. In a second terminal, curl http://127.0.0.1:8080/health returns {"status":"ok"}.

If you are tuning this on a laptop with a discrete GPU and shared system memory, the layer-offload and context trade-offs are covered in more depth in How to Run a Local LLM on a Ryzen 9 8940HX + RTX 5060 Laptop.

How to check: send a real completion and confirm you get text back:

curl -s http://127.0.0.1:8080/v1/chat/completions \
 -H "Content-Type: application/json" \
 -d '{"model":"local","messages":[{"role":"user","content":"Reply with the word: ready"}],"max_tokens":16}'

Expected: JSON containing "choices" with a message.content field. In parallel, nvidia-smi should show the llama-server process holding VRAM close to your calculated budget.

Step 3. Import the same GGUF into Ollama and verify GPU offload

Illustration: Step 3. Import the same GGUF into Ollama and verify GPU offload
Illustration: Step 3. Import the same GGUF into Ollama and verify GPU offload

What to do: Create a Modelfile that points at the GGUF you already downloaded, register it locally, and check that Ollama runs it on the GPU.

Why: Ollama manages the server, model registry and context for you, which is convenient for scripting. Importing from a local file avoids downloading the weights a second time.

Create a file named Modelfile in the directory that contains your GGUF:

FROM ./models/<gguf-file>
PARAMETER num_ctx 8192
PARAMETER num_gpu 99
PARAMETER temperature 0.7

num_ctx sets the context window, num_gpu 99 requests full GPU offload, and temperature controls sampling randomness. Then register and run it:

ollama create qwen4-local -f Modelfile
ollama run qwen4-local "Reply with the word: ready"

Example: the first command prints progress lines and ends with success. The second prints the model's answer to your prompt and drops you into an interactive session (exit with /bye).

How to check:

ollama ps

Expected: a row for qwen4-local with a SIZE column and a PROCESSOR column reading 100% GPU. If it says 100% CPU, the offload did not happen — see Troubleshooting. The API check is:

curl -s http://127.0.0.1:11434/api/generate \
 -d '{"model":"qwen4-local","prompt":"Say: ready","stream":false}'

Expected: JSON with a "response" field containing the answer.

Checklist before you call it done:

Troubleshooting

Problem. The server dies during model load with an allocation failure

Problem. The model refuses to load after a fresh build

Problem. Ollama rejects the model name or the import

Summary and next steps

You now have the same Qwen4 GGUF served two ways — llama-server on port 8080 and Ollama on port 11434 — with a VRAM budget you can recompute for any context length or quantization. Next, wire one of these endpoints into your client code by pointing the base URL at http://127.0.0.1:8080/v1 and keeping the API key field set to any non-empty string.

FAQ

How much VRAM do I need to run Qwen4 locally?

It depends on the parameter count and the quantization you pick. Compute it: file size + KV cache (2 × layers × kv-heads × head-dim × context × 2 bytes) + roughly 1 GB of runtime overhead. Read the real layer and head counts from the load log as shown in Step 1, and take the file size from the Hugging Face repo listing.

Does Ollama have an official Qwen4 model?

Check ollama.com/library before assuming. If there is no entry, download the GGUF yourself and import it with a Modelfile as in Step 3 — that path works with any GGUF file.

Is Q4_K_M good enough, or should I use Q8_0?

Use the largest quantization that fits in your VRAM with room for the context you need. Q8_0 is about twice the size of Q4_K_M for the same model, so on consumer GPUs Q4_K_M is usually the practical choice.

Can I run it without a GPU?

Yes — build without CUDA/Metal and leave -ngl 0. It works, but tokens per second drop sharply, so prefer a smaller quantization and a smaller context.

🤖 AI summary

AI Release Knowledge Layer
Machine-readable description · Version 1.0

Status: practical guide. Some statements come from vendors; verify in your environment.

1. Summary

Time to complete: 45–60 minutes (most of it is the llama.cpp build and the model download) Difficulty: Intermediate

Inside: direct answers, key facts, entities, context, reliability, unknowns and sources.

Machine data: Citation Map JSON · JSON-LD · Semantic Embeddings — separate stage.

Full Knowledge Layer: sections 2–8

2. Direct answers

What is required?
OS: Linux or macOS (the commands below are bash). On Windows use WSL2 or adjust the paths to .\build\bin\llama-server.exe.; GPU: NVIDIA with a current driver — verify with nvidia-smi; or Apple Silicon. A CPU-only run works but is slow, so plan a smaller quantization.; Build tools: cmake, make or ninja, and a C++17… → details (AR-GUIDE-KAKZAPUSTI-003)
How to do it?
Step 1. Size the model against your VRAM and pick a quantization → Step 2. Build llama.cpp and start the OpenAI-compatible server → Step 3. Import the same GGUF into Ollama and verify GPU offload → details (AR-GUIDE-KAKZAPUSTI-004)
Which topics does it cover?
Qwen4 запуск локально, Qwen4 VRAM требования, Qwen4 GGUF квантизация → details (AR-GUIDE-KAKZAPUSTI-002)
What are the key points?
Time to complete: 45–60 minutes (most of it is the llama.cpp build and the model download) Difficulty: Intermediate → details (AR-GUIDE-KAKZAPUSTI-007)

3. Key facts

  1. Time to complete: 45–60 minutes (most of it is the llama.cpp build and the model download) — evidence; status: заявление источника.
  2. Difficulty: Intermediate — evidence; status: заявление источника.
  3. You will need: a machine with a discrete GPU (NVIDIA with CUDA, or Apple Silicon with Metal), Python 3 with huggingface-cli, git, cmake + a C++ compiler, Ollama, and the Qwen4 GGUF file from its Hugging Face repository — evidence; status: заявление источника.
  4. OS: Linux or macOS (the commands below are bash). On Windows use WSL2 or adjust the paths to .\build\bin\llama-server.exe. — evidence; status: заявление источника.
  5. GPU: NVIDIA with a current driver — verify with nvidia-smi; or Apple Silicon. A CPU-only run works but is slow, so plan a smaller quantization. — evidence; status: заявление источника.
  6. Build tools: cmake, make or ninja, and a C++17 compiler. Check with cmake --version. — evidence; status: заявление источника.

4. Entities

EntityTypeRole
Qwen4 запуск локальнопродукт/модельупоминается в заголовке, TL;DR или разделах гайда
Qwen4 VRAM требованияпродукт/модельупоминается в заголовке, TL;DR или разделах гайда
Qwen4 GGUF квантизацияпродукт/модельупоминается в заголовке, TL;DR или разделах гайда
CUDAплатформа/технологияупоминается в заголовке, TL;DR или разделах гайда
Pythonплатформа/технологияупоминается в заголовке, TL;DR или разделах гайда
Gitплатформа/технологияупоминается в заголовке, TL;DR или разделах гайда
OpenAIкомпанияупоминается в заголовке, TL;DR или разделах гайда
Appleкомпанияупоминается в заголовке, TL;DR или разделах гайда
NVIDIAкомпанияупоминается в заголовке, TL;DR или разделах гайда
Hugging Faceкомпанияупоминается в заголовке, TL;DR или разделах гайда

5. Context

  • Guide — describes → How to Run Qwen4 Locally: VRAM Requirements, GGUF Quantization, llama.cpp and Ollama Setup (AR-GUIDE-KAKZAPUSTI-001).
  • Guide — includes step → Step 1. Size the model against your VRAM and pick a quantization (AR-GUIDE-KAKZAPUSTI-001).

6. Reliability

Confirmed

No independent confirmation is provided; source claims and editorial conclusions are separated below.

Source claims

  • Product features, versions, prices and limits come from vendors and the guide.
  • Commands and steps are recommendations, not guaranteed results.

AI Release analysis

  • Structure, comparison and selection criteria are editorial.
  • The guide does not replace an independent audit or legal advice.

7. Unknowns

  • Current versions, prices and limits.
  • Independent benchmarks and quality checks.
  • Terms of use and data policy.

8. Sources

SourceTypeRole
github.comвнешний источникссылка из тела гайда

Cite as: AI Release. Как запустить Qwen4 локально: требования к VRAM, квантизация GGUF и настройка в llama.cpp и Ollama. ai-release.org.