Skip to content

ggml-openvino: release host weight buffers by default on GPU and restore them from the model file - #467

Open
osabnis wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
osabnis:ov-release-host-weights
Open

osabnis wants to merge 1 commit into
ravi9:dev_backend_openvinofrom
osabnis:ov-release-host-weights

Conversation

@osabnis

@osabnis osabnis commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Overview

On GPU, the OpenVINO plugin maintains its own device copy of each weight after compilation, but the corresponding host weight buffers remain resident in memory. This can consume 20–24 GB of host memory for 32–36B models, even after the weights have been transferred to the GPU.

Host weight buffer release already exists (GGML_OPENVINO_RELEASE_WEIGHTS, or GGML_OPENVINO_MEMORY_OPTIMIZE on GPU), but it is off by default. Released buffers cannot be restored: a later compile would read zeroed pages, so it fails, and the compiled-model cache is kept alive across backend teardown to avoid recompiling.

This change enables host weight buffer release by default on GPU and restores the contents from the model file when they are needed again.

Changes

  • GGML_OPENVINO_RELEASE_WEIGHTS is now enabled by default on GPU. When GGML_OPENVINO_MEMORY_OPTIMIZE is set, it still follows that value.
  • Record every write into a weight buffer, with its offset in the model file.
  • Release (madvise(MADV_DONTNEED)) only the buffers whose contents all come from the model file mapping. Buffers with data from other sources (-lm none, memset, copies) are never released.
  • Keep host buffers that another backend reads at run time.
  • Before a new graph is compiled (dynamic path and static_load_variants) or a weight is read on the host, write the released buffers again from the model file.
  • Remove the old failures on a compile after a release. Always clear the compiled-model cache at backend teardown.
  • Linux only: elsewhere the release does nothing, as before.
  • Update dev_doc/OpenVINO-ENV-VARS.md.

Results

Host memory usage

Steady-state host memory usage (median RssAnon over each run). KLD remained unchanged in every case.

Run Seed-OSS-36B before After Qwen3-32B before After
Perplexity (4 chunks) 24.5 GB 5.0 GB 20.1 GB 4.5 GB
-ngl 40 (partial offload) 15.1 GB 7.3 GB 16.0 GB 5.4 GB
llama-bench (new context per test) 21.7 GB 15.8 GB 17.1 GB 14.5 GB
Perplexity with -lm none 27.2 GB 20.1 GB 19.0 GB 16.8 GB
  • With -lm none, most buffers stay resident by design (their data does not come from a file mapping).
  • Answers were correct in all 3 test cases, both with and without -lm none. In llama-cli, the decode graph is compiled after the weight buffers have been released.

Performance impact

Released weights must be restored from the model file before compiling each new graph. This adds overhead when benchmarks create a new context for each test.

In llama-bench, one timed repetition per test is affected:

Model Test Before After
Seed-OSS-36B pp512 1476 ± 14 t/s 1020 ± 763 t/s
Qwen3-32B pp512 1642 ± 24 t/s 1114 ± 906 t/s

pp2048 performance remained unchanged.

Requirements

  • I have read and agree with the contributing guidelines.
  • AI usage disclosure: YES - AI assistance was used for analysis and running tests.

@osabnis
osabnis force-pushed the ov-release-host-weights branch from 9f1c304 to 81cf53e Compare November 28, 2026 23:37
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