Speed Up Local LLM Inference on Integrated GPUs
In this article
Running a local large language model (LLM) on an integrated GPU (like Intel Iris Xe, AMD Radeon Graphics, or Apple M-series) is often slow because these GPUs share system memory and have limited compute units. This guide shows practical, software-level tweaks to cut generation time significantly—often 20–50%—without buying new hardware. You'll need a working local LLM setup (e.g., Ollama, LM Studio, llama.cpp) and know your model's file format (GGUF, GPTQ, etc.).
What You'll Need
- A computer with an integrated GPU (Intel, AMD, or Apple Silicon).
- A local LLM runtime installed (Ollama, LM Studio, llama.cpp, or similar).
- A model file (preferably GGUF format for llama.cpp-based runtimes).
- Administrator access to change system settings (optional but helpful).
Step-by-Step
- Update your GPU drivers and runtime. Visit your GPU vendor's site (Intel, AMD, Apple) and install the latest drivers. Then update your LLM runtime to the newest version—optimizations like Vulkan support or Metal improvements land frequently. For Ollama, run
ollama update; for LM Studio, check the settings for updates. - Choose a smaller or quantized model. Integrated GPUs handle models under 7B parameters best. Use a 4-bit or 5-bit quantized version (e.g., Q4_K_M) instead of a full-precision model. For example, replace Llama-2-7B with Llama-2-7B-GGUF-Q4_K_M. Smaller models reduce memory bandwidth pressure, which is the main bottleneck on shared memory.
- Set the context window to the minimum you need. The context length (e.g., 2048, 4096) directly multiplies memory usage and compute. In your runtime, set
context_sizeorn_ctxto 2048 or 512 if your task allows. For Ollama, useOLLAMA_CONTEXT_LENGTH=2048; in LM Studio, adjust the slider in the model settings. - Enable GPU offloading (partial or full). Most runtimes let you specify how many layers to offload to the GPU. On integrated GPUs, offloading all layers often works, but if you get out-of-memory errors, reduce the number. In llama.cpp, use
-ngl 99to offload all; in Ollama, setOLLAMA_GPU_LAYERS=99; in LM Studio, drag the “GPU Offload” slider to max. - Use a Vulkan or Metal backend. Integrated GPUs are not CUDA-capable, so ensure your runtime uses Vulkan (Windows/Linux) or Metal (macOS). In llama.cpp, build with
-DGGML_VULKAN=ONor use the pre-built Vulkan binaries. Ollama automatically uses Metal on Mac and Vulkan on Windows/Linux if available. Check the logs to confirm it's using the GPU, not the CPU. - Adjust batch size and thread count. Increase the batch size (e.g.,
-b 512orOLLAMA_BATCH_SIZE=512) to process more tokens in parallel. For CPU threads, use the number of physical cores (not logical) to avoid oversubscription. In llama.cpp,-t 4for a quad-core; in Ollama, setOLLAMA_NUM_PARALLEL=1andOLLAMA_NUM_THREADS=4. - Close memory-hogging applications. Integrated GPUs share system RAM. Close browsers with many tabs, video players, or background apps to free up memory and bandwidth. On Windows, check Task Manager; on macOS, Activity Monitor.
- Set the GPU to maximum performance mode. In Windows, go to Power Options > Advanced > PCI Express > Link State Power Management and set to “Off”. On macOS, enable “Low Power Mode” off in System Settings > Battery. This prevents the GPU from throttling.
- Enable flash attention (if supported). Flash attention reduces memory usage and speeds up inference. In llama.cpp, add
-fa; in Ollama, setOLLAMA_FLASH_ATTENTION=1. This works best with models that use the standard attention architecture. - Use a speculative decoding or draft model. Some runtimes (like llama.cpp with
--draft) support a small draft model to guess tokens, speeding up generation. For example, use a 0.5B draft with a 7B main model. This can double tokens per second on integrated GPUs.
Common Mistakes
- Using a model too large for the GPU. If the model doesn't fit in shared memory, the runtime falls back to CPU, which is much slower. Check memory usage with
nvidia-smi(not available on iGPU) or system monitor. - Not updating the runtime. Older versions lack Vulkan/Metal optimizations. Always update.
- Setting context too high. A 4096 context on a 7B model can consume 8GB+ of memory, causing swapping.
- Ignoring quantization. Running a full 16-bit model on an iGPU is a common mistake. Use Q4 or Q5.
- Offloading too many layers to CPU. If you offload all layers but the GPU can't handle them, it may spill to system RAM, slowing everything. Reduce layers gradually.
Tips
- Monitor tokens per second (t/s) to measure improvements. Most runtimes show this in the terminal or UI.
- Try different backends: on Windows, Vulkan is usually faster than OpenCL; on Linux, both are available.
- For Apple Silicon, ensure you're using the Metal backend and have at least 16GB unified memory for 7B models.
- Use a model with GQA (Grouped Query Attention) like Llama 3, which is faster on iGPUs.
- If you're on Linux, try building llama.cpp with
-DGGML_VULKAN=ONand-DGGML_NATIVE=ONfor CPU optimizations.
Troubleshooting
- Model runs on CPU instead of GPU: Check runtime logs for “offloaded 0/32 layers” or “using CPU”. Ensure you set the offload layers correctly and that the backend (Vulkan/Metal) is installed. Reinstall the runtime with GPU support.
- Out of memory errors: Reduce context length, switch to a smaller quant, or offload fewer layers. Also close other applications.
- No speed improvement: Verify that the GPU is actually being used (logs show “Vulkan” or “Metal”). Try increasing batch size or enabling flash attention. If still slow, the model may be too large for the iGPU—try a 3B model.
- System becomes unresponsive: Lower the number of CPU threads and reduce batch size. Ensure you're not oversubscribing the CPU.
- Vulkan not detected: Install the latest GPU drivers and the Vulkan runtime. On Linux, install
vulkan-toolsandlibvulkan1.
Frequently Asked Questions
Will these steps work on any integrated GPU?
Yes, the principles apply to Intel, AMD, and Apple integrated GPUs, but the exact settings and speed gains vary. Apple Silicon tends to benefit most from Metal optimizations.
Is it better to use CPU or iGPU for LLMs?
For most integrated GPUs, offloading to the GPU is faster than pure CPU inference because the GPU has higher memory bandwidth. However, if your iGPU is very weak, CPU might be comparable.
How much speedup can I expect?
With proper settings, you might see 20–50% faster generation compared to default settings. The biggest gains come from using a quantized model and enabling GPU offload.
Can I run a 13B model on an integrated GPU?
It's possible if you have 32GB+ unified memory (like on some Macs) and use a 4-bit quant. But expect slow speeds—usually under 5 t/s. A 7B model is more practical.
What is the best runtime for integrated GPUs?
llama.cpp with Vulkan or Metal is the most optimized. Ollama and LM Studio are user-friendly and use llama.cpp under the hood, so they're good choices.
Does increasing batch size always help?
Not always. If the batch size exceeds the GPU's capacity, it can cause memory issues. Start with 512 and test; if it doesn't help, revert.