# llama.cpp OpenVINO backend cookbook Recipes for the OpenVINO backend, one section per task. - Quick Start, supported devices, build basics and the user environment variables: [docs/backend/OPENVINO.md](../../../../docs/backend/OPENVINO.md). - Internals: [developer documentation](README.md). Developer variables: [OpenVINO-ENV-VARS.md](OpenVINO-ENV-VARS.md). ```bash # The examples assume a Linux build in build/ReleaseOV, models in ~/models, and OpenVINO set up in the shell source /opt/intel/openvino/setupvars.sh ``` ## Contents - [Build from source](#build-from-source) - [Ubuntu build script](#ubuntu-build-script) - [Windows build script](#windows-build-script) - [Docker](#docker) - [Run on each device](#run-on-each-device) - [Linux](#linux) - [Windows](#windows) - [llama-server](#llama-server) - [NPU context and prefill chunk](#npu-context-and-prefill-chunk) - [Multiple GPUs](#multiple-gpus) - [Compiled model cache](#compiled-model-cache) - [CPU and GPU](#cpu-and-gpu) - [NPU: gemma-4 E2B example](#npu-gemma-4-e2b-example) - [Lower memory use](#lower-memory-use) - [Large MoE models](#large-moe-models) - [Qwen3.6-35B-A3B on the NPU](#qwen36-35b-a3b-on-the-npu) - [Muse-Glimmer-30B with a DFlash draft on the GPU](#muse-glimmer-30b-with-a-dflash-draft-on-the-gpu) - [Speculative decoding](#speculative-decoding) - [Image input](#image-input) - [Embeddings and perplexity](#embeddings-and-perplexity) - [Profiling and debug dumps](#profiling-and-debug-dumps) ## Build from source The scripts install the build prerequisites and OpenVINO Runtime 2026.5. Then they build llama.cpp with the OpenVINO backend in `llama.cpp/build/ReleaseOV`. - The scripts do not install the GPU and NPU drivers. The Ubuntu script installs only the `intel-opencl-icd` package of the distribution. See [Prerequisites](../../../../docs/backend/OPENVINO.md#prerequisites). - The scripts pin OpenVINO 2026.5 in `OPENVINO_VERSION_MAJOR` and `OPENVINO_VERSION_FULL`. Edit them to use another release. ### Ubuntu build script The script installs the build tools and the OpenCL ICD, downloads and sets up OpenVINO Runtime, and builds llama.cpp with Ninja. Save it as `build-llamacpp-ov.sh` in the folder where the `llama.cpp` folder goes, then run it: ```bash chmod +x build-llamacpp-ov.sh ./build-llamacpp-ov.sh ``` ```bash #!/usr/bin/env bash # ============================================ # llama.cpp OpenVINO Build Script (Ninja) # ============================================ set -euo pipefail OPENVINO_VERSION_MAJOR="2026.5" OPENVINO_VERSION_FULL="2026.5.0.23836.73088206582" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" OPENVINO_INSTALL_DIR="/opt/intel/openvino_${OPENVINO_VERSION_MAJOR}" OPENVINO_LINK_DIR="/opt/intel/openvino" OPENVINO_TGZ="${SCRIPT_DIR}/openvino.tgz" UBUNTU_MAJOR="$(. /etc/os-release && echo "${VERSION_ID%%.*}")" # 22, 24 or 26 OPENVINO_URL="https://storage.openvinotoolkit.org/repositories/openvino/packages/${OPENVINO_VERSION_MAJOR}/linux/openvino_toolkit_ubuntu${UBUNTU_MAJOR}_${OPENVINO_VERSION_FULL}_x86_64.tgz" case "${UBUNTU_MAJOR}" in 22|24|26) ;; *) echo "Unsupported Ubuntu version ${UBUNTU_MAJOR}: OpenVINO archives exist for Ubuntu 22, 24 and 26." >&2; exit 1 ;; esac echo "============================================" echo "Installing prerequisites (apt)..." echo "============================================" sudo apt-get update sudo apt-get install -y \ build-essential libssl-dev libtbb12 \ cmake ninja-build python3-pip \ curl wget tar git echo "============================================" echo "Installing OpenCL runtime + headers..." echo "============================================" sudo apt-get install -y \ ocl-icd-opencl-dev opencl-headers opencl-clhpp-headers intel-opencl-icd cd "${SCRIPT_DIR}" # ============================================ # Clone llama.cpp if missing # ============================================ if [[ ! -f "llama.cpp/CMakeLists.txt" ]]; then echo "Cloning llama.cpp..." git clone https://github.com/ggml-org/llama.cpp fi # ============================================ # Setup OpenVINO: download & extract to /opt/intel/openvino_${OPENVINO_VERSION_MAJOR}, then point /opt/intel/openvino at it via symlink so the active version is swappable. # ============================================ if [[ -f "${OPENVINO_INSTALL_DIR}/setupvars.sh" ]]; then echo "OpenVINO ${OPENVINO_VERSION_MAJOR} already installed at ${OPENVINO_INSTALL_DIR}. Skipping download." else echo "OpenVINO not found at ${OPENVINO_INSTALL_DIR}. Starting download..." curl -fL -o "${OPENVINO_TGZ}" "${OPENVINO_URL}" echo "Extracting OpenVINO to ${OPENVINO_INSTALL_DIR}..." sudo mkdir -p "${OPENVINO_INSTALL_DIR}" sudo tar -xzf "${OPENVINO_TGZ}" -C "${OPENVINO_INSTALL_DIR}" --strip-components=1 rm -f "${OPENVINO_TGZ}" fi # Refresh symlink: /opt/intel/openvino -> /opt/intel/openvino_${OPENVINO_VERSION_MAJOR} sudo ln -sfn "${OPENVINO_INSTALL_DIR}" "${OPENVINO_LINK_DIR}" OPENVINO_ROOT="${OPENVINO_LINK_DIR}" echo "OpenVINO Ready: ${OPENVINO_ROOT} -> ${OPENVINO_INSTALL_DIR}" # Install OpenVINO's own runtime dependencies (one-time per system). if [[ -x "${OPENVINO_ROOT}/install_dependencies/install_openvino_dependencies.sh" ]]; then echo "============================================" echo "Installing OpenVINO runtime dependencies..." echo "============================================" echo "Y" | sudo -E "${OPENVINO_ROOT}/install_dependencies/install_openvino_dependencies.sh" fi # ============================================ # Clean old build cache # ============================================ cd "${SCRIPT_DIR}/llama.cpp" if [[ -d "build/ReleaseOV" ]]; then echo "Removing old build directory..." rm -rf "build/ReleaseOV" fi echo "============================================" echo "Configuring with CMake..." echo "============================================" set +u source "${OPENVINO_ROOT}/setupvars.sh" set -u cmake -B build/ReleaseOV -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DGGML_OPENVINO=ON cmake --build build/ReleaseOV --parallel echo "============================================" echo "Build completed successfully!" echo "============================================" echo "Binaries: $(pwd)/build/ReleaseOV/bin" echo echo "NOTE: To run, source setupvars.sh and pick a device:" echo " source /opt/intel/openvino/setupvars.sh" echo " export GGML_OPENVINO_DEVICE=CPU # or GPU / NPU" echo " ./build/ReleaseOV/bin/llama-cli -m model.gguf" ``` ### Windows build script The script installs Git, Ninja, CMake, Visual Studio 2022 Build Tools and OpenCL (with vcpkg). Then it downloads OpenVINO Runtime and builds llama.cpp with Ninja. Save it as `build-llamacpp-ov.bat` in the folder where the `llama.cpp` folder goes, then run it from Command Prompt or PowerShell: ```cmd :: Command Prompt build-llamacpp-ov.bat ``` ```powershell # PowerShell .\build-llamacpp-ov.bat ``` ```bat @echo off setlocal enabledelayedexpansion REM ============================================ REM llama.cpp OpenVINO Build Script (Ninja) REM ============================================ set "OPENVINO_VERSION_MAJOR=2026.5" set "OPENVINO_VERSION_FULL=2026.5.0.23836.73088206582" set "SCRIPT_DIR=%~dp0" set "VCPKG_DIR=C:\vcpkg" set "OPENVINO_INSTALL_DIR=C:\Intel\openvino_%OPENVINO_VERSION_MAJOR%" set "OPENVINO_LINK_DIR=C:\Intel\openvino" set "OPENVINO_ZIP=%SCRIPT_DIR%openvino.zip" set "OPENVINO_EXTRACT_TMP=%SCRIPT_DIR%openvino_extract_tmp" set "OPENVINO_URL=https://storage.openvinotoolkit.org/repositories/openvino/packages/%OPENVINO_VERSION_MAJOR%/windows/openvino_toolkit_windows_%OPENVINO_VERSION_FULL%_x86_64.zip" echo ============================================ echo Installing prerequisites... echo ============================================ winget install --id Git.Git -e --accept-source-agreements --accept-package-agreements 2>nul winget install --id Ninja-build.Ninja -e --accept-source-agreements --accept-package-agreements 2>nul winget install --id Kitware.CMake -e --accept-source-agreements --accept-package-agreements 2>nul REM Ensure Visual Studio Build Tools are installed. echo Checking for Visual Studio Build Tools... set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" set "VS_INSTALLED=" if exist "%VSWHERE%" ( for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath 2^>nul`) do ( set "VS_INSTALLED=%%i" ) ) if defined VS_INSTALLED ( echo Visual Studio with VC++ x86/x64 tools already present at "!VS_INSTALLED!". Skipping winget install. ) else ( winget install --id Microsoft.VisualStudio.2022.BuildTools -e --override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended" --accept-source-agreements --accept-package-agreements if errorlevel 1 ( echo WARNING: winget could not install Visual Studio Build Tools automatically. echo Install manually from https://aka.ms/vs/17/release/vs_BuildTools.exe ^(select the "Desktop development with C++" workload^) echo and re-run this script from a "Developer Command Prompt for VS 2022". ) ) echo ============================================ echo Installing OpenCL via vcpkg... echo ============================================ if not exist "%VCPKG_DIR%" ( git clone https://github.com/microsoft/vcpkg "%VCPKG_DIR%" cd /d "%VCPKG_DIR%" call bootstrap-vcpkg.bat call vcpkg integrate install ) cd /d "%VCPKG_DIR%" call vcpkg install opencl cd /d "%SCRIPT_DIR%" REM ============================================ REM Clone llama.cpp if missing REM ============================================ if not exist "llama.cpp\CMakeLists.txt" ( echo Cloning llama.cpp... git clone https://github.com/ggml-org/llama.cpp ) cd /d "llama.cpp" set "SCRIPT_DIR=%CD%" REM ============================================ REM Setup OpenVINO: download & extract to C:\Intel\openvino_%OPENVINO_VERSION_MAJOR%, then point C:\Intel\openvino at it via a directory junction (mklink /J). REM ============================================ if exist "%OPENVINO_INSTALL_DIR%\setupvars.bat" ( echo OpenVINO %OPENVINO_VERSION_MAJOR% already installed at "%OPENVINO_INSTALL_DIR%". Skipping download. ) else ( echo OpenVINO not found at "%OPENVINO_INSTALL_DIR%". Starting download... curl -L -o "%OPENVINO_ZIP%" "%OPENVINO_URL%" if errorlevel 1 ( echo ERROR: Download failed. exit /b 1 ) echo Extracting OpenVINO... if exist "%OPENVINO_EXTRACT_TMP%" rmdir /s /q "%OPENVINO_EXTRACT_TMP%" mkdir "%OPENVINO_EXTRACT_TMP%" tar -xf "%OPENVINO_ZIP%" -C "%OPENVINO_EXTRACT_TMP%" if errorlevel 1 ( echo ERROR: Extraction failed. exit /b 1 ) REM Move the single top-level folder contents into the versioned install dir. set "OPENVINO_EXTRACTED=" for /d %%i in ("%OPENVINO_EXTRACT_TMP%\*") do set "OPENVINO_EXTRACTED=%%i" if not defined OPENVINO_EXTRACTED ( echo ERROR: Could not locate extracted OpenVINO folder under "%OPENVINO_EXTRACT_TMP%". exit /b 1 ) if not exist "%OPENVINO_INSTALL_DIR%" mkdir "%OPENVINO_INSTALL_DIR%" xcopy /e /i /y /q "!OPENVINO_EXTRACTED!\*" "%OPENVINO_INSTALL_DIR%\" >nul if errorlevel 1 ( echo ERROR: Failed to copy OpenVINO from "!OPENVINO_EXTRACTED!" to "%OPENVINO_INSTALL_DIR%". echo Re-run this script from an elevated Command Prompt ^(Run as administrator^) if access is denied. exit /b 1 ) rmdir /s /q "%OPENVINO_EXTRACT_TMP%" del "%OPENVINO_ZIP%" ) REM Refresh junction: C:\Intel\openvino -> C:\Intel\openvino_. REM `mklink /J` creates a directory junction (no admin / Developer Mode required). if exist "%OPENVINO_LINK_DIR%" rmdir "%OPENVINO_LINK_DIR%" mklink /J "%OPENVINO_LINK_DIR%" "%OPENVINO_INSTALL_DIR%" >nul if errorlevel 1 ( echo ERROR: Failed to create junction "%OPENVINO_LINK_DIR%" -^> "%OPENVINO_INSTALL_DIR%". echo If "%OPENVINO_LINK_DIR%" already exists as a regular non-empty folder, remove it manually and re-run. exit /b 1 ) set "OPENVINO_ROOT=%OPENVINO_LINK_DIR%" echo OpenVINO Ready: %OPENVINO_ROOT% -^> %OPENVINO_INSTALL_DIR% echo ============================================ echo Setting up compiler environment... echo ============================================ REM Locate Visual Studio Build Tools vcvars64.bat set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if exist "%VSWHERE%" ( for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( set "VS_PATH=%%i" ) ) if defined VS_PATH ( call "%VS_PATH%\VC\Auxiliary\Build\vcvars64.bat" >nul ) else ( echo WARNING: Visual Studio Build Tools not found. Compiler may be missing. ) REM ============================================ REM Clean old build cache REM ============================================ if exist "build\ReleaseOV" ( echo Removing old build directory ... rmdir /s /q "build\ReleaseOV" ) echo ============================================ echo Configuring with CMake... echo ============================================ call "%OPENVINO_ROOT%\setupvars.bat" >nul 2>nul cmake -B build\ReleaseOV -G Ninja ^ -DCMAKE_BUILD_TYPE=Release ^ -DGGML_OPENVINO=ON ^ -DCMAKE_TOOLCHAIN_FILE="%VCPKG_DIR%\scripts\buildsystems\vcpkg.cmake" if errorlevel 1 ( echo If you continue to face CMAKE errors, make sure to install: echo winget install Microsoft.VisualStudio.2022.BuildTools echo Then run the "Developer Command Prompt for VS 2022" and launch this script from there. exit /b 1 ) cmake --build build\ReleaseOV --config Release if errorlevel 1 exit /b 1 echo ============================================ echo Build completed successfully! echo ============================================ echo Binaries: %CD%\build\ReleaseOV\bin echo. echo NOTE: To run, source setupvars.bat and pick a device: echo call "C:\Intel\openvino\setupvars.bat" echo set GGML_OPENVINO_DEVICE=CPU^&^& REM or GPU / NPU echo build\ReleaseOV\bin\llama-cli.exe -m model.gguf echo. endlocal ``` - In a new shell, run the setupvars script through the junction: `call "C:\Intel\openvino\setupvars.bat"` in cmd, or `& "C:\Intel\openvino\setupvars.ps1"` in PowerShell. - If winget cannot register Visual Studio Build Tools on the first run, install them once by hand. Then run the script again from an elevated **Developer Command Prompt for VS 2022**. ## Docker The images come from [.devops/openvino.Dockerfile](../../../../.devops/openvino.Dockerfile). Prebuilt images for `linux/amd64` are on the GitHub Container Registry: ```bash # full: all binaries and the Python tools; light: llama-cli and llama-completion; server: llama-server docker pull ghcr.io/ggml-org/llama.cpp:full-openvino docker pull ghcr.io/ggml-org/llama.cpp:light-openvino docker pull ghcr.io/ggml-org/llama.cpp:server-openvino ``` Build the images locally: ```bash # Build the base runtime image with compiled shared libraries and minimal dependencies. docker build --target=base -t llama-openvino:base -f .devops/openvino.Dockerfile . # Build the complete image with all binaries, Python tools, gguf-py library, and model conversion utilities. docker build --target=full -t llama-openvino:full -f .devops/openvino.Dockerfile . # Build a minimal CLI image with the llama, llama-cli and llama-completion executables. docker build --target=light -t llama-openvino:light -f .devops/openvino.Dockerfile . # Build a server-only image with llama-server executable, health check endpoint, and REST API support. docker build --target=server -t llama-openvino:server -f .devops/openvino.Dockerfile . # If you are behind a proxy: docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --target=server -t llama-openvino:server -f .devops/openvino.Dockerfile . ``` Run a container on the CPU, GPU or NPU. The examples mount the models in `~/models`. For a prebuilt image, use `ghcr.io/ggml-org/llama.cpp:light-openvino` instead of `llama-openvino:light`. ```bash # Run the container on the CPU docker run --rm -it -v ~/models:/models llama-openvino:light --no-warmup -c 1024 -m /models/Llama-3.2-1B-Instruct-Q4_K_M.gguf # With Intel GPU access (iGPU or dGPU) docker run --rm -it -v ~/models:/models \ --device=/dev/dri --group-add=$(stat -c "%g" /dev/dri/render* | head -n 1) -u $(id -u):$(id -g) \ --env=GGML_OPENVINO_DEVICE=GPU \ llama-openvino:light --no-warmup -c 1024 -m /models/Llama-3.2-1B-Instruct-Q4_K_M.gguf # With Intel NPU access docker run --rm -it -v ~/models:/models \ --device=/dev/accel --group-add=$(stat -c "%g" /dev/accel/accel* | head -n 1) -u $(id -u):$(id -g) \ --env=GGML_OPENVINO_DEVICE=NPU \ llama-openvino:light --no-warmup -c 512 -m /models/Llama-3.2-1B-Instruct-Q4_K_M.gguf ``` Run llama-server in a container. The server image listens on `0.0.0.0:8080`. Test it as in [llama-server](#llama-server). ```bash # Run the llama-openvino:server Docker container (CPU) docker run --rm -it -p 8080:8080 -v ~/models:/models llama-openvino:server --no-warmup -m /models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 # Run the llama-openvino:server Docker container with Intel GPU access (iGPU or dGPU) docker run --rm -it -v ~/models:/models \ --device=/dev/dri --group-add=$(stat -c "%g" /dev/dri/render* | head -n 1) -u $(id -u):$(id -g) \ -p 8080:8080 --env=GGML_OPENVINO_DEVICE=GPU \ llama-openvino:server --no-warmup -c 1024 -m /models/Llama-3.2-1B-Instruct-Q4_K_M.gguf # Run the llama-openvino:server Docker container with Intel NPU access docker run --rm -it -v ~/models:/models \ --device=/dev/accel --group-add=$(stat -c "%g" /dev/accel/accel* | head -n 1) -u $(id -u):$(id -g) \ -p 8080:8080 --env=GGML_OPENVINO_DEVICE=NPU \ llama-openvino:server --no-warmup -c 512 -m /models/Llama-3.2-1B-Instruct-Q4_K_M.gguf ``` ## Run on each device ### Linux ```bash # If the device is unset, the CPU is used. export GGML_OPENVINO_DEVICE=GPU # To run llama-simple: ./build/ReleaseOV/bin/llama-simple -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -n 50 "The story of AI is " # To run in chat mode: ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 # To run llama-bench: ./build/ReleaseOV/bin/llama-bench -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf # NPU export GGML_OPENVINO_DEVICE=NPU ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 512 ``` ### Windows Download a model: ```powershell # Windows PowerShell mkdir C:\models Invoke-WebRequest -Uri https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_K_M.gguf -OutFile C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf ``` ```cmd REM Windows Command Prompt mkdir C:\models curl -L https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_K_M.gguf -o C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf ``` Run it: ```cmd REM Windows Command Prompt set GGML_OPENVINO_DEVICE=GPU REM To run llama-simple: build\ReleaseOV\bin\llama-simple.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf" -n 50 "The story of AI is " REM To run in chat mode: build\ReleaseOV\bin\llama-cli.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf" -c 1024 REM To run llama-bench: build\ReleaseOV\bin\llama-bench.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf" REM NPU set GGML_OPENVINO_DEVICE=NPU build\ReleaseOV\bin\llama-cli.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf" -c 512 ``` ```powershell # Windows PowerShell $env:GGML_OPENVINO_DEVICE = "GPU" build\ReleaseOV\bin\llama-cli.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf" -c 1024 # NPU $env:GGML_OPENVINO_DEVICE = "NPU" build\ReleaseOV\bin\llama-cli.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.gguf" -c 512 ``` ### llama-server ```bash export GGML_OPENVINO_DEVICE=GPU ./build/ReleaseOV/bin/llama-server -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf --port 8080 -c 1024 # Option 1: open http://localhost:8080 in a browser for Llama Chat, the built-in chat app of llama-server. # Option 2: test the server with curl, from a new terminal. # Behind a proxy, keep localhost off the proxy export NO_PROXY=localhost,127.0.0.1 # Health endpoint curl -f http://localhost:8080/health # A simple prompt curl -X POST "http://localhost:8080/v1/chat/completions" -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"Write a poem about OpenVINO"}],"max_tokens":100}' | jq . # NPU: several slots need the unified KV cache (-kvu). Without -np, llama-server uses 4 slots with it. export GGML_OPENVINO_DEVICE=NPU ./build/ReleaseOV/bin/llama-server -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf --port 8080 -c 1024 -np 2 -kvu ``` ### NPU context and prefill chunk ```bash export GGML_OPENVINO_DEVICE=NPU # Set -c. The default is the training context of the model, for example 131072 for Llama 3.2 1B. # Keep it small on the NPU: -c 512, or -c 256 for larger models. Decode can slow down as the context grows. ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 512 # Tokens in one NPU prefill step (default 256). # A larger value can make long prompts faster. It also makes the first load longer. export GGML_OPENVINO_PREFILL_CHUNK_SIZE=512 ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 # NPU plugin properties: the compiler in OpenVINO, one compiler thread (lower memory peak), more plugin logs export GGML_OPENVINO_NPU_CONFIG="NPU_COMPILER_TYPE=PLUGIN,COMPILATION_NUM_THREADS=1,LOG_LEVEL=LOG_INFO" ``` ### Multiple GPUs ```bash # List the devices. Each OpenVINO device shows its GGML_OPENVINO_DEVICE value; (selected) marks the active one. ./build/ReleaseOV/bin/llama-cli --list-devices # With several GPUs, select one by name. GPU alone is not available then. export GGML_OPENVINO_DEVICE=GPU.1 ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 # Split a model across two GPUs by layer export GGML_OPENVINO_DEVICE=GPU.0,GPU.1 ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 -sm layer ``` ## Compiled model cache The cache keeps compiled models on disk, so later starts of the same model load faster. - One directory can hold the cached models of different models and settings. - Use the same model and the same settings in every run. A changed setting selects another cache entry. The settings: [Compiled model cache](README.md#compiled-model-cache). ### CPU and GPU ```bash # First run: compile the model and write the cache. # -lv 4 logs "model cache WROTE" (llama-bench: -v). Wait for it before you stop the run: an interrupted export is not cached. export GGML_OPENVINO_DEVICE=GPU # or CPU export GGML_OPENVINO_COMPILED_MODEL_CACHE_DIR=$HOME/ov_cache ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 -lv 4 # Later runs (optional): cache-only mode. It requires the cached model and skips the weight upload and the compilation. export GGML_OPENVINO_COMPILED_MODEL_CACHE_ONLY=1 ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 ``` - Cache-only mode needs mmap loading (the default) and a model that runs fully on OpenVINO. - MoE models are not written to the cache on CPU, so cache-only mode does not work for them on CPU. - A cache hit without cache-only mode shortens the load, but it uses about as much memory as a run without the cache. ### NPU: gemma-4 E2B example On the NPU, the cache holds the compiled models without weights, plus one shared weights file. Only the first start compiles the model. 1. Run once to compile and save the model: ```bash # This start takes longer: the backend compiles the model for the NPU and saves it in the cache directory. # The log shows the warning "no usable cached blobs ... compiling and exporting". # Use the model as usual, then exit with /exit. export GGML_OPENVINO_DEVICE=NPU export GGML_OPENVINO_COMPILED_MODEL_CACHE_DIR=$HOME/ov_cache # Host gather is on by default. GGML_OPENVINO_NPU_HOST_GATHER=0 turns it off. export GGML_OPENVINO_NPU_TOKEN_EMBD_QUANT=q4_0_128 # optional: slightly less memory; may lower accuracy export GGML_OPENVINO_PREFILL_CHUNK_SIZE=512 # optional: can make long prompts faster; makes the first run longer ./build/ReleaseOV/bin/llama-cli -m google_gemma-4-E2B-it-Q4_K_M.gguf -c 4096 ``` 2. On every later start, load the model from the cache: ```bash # Use the same exports as in step 1 (repeat them in a new shell) and the same command. # The backend loads the compiled model instead of compiling it. With -lv 4, the log shows "model cache HIT". # A changed setting or -c value compiles and saves again, or stops with an error when GGML_OPENVINO_SELF_CONTAINED_MMAP=1 is set. export GGML_OPENVINO_SELF_CONTAINED_MMAP=1 # optional, later runs only: use the memory-mapped GGUF file as the model buffer; fails without the cache of step 1 ./build/ReleaseOV/bin/llama-cli -m google_gemma-4-E2B-it-Q4_K_M.gguf -c 4096 ``` - With the default settings, the first prompt writes the prefill model of every KV window up to `-c`. Later runs with the same `-c` find a cached model for any prompt length. ## Lower memory use With the default settings, the GPU and CPU plugins keep their own copy of the weights next to the copy of the backend while a model compiles. On integrated GPUs, both copies are in system RAM. The settings below lower that peak. They do not change the output. ```bash # GPU or CPU, large model, Linux: keep at most 10% of the weights in RAM while the model loads and compiles. # This lowers the peak the most, also when RAM is free. The first token can come later. export GGML_OPENVINO_COMPILE_MEM_SPILL=0.1 # Or without a cap: the kernel drops the spilled pages only when RAM runs out, so the peak does not change while RAM is free. # export GGML_OPENVINO_COMPILE_MEM_SPILL=1 # Both back the host buffers with files in /var/tmp and write them at each start: the load takes longer, and decoding can be a little slower. # Needs free disk space of more than the model size, on CPU also the KV cache; with less, the backend warns and uses RAM. # Another directory, on a local disk (not tmpfs): export GGML_OPENVINO_COMPILE_MEM_SPILL_DIR=$HOME/ov_spill mkdir -p $GGML_OPENVINO_COMPILE_MEM_SPILL_DIR # GPU: nothing to set. The backend already releases its host copy of the weights after compilation (GGML_OPENVINO_RELEASE_WEIGHTS=1, the default). # CPU, MoE model: build fewer weight nodes during compilation. export GGML_OPENVINO_REDUCE_COMPILE_MEM=1 # All at once: GGML_OPENVINO_MEMORY_OPTIMIZE=1 sets GGML_OPENVINO_REDUCE_COMPILE_MEM=1, GGML_OPENVINO_COMPILE_MEM_SPILL=0.1 and, on GPU, GGML_OPENVINO_RELEASE_WEIGHTS=1 (already the default). # Each one set on its own wins. export GGML_OPENVINO_MEMORY_OPTIMIZE=1 ``` - The same model, started again and again: [cache-only mode](#cpu-and-gpu) skips the weight upload. `GGML_OPENVINO_COMPILE_MEM_SPILL` is optional in the first run. - NPU: `GGML_OPENVINO_SELF_CONTAINED_MMAP=1` uses the memory-mapped GGUF file as the model buffer. See [NPU: gemma-4 E2B example](#npu-gemma-4-e2b-example). - `GGML_OPENVINO_COMPILE_MEM_SPILL` is ignored on Windows and in cache-only mode. - `-lm none` (no mmap) does not lower the memory in use. Cache-only mode needs mmap loading and stops with an error with `-lm none`. - The variables: [Memory optimization](OpenVINO-ENV-VARS.md#memory-optimization). ## Large MoE models ### Qwen3.6-35B-A3B on the NPU MoE models with a softmax router and SwiGLU experts run on the NPU through the MoE support of NPUW. This needs OpenVINO 2026.5 or later. A 35B MoE model needs nearly all of a 32 GB system: the backend and NPUW each hold a copy of the weights (about 18 GB each), and the NPU can address 18 GB of the shared memory. Use a small context and these settings: ```bash export GGML_OPENVINO_DEVICE=NPU export GGML_OPENVINO_PREFILL_CHUNK_SIZE=128 export GGML_OPENVINO_NPU_CONFIG="NPUW_WEIGHTS_BANK_ALLOC=CPU,NPUW_FUNCALL_ASYNC=NO,COMPILATION_NUM_THREADS=1" ./build/ReleaseOV/bin/llama-cli -m Qwen_Qwen3.6-35B-A3B-Q4_0.gguf -c 256 ``` ```bat REM Windows set GGML_OPENVINO_DEVICE=NPU set GGML_OPENVINO_PREFILL_CHUNK_SIZE=128 set GGML_OPENVINO_NPU_CONFIG=NPUW_WEIGHTS_BANK_ALLOC=CPU,NPUW_FUNCALL_ASYNC=NO,COMPILATION_NUM_THREADS=1 build\ReleaseOV\bin\llama-cli.exe -m Qwen_Qwen3.6-35B-A3B-Q4_0.gguf -c 256 ``` - `NPUW_WEIGHTS_BANK_ALLOC=CPU` keeps the NPUW copy of the weights in host memory instead of the NPU-addressable memory, at some cost in speed. - `NPUW_FUNCALL_ASYNC=NO` and `COMPILATION_NUM_THREADS=1` lower the memory peak. - The backend sets `NPUW_MOE_POOL_SIZE=0` and `NPUW_MOE_TOKEN_CHUNK_SIZE=16` itself for MoE models (see [NPU plugin properties](OpenVINO-ENV-VARS.md#npu-plugin-properties)). Without them, the load can hang on a 32 GB system. - The NPU compiler type can stay unset: models with `GATED_DELTA_NET` layers, such as Qwen3.6, then compile with the compiler in OpenVINO. `NPU_COMPILER_TYPE=PREFER_PLUGIN` gives the same result. - Linux: the NPU reports almost all of the system memory, so `--fit` keeps every weight in the backend, and a 32 GB system swaps heavily. Pass `--fit-target 16384`: `--fit` then leaves part of the expert weights in the memory-mapped model file. Windows does the same without it, because the NPU reports 16 GB there. The graph still runs on the NPU alone. - `llama-perplexity`: see [Embeddings and perplexity](#embeddings-and-perplexity). ### Muse-Glimmer-30B with a DFlash draft on the GPU This needs a 64 GB system. ```bash export GGML_OPENVINO_DEVICE=GPU export GGML_OPENVINO_COMPILE_MEM_SPILL=1 export GGML_OPENVINO_ROPE_SINCOS=device_f32 # long prompts ./build/ReleaseOV/bin/llama-server -m Muse-Glimmer-30B-Q4_K_M.gguf -md .gguf \ --spec-type draft-dflash --spec-draft-n-max 4 ``` ## Speculative decoding MTP, for Qwen3.5 and Qwen3.6 models with MTP weights in the GGUF file. It needs the GPU (dynamic stateless execution). Internals and limitations: [Qwen MTP](README.md#qwen-mtp). ```bash export GGML_OPENVINO_DEVICE=GPU export GGML_OPENVINO_REQUANT_KQUANT=q4_asym64_all # recommended for Qwen3.6-35B-A3B Q4_K_M # Keep GGML_OPENVINO_KV_SLICE at its default (1) ./build/ReleaseOV/bin/llama-server -m Qwen3.6-35B-A3B-Q4_K_M.gguf --spec-type draft-mtp --spec-draft-n-max 2 # Several slots: the unified KV cache is the recommended layout on the GPU ./build/ReleaseOV/bin/llama-server -m Qwen3.6-35B-A3B-Q4_K_M.gguf --spec-type draft-mtp --spec-draft-n-max 2 -np 4 --kv-unified ``` DFlash: see [Muse-Glimmer-30B with a DFlash draft on the GPU](#muse-glimmer-30b-with-a-dflash-draft-on-the-gpu). ## Image input Image input is experimental. It runs on CPU and GPU. Internals and limitations: [Multimodal](README.md#multimodal). Gemma4 E2B image input on GPU or CPU: ```bash # Gemma4 E2B image input on GPU (or CPU). The chat template of the model needs --jinja. # The projector (mmproj) file is in the same Hugging Face repository as the model. # The model writes its reasoning before the answer. export GGML_OPENVINO_DEVICE=GPU ./build/ReleaseOV/bin/llama-mtmd-cli -m google_gemma-4-E2B-it-Q4_K_M.gguf \ --mmproj mmproj-google_gemma-4-E2B-it-f16.gguf --jinja -c 4096 \ --image cat.jpg -p "What animal is in this image?" ``` Qwen3-VL-4B image input on GPU: ```bash # Qwen3-VL-4B image input on GPU. Model and projector: https://huggingface.co/unsloth/Qwen3-VL-4B-Instruct-GGUF # --image-max-tokens 256 keeps the image prefill within the memory of a 16 GB system. export GGML_OPENVINO_DEVICE=GPU ./build/ReleaseOV/bin/llama-mtmd-cli -m Qwen3-VL-4B-Instruct-Q4_K_M.gguf \ --mmproj mmproj-F16.gguf --jinja -c 4096 --image-max-tokens 256 \ --image tools/mtmd/test-1.jpeg -p "Describe this image in one sentence." ``` ## Embeddings and perplexity ```bash # Embeddings: CPU or GPU (embedding models do not work on the NPU) export GGML_OPENVINO_DEVICE=GPU ./build/ReleaseOV/bin/llama-embedding -m embedding-model-Q8_0.gguf -p "Hello world" # Perplexity ./build/ReleaseOV/bin/llama-perplexity -m model.gguf -f wiki.test.raw -c 512 # MoE models on the GPU: set -b to the -c value, so that each batch holds one sequence ./build/ReleaseOV/bin/llama-perplexity -m model.gguf -f wiki.test.raw -c 512 -b 512 # NPU: -b at most -c (one sequence per batch), -ub equal to the prefill chunk size (default 256) export GGML_OPENVINO_DEVICE=NPU ./build/ReleaseOV/bin/llama-perplexity -m model.gguf -f wiki.test.raw -c 1024 -b 1024 -ub 256 # NPU, MoE models such as Qwen3.6-35B-A3B: -c at most twice GGML_OPENVINO_PREFILL_CHUNK_SIZE. # The output rows of the last layer must not exceed the chunk size. export GGML_OPENVINO_PREFILL_CHUNK_SIZE=128 ./build/ReleaseOV/bin/llama-perplexity -m Qwen_Qwen3.6-35B-A3B-Q4_0.gguf -f wiki.test.raw -c 256 ``` ## Profiling and debug dumps The variables are in [Debug output](OpenVINO-ENV-VARS.md#debug-output). ```bash # Execution timing of each graph: 1. 2 or higher also turns on OpenVINO and OpenCL profiling. # llama-simple prints the timing lines. llama-cli needs -lv 4, llama-bench needs -v. export GGML_OPENVINO_DEVICE=GPU export GGML_OPENVINO_PROFILING=1 ./build/ReleaseOV/bin/llama-simple -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -n 50 "The story of AI is " ``` ```bash # Show the variables in effect (log verbosity 4) ./build/ReleaseOV/bin/llama-cli -m ~/models/Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 1024 -lv 4 2>&1 | grep "settings from the environment" ``` ```bash # CPU in FP16, as the GPU and the NPU compute. This helps to debug the accuracy of a quantized model. GGML_OPENVINO_DEVICE=CPU GGML_OPENVINO_CPU_CONFIG="INFERENCE_PRECISION_HINT=f16" \ ./build/ReleaseOV/bin/llama-cli -m model.gguf -c 512 ``` ```bash # Find out whether a default optimization causes a wrong result: turn it off and compare the output GGML_OPENVINO_DEVICE=NPU GGML_OPENVINO_NPU_FAST_MASK=0 \ ./build/ReleaseOV/bin/llama-completion -m model.gguf -c 512 -n 32 --temp 0 -no-cnv -p "The capital of France is" ``` ```bash # Dump the GGML graph and the OpenVINO IR of a run GGML_OPENVINO_DUMP_CGRAPH=1 GGML_OPENVINO_DUMP_IR=1 \ ./build/ReleaseOV/bin/llama-cli -m model.gguf -c 512 # Shapes of each graph node, with * at the dynamic (token) dimension. Printed to stdout. GGML_OPENVINO_DEBUG_DYNAMIC_DIMS=1 ./build/ReleaseOV/bin/llama-completion -m model.gguf -c 512 -n 4 -no-cnv -p "Hello" > dims.txt # Log unsupported ops. The lines have the WARN level, which the default log verbosity shows (-lv 2 or higher). GGML_OPENVINO_LOG_UNSUPPORTED_OPS=1 ./build/ReleaseOV/bin/llama-cli -m model.gguf -c 512 # What supports_op accepts and rejects: 1 = summary at exit, 2 = also each call GGML_OPENVINO_LOG_SUPPORTS_OP=1 ./build/ReleaseOV/bin/llama-completion -m model.gguf -c 512 -n 16 -no-cnv -p "Hello" 2>&1 | grep ov-supports-op # Graph key and tensor shapes when an inference throws GGML_OPENVINO_DIAG_GRAPH_IO=1 ./build/ReleaseOV/bin/llama-completion -m model.gguf -c 512 -n 16 -no-cnv -p "Hello" 2>&1 | grep DIAG # NPUW dumps. They need an OpenVINO developer build (NPU_PLUGIN_DEVELOPER_BUILD). export GGML_OPENVINO_DEVICE=NPU export GGML_OPENVINO_NPUW_DUMP_SUBS=YES export GGML_OPENVINO_NPUW_DUMP_SUBS_DIR=/tmp/npuw_dump # optional ./build/ReleaseOV/bin/llama-cli -m model.gguf -c 512 ``` List the properties of the installed NPU plugin (C++): ```cpp // List the properties of the installed NPU plugin with their current values ov::Core core; for (const auto & name : core.get_property("NPU", ov::supported_properties)) { std::cout << name << " = " << core.get_property("NPU", name).as() << "\n"; } ```