Qwen3 8B vs 27B: GPU vs CPU Offloading Tradeoffs
In this article
For Qwen3 8B and 27B models, running on a single GPU with CPU offloading trades speed for memory: you can run larger models or longer contexts than the GPU VRAM alone allows, but inference slows dramatically because every layer that spills to system RAM must cross the PCIe bus. Specifically, expect a 5–20x slowdown when offloading most weights to CPU, versus a pure GPU run, while the 27B model becomes feasible on a 12–16GB GPU instead of requiring 24GB+.
Background: What These Models Actually Need
Qwen3 comes in several sizes, but the two most discussed for single-machine inference are the 8B and 27B dense models. The 8B variant has roughly 8 billion parameters; the 27B has about 27 billion. Memory requirements scale with parameter count and precision:
- FP16/BF16 (standard): ~2 bytes per parameter. 8B ≈ 16GB, 27B ≈ 54GB.
- INT8 quantization: ~1 byte per parameter. 8B ≈ 8GB, 27B ≈ 27GB.
- INT4 quantization: ~0.5–0.6 bytes per parameter. 8B ≈ 4–5GB, 27B ≈ 14–16GB.
These figures are for weights only. Add KV cache (which grows with context length and batch size), activations, and the CUDA runtime overhead, and a 27B in INT4 can still exceed a 12GB GPU once you pass a few thousand tokens of context. That is exactly where CPU offloading enters the picture.
How CPU Offloading Works
CPU offloading (often called “GPU offload” in llama.cpp, or “device_map=auto” in Hugging Face Transformers) splits the model across GPU VRAM and system RAM. The GPU holds some transformer layers; the CPU holds the rest. During inference, each token requires a forward pass through every layer. Layers on the GPU compute quickly; layers on the CPU compute slowly, and the weights for CPU layers must be transferred to the GPU (or the activations to the CPU) for each token. That transfer is the bottleneck.
Two common implementations:
- llama.cpp / Ollama: You specify a number of layers to offload with
-ngl(n-gpu-layers). The rest stay in RAM. This is the most common approach for local use. - Hugging Face Transformers:
device_map="auto"places layers across devices automatically, but it is less efficient for single-GPU setups because it does not batch transfers as cleverly as llama.cpp.
The key metric is memory bandwidth. A modern GPU like an RTX 4090 has ~1TB/s of VRAM bandwidth. System DDR5 RAM has ~50–80GB/s. Even if the CPU computes instantly, moving weights from RAM to GPU at 60GB/s is over 10x slower than reading from VRAM. That is the fundamental ceiling.
Performance: What You Actually See
Measured tokens-per-second (tok/s) vary widely, but the pattern is consistent. On a single RTX 4090 (24GB VRAM):
- Qwen3 8B, FP16, full GPU: ~80–120 tok/s.
- Qwen3 8B, Q4, full GPU: ~150–200 tok/s.
- Qwen3 27B, Q4, full GPU: ~40–60 tok/s (fits in 24GB).
- Qwen3 27B, Q4, 12GB GPU + CPU offload: ~5–10 tok/s.
- Qwen3 27B, FP16, 16GB GPU + CPU offload: ~2–4 tok/s.
These are rough, hardware-dependent numbers. The pattern to remember: offloading half the layers roughly halves throughput; offloading 80% of layers can cut it to 10–20% of full-GPU speed. For interactive chat, anything below ~8 tok/s feels sluggish. For batch processing or offline summarization, even 3 tok/s may be acceptable.
Choosing Between 8B and 27B
The decision is not just about memory. The 27B model is noticeably better at reasoning, coding, and following complex instructions than the 8B. If your task is simple Q&A or summarization, the 8B may be indistinguishable. If you need multi-step logic or code generation, the 27B is worth the slowdown.
Practical rules of thumb:
- GPU has 24GB VRAM: Run 27B at Q4 or Q5 entirely on GPU. No offloading needed. Best speed and quality.
- GPU has 12–16GB VRAM: Run 27B at Q4 with offloading. Expect 5–15 tok/s. Or run 8B at full FP16 with no offload for speed.
- GPU has 8GB VRAM: 27B Q4 will offload heavily and may run at 2–5 tok/s. 8B Q4 fits comfortably and is the better choice for interactive use.
- No GPU or very old GPU: Pure CPU inference of 27B Q4 is possible but painfully slow (0.5–2 tok/s). The 8B is more practical.
Also consider context length. A 27B with 32K context demands far more KV cache than 8K. If you need long documents, the 8B with a large context may outperform the 27B with a truncated one.
Common Problems and Misconceptions
“Offloading is just slower, but works the same.” Not quite. Some implementations break with partial offload, especially when the batch size exceeds 1 or when using advanced sampling. Also, prompt processing (prefill) is far more compute-bound than token generation; offloading hurts prefill disproportionately.
“More RAM always helps.” Only up to a point. If the model fits in RAM, adding more RAM does not speed it up. The bottleneck is PCIe bandwidth and CPU memory bandwidth, not capacity.
“Quantization is lossy, so avoid it.” For Q4 and Q5, quality loss on modern models like Qwen3 is minimal, often imperceptible. Q3 and lower show degradation. Use Q4_K_M or Q5_K_M as a default.
“I can just use a bigger GPU.” Yes, but a used 3090 (24GB) is often cheaper than a new 4070 Ti Super (16GB) and runs the 27B without offload. Check local prices before assuming newer is better.
“llama.cpp and Transformers give the same speed.” No. llama.cpp is typically 2–4x faster for single-user inference because it is optimized for this exact workload. Transformers is a general-purpose library.
Costs and Practical Setup
Hardware cost is the main consideration. A 12GB GPU (RTX 3060) costs roughly half of a 24GB GPU (RTX 3090 used). If you already own a 12GB card, offloading the 27B costs nothing extra but time. If you are buying new, the math changes:
- Buy a 24GB GPU: one-time cost, no offloading, best experience.
- Buy a 16GB GPU + 64GB RAM: cheaper upfront, but you will offload and wait.
- Use cloud GPUs: hourly rates for 24GB cards are often $0.50–$1.50; for occasional use, this beats buying hardware.
Software setup is straightforward. With Ollama, you can set num_gpu in the Modelfile or use environment variables. With llama.cpp, compile with CUDA support and pass -ngl 20 to offload 20 layers. With Transformers, use device_map="auto" and set load_in_4bit=True.
Alternatives to CPU Offloading
If offloading is too slow, consider these options:
- Smaller quantization: Q4 instead of FP16 halves memory with minimal quality loss.
- Distilled or smaller models: Qwen3 4B or 1.7B may be “good enough” and run entirely on GPU.
- MoE models: Qwen3 has a MoE variant (30B-A3B) where only 3B parameters are active per token. It runs faster than the dense 27B on the same hardware, though it still needs ~18GB for weights.
- API access: If you have internet, calling a hosted Qwen3 API avoids all local hardware limits, at a per-token cost.
- Multi-GPU: Two 12GB GPUs with NVLink or PCIe can run the 27B without CPU offload, but setup is more complex and not all motherboards support it.
Frequently Asked Questions
Will CPU offloading damage my hardware?
No. Offloading uses system RAM and CPU compute, which are designed for sustained load. The main risk is thermal throttling on poorly cooled laptops, but that slows inference rather than damaging components.
How much system RAM do I need for the 27B with offload?
For Q4 quantization, the model needs ~16GB for weights. Add ~4–8GB for KV cache and overhead. So 32GB total RAM is comfortable; 64GB is overkill but allows FP16 offloading (needing ~54GB).
Can I offload just a few layers to speed things up?
Yes. In llama.cpp, -ngl controls this. Offloading even 10–20 layers (out of ~64) can double throughput because the first layers are the most compute-intensive. Experiment with values from 10 to 40 to find your sweet spot.
Is the 27B worth it over the 8B if I have to offload?
For casual chat, no. For coding or complex reasoning, often yes. The 27B’s advantage is most visible in tasks requiring multiple steps. If you are patient (waiting 10–20 seconds per response), the quality difference is worth it.
Does faster RAM (DDR5 vs DDR4) matter for offloading?
Yes, but modestly. DDR5-6000 has ~2x the bandwidth of DDR4-3200, which can improve offloaded inference by 30–50%. If you are building a system for this, choose DDR5 if your CPU supports it.
What is the maximum context length I can use with offloading?
It depends on RAM, not VRAM. Each token of context costs roughly 2 bytes per layer per attention head times head dimension, which for Qwen3 is about 0.5–1MB per 1K tokens for the 27B. With 64GB RAM, you can run 32K context comfortably; with 32GB, stick to 8–16K.