Run Ollama for Qwen3 or Qwen2.5-Coder when one developer works on a laptop, Mac, or single consumer GPU and wants a quantized model running in under a minute. Run vLLM when a server with 24 GB, 48 GB, or multiple NVIDIA or AMD GPUs serves concurrent coding agents, API backends, or shared team traffic where continuous batching and PagedAttention keep throughput from collapsing. Both expose an OpenAI-compatible API, so application code can stay identical while the runtime changes underneath.
The choice comes down to execution model rather than model quality alone. Ollama wraps a GGUF-based engine optimized for fast startup, automatic model unloading, and single-machine convenience. vLLM runs Hugging Face Safetensors and GPU-native quantizations with paged KV memory, prefix caching, and tensor parallelism across multiple GPUs. For broader server comparisons that also include llama-server, see the local LLM inference servers guide.
Model formats: GGUF vs Safetensors and GPU quantizations
Weight format is the first architectural fork when serving Qwen models locally.
Ollama pulls pre-packaged GGUF blobs from its registry, such as qwen3:8b, qwen3:32b, or qwen2.5-coder:32b. Most default library tags ship in Q4_K_M 4-bit quantization, while explicit tags expose Q8_0 or FP16. GGUF packs mixed-precision integer weights into a single file designed for fast loading and partial CPU-GPU layer splitting. When a 32B Q4_K_M model (~20 GB) runs on a 16 GB laptop or a 24 GB GPU with a long prompt, Ollama can spill overflow layers into system RAM over PCIe or unified memory. You still get an answer, even if generation slows down to memory-bus speed.
vLLM reads Hugging Face repositories in Safetensors format alongside GPU-first quantizations: BF16, FP8, AWQ, GPTQ, and compressed-tensors. It expects the full working set—weights plus KV cache allocation—to reside in accelerator VRAM unless you explicitly configure CPU swap space for preemption. On Ada Lovelace, Hopper, or Blackwell GPUs, FP8 cuts 16-bit weights roughly in half with native tensor-core execution, while AWQ packs 4-bit weights into ~18-19 GB for a 32B checkpoint so it fits on a 24 GB or 48 GB card with high kernel throughput.
# Ollama: pull and run a 4-bit Qwen3 or Qwen2.5-Coder build
ollama pull qwen3:8b
ollama run qwen2.5-coder:32b-instruct-q4_K_M
# vLLM: serve native BF16 or quantized AWQ/FP8 Safetensors
vllm serve Qwen/Qwen3-8B \
--host 127.0.0.1 --port 8000 \
--dtype auto
vllm serve Qwen/Qwen2.5-Coder-32B-Instruct-AWQ \
--host 127.0.0.1 --port 8000 \
--quantization awq_marlin \
--max-model-len 32768
Avoid running GGUF files inside vLLM. The vLLM documentation treats GGUF support as experimental and secondary to Safetensors, AWQ, and FP8 kernels. If your hardware constraint requires GGUF and CPU offloading, Ollama or llama.cpp is the right runtime.
KV cache VRAM math for 32K to 128K context
Qwen3 and Qwen2.5-Coder support long context windows—32,768 tokens natively on standard setups and up to 131,072 tokens with RoPE scaling—which makes KV cache sizing the main source of out-of-memory errors. Every active sequence stores key and value tensors across every layer and token:
KV bytes per token = 2 × num_hidden_layers × num_key_value_heads × head_dim × bytes_per_value
Both Qwen3-8B (36 layers, 8 KV heads via GQA, 128 head dimension) and Qwen3-32B / Qwen2.5-Coder-32B (64 layers, 8 KV heads, 128 head dimension) use Grouped-Query Attention, which shrinks the cache compared to older multi-head models, yet 128K contexts still consume tens of gigabytes:
- Qwen3-8B (16-bit KV cache):
2 × 36 × 8 × 128 × 2 = 147,456 bytes = 144 KiB/token. One 32K sequence takes4.5 GiB, and one 128K sequence takes18.0 GiB. - Qwen3-32B or Qwen2.5-Coder-32B (16-bit KV cache):
2 × 64 × 8 × 128 × 2 = 262,144 bytes = 256 KiB/token. One 32K sequence takes8.0 GiB, and one 128K sequence takes32.0 GiB. - With 8-bit KV cache (
fp8/q8_0): Those numbers drop by half to2.25 GiB(8B at 32K) and16.0 GiB(32B at 128K), subject to accuracy validation on coding benchmarks.
Here is where Ollama and vLLM diverge sharply in memory reservation. As the Ollama FAQ explains, Ollama's KV memory footprint scales statically as OLLAMA_NUM_PARALLEL × OLLAMA_CONTEXT_LENGTH. If you set OLLAMA_CONTEXT_LENGTH=65536 and OLLAMA_NUM_PARALLEL=4 for qwen3:8b, Ollama reserves memory for four full 64K slots—36 GiB of KV cache alone—even when every user sends a 500-token prompt. Always verify actual allocation with ollama ps.
vLLM uses PagedAttention to allocate KV cache in fixed-size blocks on demand. After loading model weights, vLLM claims the fraction specified by --gpu-memory-utilization (default 0.90) and turns every remaining megabyte into a shared block pool. Short 2K prompts only consume 2K worth of blocks, leaving room for dozens of concurrent IDE completions while still allowing an occasional 32K repository summary without wasting idle memory.
# Ollama: cap context and parallel slots to fit a 24 GB GPU
OLLAMA_HOST=127.0.0.1:11434 \
OLLAMA_CONTEXT_LENGTH=32768 \
OLLAMA_NUM_PARALLEL=2 \
OLLAMA_KV_CACHE_TYPE=q8_0 \
OLLAMA_FLASH_ATTENTION=1 \
ollama serve
# vLLM: 48 GB server with FP8 KV cache and prefix caching for coding agents
vllm serve Qwen/Qwen3-32B-FP8 \
--host 127.0.0.1 --port 8000 \
--max-model-len 65536 \
--max-num-seqs 32 \
--kv-cache-dtype fp8 \
--enable-prefix-caching \
--gpu-memory-utilization 0.92
Notice --enable-prefix-caching on vLLM: when an agent or IDE plugin sends the same system prompt and repository tree repeatedly, vLLM reuses the computed KV blocks for the shared prefix instead of recomputing prefill from scratch. For deeper hardware sizing across 24 GB, 48 GB, and multi-GPU nodes, read the local LLM hardware guide.
Qwen tool calling and OpenAI compatibility
Agentic workflows depend on deterministic function calls and valid JSON schemas. Both runtimes accept OpenAI-format tools on /v1/chat/completions, yet their defaults differ.
Ollama parses tool calls using template definitions embedded inside each library model's Modelfile. On official qwen3 and qwen2.5-coder tags, /v1/chat/completions and /api/chat support tools out of the box when the prompt stays within the active OLLAMA_CONTEXT_LENGTH. Beware of silent truncation: if your tool schemas plus conversation exceed Ollama's default context length (which can be 2048 or 4096 tokens depending on version and VRAM), Ollama truncates the front of the prompt and drops your system instructions or tool declarations without throwing an error. According to the Ollama OpenAI compatibility docs, its /v1/responses endpoint is also non-stateful, so agents must still pass full conversation history.
vLLM disables automatic tool call extraction unless you pass explicit parser flags at startup. For Qwen2.5 and Qwen3 checkpoints using Hermes-style <tool_call> blocks, start the server with --enable-auto-tool-choice and --tool-call-parser hermes (newer vLLM builds also expose a dedicated qwen3_coder or reasoning parser when serving Qwen3 thinking variants). Without those flags, vLLM returns raw <tool_call> XML inside message.content instead of populating message.tool_calls, breaking downstream OpenAI SDK clients.
vllm serve Qwen/Qwen2.5-Coder-14B-Instruct \
--host 127.0.0.1 --port 8000 \
--enable-auto-tool-choice \
--tool-call-parser hermes \
--max-model-len 32768
Test tool calling immediately against the live endpoint before pointing an agent loop at it:
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="local-dev")
response = client.chat.completions.create(
model="Qwen/Qwen2.5-Coder-14B-Instruct",
messages=[{"role": "user", "content": "Check disk usage on /var/log."}],
tools=[{
"type": "function",
"function": {
"name": "run_df",
"description": "Report filesystem disk usage for a path.",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"],
"additionalProperties": False,
},
},
}],
tool_choice="auto",
)
print(response.choices[0].message.tool_calls)
If tool_calls is None and the model emitted JSON tags inside content, either the parser flag is missing or the template did not match the model checkpoint. Keep tool execution isolated and validated, as covered in the production AI agent architecture guide.
Sampling defaults and generation_config.json gotchas
A frequent complaint when migrating Qwen3 or Qwen2.5-Coder from Ollama to vLLM is that identical code produces repetitive loops, overly creative edits, or unexpected <think> blocks. The culprit is usually sampling inheritance.
Hugging Face Qwen repositories ship a generation_config.json file encoding the model author's default temperature, top_p, top_k, and repetition_penalty (for instance, Qwen3 thinking mode recommends non-zero temperature like 0.6 and top_p=0.95, while greedy temperature=0 can cause repetition traps in reasoning traces). By default, vLLM loads generation_config.json and merges any parameter your client request omits. If your evaluation script assumes OpenAI API defaults (temperature=1.0, no top_k limit, no repetition penalty) and omits those fields, vLLM quietly applies Hugging Face values instead.
Pass --generation-config vllm when launching vLLM if you want strict OpenAI-style neutral defaults unless overridden by the caller:
vllm serve Qwen/Qwen3-8B \
--host 127.0.0.1 --port 8000 \
--generation-config vllm \
--enable-auto-tool-choice \
--tool-call-parser hermes
On the Ollama side, parameters come from the Modelfile PARAMETER directives, which may differ from Hugging Face generation_config.json. Furthermore, standard OpenAI client fields do not include top_k or repeat_penalty: vLLM accepts top_k and repetition_penalty inside extra_body, whereas Ollama expects num_ctx and repeat_penalty in its native /api/chat options object. Pin temperature, top_p, max_tokens, and seed explicitly in every client call, and verify whether Qwen3 thinking mode is enabled or disabled via chat template kwargs (enable_thinking: false in extra_body={"chat_template_kwargs": ...} on vLLM or /no_think / tag selection on Ollama) so token budgets are not burned on hidden reasoning chains.
Latency vs concurrent throughput tradeoffs
Single-user latency and multi-user aggregate throughput reward different architectures.
For one developer running a single stream on a MacBook Pro (Apple Silicon unified memory) or an RTX 4090 (24 GB VRAM), Ollama often matches or beats vLLM on single-stream decode speed for 4-bit GGUF models. Because Q4_K_M shrinks weights to ~0.55 bytes per parameter, reading a 32B model per generated token moves ~18 GB over memory bandwidth instead of 33 GB (FP8) or 65 GB (BF16). On a 1 TB/s GPU, that translates directly to higher single-user tokens per second, and Ollama stays idle at 0 GB VRAM after OLLAMA_KEEP_ALIVE expires (5 minutes by default).
The curve flips as soon as concurrency rises above two or three simultaneous requests:
- Ollama queuing: With default
OLLAMA_NUM_PARALLEL=1, the second request waits in the queue until the first finishes. RaisingOLLAMA_NUM_PARALLEL=4multiplies static KV allocation by four and splits attention bandwidth across slots without block-level memory sharing. - vLLM continuous batching: New requests join the active batch on the very next decode step rather than waiting for an entire generation to complete. Weight reads from HBM/GDDR are amortized across all active sequences in the batch, so 16 concurrent users can share one GPU with only a modest drop in per-user inter-token latency while aggregate tokens per second climbs by 5x to 15x.
- Multi-GPU scaling: Ollama can span layers sequentially across GPUs (pipeline split), which leaves one card idle while another computes. vLLM uses
--tensor-parallel-size 2or4(with--ipc=hostin Docker for PyTorch shared memory) to compute attention heads and MLP layers in parallel across NVLink or PCIe, cutting both time to first token and decode latency for 32B and 72B/235B models.
# vLLM multi-GPU tensor parallelism on 2x 24 GB or 2x 48 GB cards
docker run -d --name vllm-qwen3 \
--runtime nvidia --gpus all --ipc=host \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-p 127.0.0.1:8000:8000 \
vllm/vllm-openai:latest \
--model Qwen/Qwen3-32B \
--tensor-parallel-size 2 \
--max-model-len 32768 \
--enable-auto-tool-choice \
--tool-call-parser hermes \
--generation-config vllm
Side-by-side comparison for Qwen inference
| Dimension | Ollama | vLLM |
|---|---|---|
| Primary target | Single developer, laptop, Mac, 1 consumer GPU | Shared team servers, coding agents, production APIs |
| Native weight formats | GGUF (Q4_K_M, Q8_0), registry blobs |
Safetensors (BF16, FP8, AWQ, GPTQ) |
| CPU-VRAM partial offload | Automatic layer split over RAM | Not designed for split inference; GPU-resident |
| KV cache management | Static OLLAMA_NUM_PARALLEL × OLLAMA_CONTEXT_LENGTH |
PagedAttention block pool with prefix caching |
| Multi-GPU execution | Sequential layer split across devices | Tensor and pipeline parallelism (--tensor-parallel-size) |
| Qwen tool calling | Built into official model Modelfiles | Requires --enable-auto-tool-choice --tool-call-parser hermes |
| Sampling defaults | Modelfile PARAMETER directives |
Loads Hugging Face generation_config.json unless --generation-config vllm |
| Idle memory behavior | Unloads model after OLLAMA_KEEP_ALIVE (5m default) |
Keeps weights and KV pool pinned in VRAM |
| Observability | ollama ps and per-response nanosecond timings |
Built-in /metrics Prometheus endpoint and /health |
Practical decision rules for 24 GB, 48 GB, and multi-GPU nodes
Use hardware capacity and concurrency together to pick the stack without guesswork:
- Laptops, Apple Silicon Macs, or 8-16 GB consumer GPUs: Choose Ollama with
qwen3:8borqwen2.5-coder:7b(Q4_K_MorQ8_0). SetOLLAMA_CONTEXT_LENGTH=32768explicitly so long code files do not get silently cropped. - Single 24 GB GPU (RTX 3090/4090) for one developer: Choose Ollama with
qwen2.5-coder:32b-instruct-q4_K_Morqwen3:14b(Q8_0) if you want maximum single-stream speed and easy switching between models. Choose vLLM withQwen/Qwen3-8BorQwen/Qwen2.5-Coder-14B-Instruct-AWQonly if multiple IDE plugins or background workers hit the card concurrently. - Single 48 GB GPU (L40S, RTX 6000 Ada, A6000) or multi-GPU servers: Choose vLLM. Load
FP8orAWQweights for 32B Qwen models with--enable-prefix-caching,--kv-cache-dtype fp8,--enable-auto-tool-choice,--tool-call-parser hermes, and--generation-config vllm. Add--tensor-parallel-sizewhen moving to 72B+ dense models or high concurrency.
Many engineering teams run both: developers prototype locally on Ollama against qwen3:8b, while CI, staging, and production agents hit vLLM on dedicated GPUs behind a gateway. Keep your OpenAI SDK client identical across environments, pin temperature and context limits in code, and benchmark tool-calling accuracy against the exact production quantization before switching traffic.