kv-cache : spend the partial residency budget on the slowest link first - #68
Open
Piggidragon wants to merge 4 commits into
Open
kv-cache : spend the partial residency budget on the slowest link first#68Piggidragon wants to merge 4 commits into
Piggidragon wants to merge 4 commits into
Conversation
This was referenced Sep 3, 2026
Owner
|
Automated preliminary review by Codex; the repository owner plans a separate manual review. Verdict: FAIL. Blocking
Will slow review
Developmental progress
Reviewed head: fe9617e |
--kv-gpu-layers was resolved inside each cache, so a cache built from several sub-caches (iSWA, DSA, DSV4, MSA) would have given each of them the full budget and was disabled for all of them. It also counted layers the attention cache does not own, so on a hybrid model most of the budget went to recurrent layers, and it took layers in layer order, which fills the device owning the first layers and leaves the free memory of the others unused. Resolve one set of layer indices for the whole model instead, from the layers the requesting context actually owns, and take them per owning device. An MTP context owns the nextn layers, which sit above the layers of the main context. Assisted-by: Claude Opus 5
The picker excluded every recurrent layer and counted its own choice as the result. Falcon H1 marks all of its layers recurrent yet caches all of them, so a request placed nothing; Nemotron H caches only the non-recurrent layers without an FFN, so part of the budget went to layers the cache then dropped, and the count still said they were resident, which can enable the attention compute offload for nothing. Ask the same ownership filter the hybrid cache uses, and report the layers the caches did place. Assisted-by: Claude Opus 5
A device-resident layer saves the host-to-device transfer it would otherwise cost every token, which is worth most where the link is slowest. Measure the bandwidth once at startup, through the same path the cache is delivered on, and take the layers of the slowest device first. Devices within 15 percent of each other stay one group and keep the round-robin, so their memory use stays even. Assisted-by: Claude Opus 5
The ranking measured a pinned source buffer while the cache uses pageable storage unless kv_cpu_pinned is set, so it timed a path the default configuration does not take. It also gave every eligible layer of the slowest device away without looking at the free memory of that device or at the size of the layer, and the cache has no fallback if its allocation then fails. Measure the storage the cache will use, and stop taking layers from a device before its reported free memory runs out. Assisted-by: Claude Opus 5
Piggidragon
force-pushed
the
mgpu/kv-residency-bandwidth
branch
from
September 6, 2026 06:04
fe9617e to
3c04a16
Compare
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.
Overview
Builds on the residency PR. There,
--kv-gpu-layersspreads round-robin over the owning devices, soeach device gives up the same number of layers. That is the right default only when the devices are
alike.
A device-resident layer saves the host-to-device transfer it would otherwise cost every token, and
that transfer costs most where the link is slowest. On an asymmetric pair the two links differ by a
lot:
A factor of 6.6, so a layer kept off the 3060 is worth 6.6 kept off the 4070.
Measure the host-to-device bandwidth once at startup, through the same path the cache is delivered
on, and spend the budget on the slowest device first. Devices within 15% of each other stay one group
and keep the round-robin, so nothing changes for a symmetric machine.
Testing
Qwen3.8-27B-UD-Q5_K_M, 15216-token prompt,
-c 20480 -n 128 -ngl 99, f16 cache,-sm layer -nkvo --kv-cpu-pinned --recurrent-state-offload. The model has 16 owned attention layers,8 per GPU. "round-robin" is the parent PR, "slowest first" is this one.
--kv-gpu-layersAt 8 layers, the point where the 3060 owns none of the host-resident cache, the two orders cost the
same memory and differ by +86% generation and +51% prefill. Both converge at 0 and at 16,
where every device gives up every layer, which is the expected sanity check.
test-llama-archs -s 1at 1, 2, 3 and 4 virtual CUDA devices: passes. Built with-DLLAMA_FATAL_WARNINGS=ON.Not done here
Deriving
--attn-splitor--tensor-splitfrom the same measurement. The measurement is there andthe rounding would land on a useful value for this pair, but it changes the reduction order for every
multi-GPU user, so it stays out until it has run on more than one machine.
Requirements
Assisted-by:commit trailer.