Repository navigation
ggml-hrx: materialize weights on demand and keep them resident - #160
Draft
AaronStGeorge wants to merge 11 commits into
Draft
AaronStGeorge wants to merge 11 commits into
AaronStGeorge wants to merge 11 commits into
Conversation
AaronStGeorge
force-pushed
the
hrx-graph-develop-v2
branch
from
October 30, 2026 16:52
44ee571 to
6851a42
Compare
Materialize imported weights in selected layouts, retain demand per source region, and retire obsolete representations after GPU users complete. Keep other immutable GGUF weights on reusable native storage. Assisted-by: Codex
AaronStGeorge
force-pushed
the
users/astgeorg/hrx-weight-residency
branch
from
October 30, 2026 20:12
ce9c50c to
fb85f01
Compare
Assisted-by: Codex
Reuse exact prepared owners at the admitted residency revision while retaining asynchronous completion ownership. Share immutable weight lease lists across prepared, recorded and current owners, and preserve direct host-input completion. Bead: lemonade-ws-tek.26
Assisted-by: Codex
…tgeorg/hrx-prepared-instance-reuse # Conflicts: # ggml/src/ggml-hrx/README.md
1 task
Assisted-by: Codex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On
hrx-graph-develop-v2, standard GPU model loading makes the native weight representation resident up front. When a kernel requests a repacked layout, HRX materializes an additional GPU allocation while keeping the original native weights resident. A repacked weight therefore occupies both native and repacked storage, even if no selected kernel needs the native layout. The original allocation is unconditional; the repack is added on demand.This duplication consumes memory that should be available for KV cache and execution buffers. On the tested 24 GiB RX 7900 XTX, Qwen3.8-27B Q4_K_M (16.55 GiB GGUF) and Mistral-Small-3.2-24B Q4_K_M (13.35 GiB GGUF) cannot complete Lemonade
chat-long-outputat context 4096 with the tested HRX offload settings, despite their model files being substantially smaller than the GPU's capacity. Baseline failures explicitly report HSA resource exhaustion while allocating the transient arena.Solution
Materialize weights on demand and keep each requested representation resident. Ordinary imported GGUF weights describe borrowed, immutable source bytes without eagerly creating a GPU copy. When a selected command first requests a weight layout, the cache materializes that representation, allocates its GPU storage, and uploads it. Later requests and prefill/decode transitions reuse the cached allocation. Unused layouts are never materialized. Existing directly bindable coherent storage is reused, and uploaded device weights, CPU weights, and HRX host buffers retain their native-only eligibility rules.
When a second layout of the same source region is actually materialized, log both layouts and their resident byte cost once on insertion. This identifies kernels that require duplicate weight storage and should converge on a common layout. First-use packing, allocation, and upload still cost time; multiple layouts remain resident if the selected kernels require them.
We also tested unloading weights when demand changed and reloading them for the next phase, in both synchronous and asynchronous designs. Repeated rematerialization proved too slow for retained-model serving. One measured prefill/decode cycle performed 442 materializations totaling 8.142 GB: about 46.54 ms allocating, 634.73 ms uploading, and 352.81 ms in other rematerialization work, or roughly 1.03 seconds altogether. Releasing the old allocations took only about 0.63 ms. Allocation alone was not the dominant cost; repeatedly rebuilding and uploading the weights was. This revision therefore removes transition eviction, retirement polling, weight submission tracking, demand revisions, and obsolete-owner invalidation. The earlier experiments and their evidence remain preserved.
Prepared and recorded programs retain ordinary shared allocation leases. Mutable host staging, imported writeback, direct-input completion, and backend teardown keep their existing ownership rules. Validated graph-instance reuse avoids repeating full binding work on stable executions; mutable-source rebinding returns to full lookup. Both routes share the prepared cache and executor, and the cheaper cache-miss metadata/hash path is retained. A guard-only ablation measured a warm-decode slowdown, so the corrected fast path remains. This PR changes neither HRX runtime nor kernels.
Validation
Exact comparison: candidate
463fd0b285835d36cf15544b7bc121fc37400ca7versus basef6d215d01be5c9b28350f21cf310629a6dff4b5b, both with HRX82214dfb029975205d1c3a59164b678e2e21fc41, matching build options and frozen runtime dependencies, on RX 7900 XTX (gfx1100). No HRX runtime or kernel changes are included by this PR.827a95c86; all 224 backend checks passed again after each of the small watch-capture and binding-construction follow-ups. An initial overlap-test failure was an obsolete zero-common-cache-build assertion; the corrected test verifies three shared entries and native-entry reuse. Original failure evidence is retained.tg128invocations per model (five repetitions, settled mean of repetitions 2-5): Llama +0.146% (95% interval +0.045% to +0.248%); Qwen -0.040% (-0.200% to +0.121%). These intervals do not establish exactly zero overhead.The fixed uninstrumented follow-up uses five warmups and then three measured requests, six AB/BA pairs, and the mean of all three measured requests. Generation +0.058% [-0.966%, +1.092%]; prefill -0.435% [-4.757%, +4.084%]; backend TTFT +0.394% [-4.797%, +5.869%]; total backend request -0.050% [-1.030%, +0.939%]. All paired text and token counts match; frozen runtime hashes are unchanged. This is a different warmup protocol and does not replace the original one-warmup result.
All-model primary measurements and fixed independent repeats
The Lemonade protocol uses version 2026.43.3,
chat-long-output, context 4096, explicit--spec-type none,--no-cache-prompt,--no-reload, one warmup and three retained requests per independent invocation. Six alternating baseline/candidate pairs per model use retained positions 2/3 as the primary estimate; position 1 remains reported separately. Reported intervals are nominal paired 95% intervals, not proof of exactly zero overhead. Instrumentation is excluded from timing runs.Keeping multiple demanded layouts can increase steady-state GPU memory. First-use packing/allocation/upload costs remain. This change makes those costs persistent cache misses instead of recurring phase-transition work. The separate all-consumer row64 kernel experiment is not included.
Earlier asynchronous, synchronous and trusted-reuse experiments and their validation artifacts remain preserved. Historical full-tier perplexity/performance results do not establish acceptance of this revision; the broader fresh full-tier/PPL work remains tracked separately. Measurements cover standard text inference on this gfx1100 GPU, with speculative decoding disabled; they do not cover MTP modes or multimodal prompts. This PR stays a draft for human review.
Requirements