Skip to content

[WIP] openvino: add GGML_OPENVINO_EVICT_ON_UPLOAD to drop host weights as t… - #488

Draft
cavusmustafa wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
cavusmustafa:ov_evict_on_upload
Draft

cavusmustafa wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
cavusmustafa:ov_evict_on_upload

Conversation

@cavusmustafa

@cavusmustafa cavusmustafa commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Evict tensors while compiling to reduce peak memory [WIP]

Overview

Adds GGML_OPENVINO_EVICT_ON_UPLOAD=1 (GPU), which drops the host pages of each weight as soon as the GPU plugin has uploaded it, instead of keeping the whole converted copy until compile_model returns. This lowers the peak of host plus GPU memory during compilation by about a third, with identical output.

The GPU plugin already calls ov::wsh::Extension::hint_evict() on each constant after its upload, which is why OpenVINO GenAI (mmap'd IR) has no such peak. Our Constants are built from an ov::Tensor and have no buffer descriptor, so the hint was ignored. With the option set, each weight Constant becomes a view of the weight buffer that has a descriptor and answers the hint with madvise(MADV_DONTNEED) on its own pages. The buffer is then marked released, so the existing restore path writes it again from the model file before any later compile, as with GGML_OPENVINO_RELEASE_WEIGHTS.

Additional information

The build does not change: same OpenVINO package, same cmake -DGGML_OPENVINO=ON, C++17. ov::AlignedBuffer is not in OpenVINO's public headers, so its declaration is mirrored in openvino/aligned_buffer.hpp, like the internal ops in openvino/op/. There are two layouts: OpenVINO 2026.5, and 2027.0 after openvinotoolkit/openvino#40120.

Because the backend derives from that class, the mirror must match the library. At configure time CMake links a small class derived from the mirror against the OpenVINO found, and defines GGML_OPENVINO_HAS_EVICT_ON_UPLOAD only if that works. A mismatch therefore compiles the feature out instead of breaking the backend; for example the 2027.0 nightly of 2026-11-30 still has the 2026.5 layout and is rejected. The Linux release tarball and the Docker image, both built with OpenVINO 2026.5.0, get the feature without CI changes. Where it is not available, or on a device other than the GPU, setting the variable prints a warning and is ignored.

Windows: the release and restore of host weights is Linux-only today; #482 adds it for Windows, and this feature can use it with a small follow-up (one VirtualFree(MEM_DECOMMIT) per range and the link test on MSVC).

Measurements and regression checks

Arc B390 iGPU (Core Ultra X7 358H, 62 GB), Linux, OpenVINO 2026.5.0 release package. "RAM used" = peak of private memory (RssAnon + RssShmem) plus GPU buffers (xe drm-resident-gtt), both system RAM on an iGPU. llama-completion -ngl 99 --temp 0.

Flag off vs on (this PR):

model RAM used, peak, off on output
Qwen2.5-7B-Instruct Q4_0 (1024-token prompt, 128 tokens) 10.14 GiB 6.56 GiB identical
gemma-4-12B-it Q4_0 (same) 16.99 GiB 11.92 GiB identical
gemma-4-26B-A4B-it Q4_0 (MoE, 64 tokens) 37.16 GiB 32.30 GiB identical
gemma-4-E2B-it Q4_0 10.09 GiB 8.53 GiB identical
granite-1b-a400m Q4_K_M (MoE) 2.25 GiB 1.22 GiB identical
Llama-3.2-1B-Instruct Q4_K_M 2.71 GiB 1.76 GiB identical

Default behavior (flag off) vs the base a274a3948: identical output and peak memory on Qwen2.5-7B (10.38 vs 10.40 GiB) and gemma-4-12B (16.98 vs 16.98 GiB); llama-bench Qwen2.5-7B tg128 24.52 vs 24.53 t/s.

Other paths with the flag on: compiled-model cache export and import (identical output to no cache), GGML_OPENVINO_MEMORY_OPTIMIZE=1 (identical), every graph recompiled with GGML_OPENVINO_DISABLE_CACHE=1 (weights written back from the GGUF, identical text), llama-bench -p 128,512 (3 compiles, 2 restores), CPU device (warning, ignored). OpenVINO master dcc454f51d (2027.0 layout): link test passes, Qwen 10.49 -> 6.98 GiB, identical output.

CI script, as the self-hosted job runs it (GG_BUILD_OPENVINO=1 GGML_OPENVINO_DEVICE=GPU GG_BUILD_LOW_PERF=1 ci/run.sh, OpenVINO 2026.5.0, where the link test enables the feature): Debug ctest 20/20, Release ctest 20/20, test-backend-ops on the GPU 10735/10735, exit 0.

What stays resident: Q/K/V weights that the GPU plugin's FullyConnectedHorizontalFusion merges into a new constant are never uploaded themselves, so they get no hint (426 MB on Qwen). The companion OpenVINO change https://github.com/cavusmustafa/openvino/tree/gpu-fc-fusion-evict-sources hints them in that pass.

Limitations: OpenVINO does not ask for evicted data back before reading it, so correctness relies on the restore before each compile (the same mechanism as GGML_OPENVINO_RELEASE_WEIGHTS). A public OpenVINO API to mark Constant data as releasable would remove the mirror.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - the change, the measurements and this description were drafted with Claude; build, memory measurements and output checks were run on the hardware above.

Written with Claude Opus 5.5

@ravi9
ravi9 force-pushed the dev_backend_openvino branch 2 times, most recently from 5b4342a to a274a39 Compare December 4, 2026 16:14
@ravi9
ravi9 force-pushed the ov_evict_on_upload branch from 3cd0433 to 69a4b8a Compare December 4, 2026 16:32
…he GPU plugin uploads them

Assisted-by: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant