inkling2_loop: co-locate per-pass KV and recurrent state with shared weights in multi-GPU layer split
Configuration
- llama.cpp
6792507b7f611a6fc68bfae3eeae85e88017fc60plus the NVFP4 scale fix from #32704 (2a28df0) - Linux, 2× Tesla T4 (sm_75), PCIe host bridge topology, NVIDIA driver 580.178.04, CUDA toolkit 13.0.88
unsloth/Inkling-2-Mini-GGUF,Mainline_Support/Inkling-2-Mini-UD-Q4_K_XL.gguf_file, revisionea0c79b2ecd73669e774c8519b79bfabfddbc027(linked locally with the.ggufsuffix)
Reproducer
llama-bench -m Inkling-2-Mini-UD-Q4_K_XL.gguf -ngl 999 -sm layer -ts 1/3 -fa on -b 2048 -ub 64 -p 2048 -n 256 -r 3 -v -o jsonl
The weights for physical layers 6–12 are on CUDA0. Their second- and third-pass slots (24–30 and 36–42) have KV and recurrent state on CUDA1. This leaves 14 loop visits with weights and state on different GPUs, despite the loader reporting 49/49 layers offloaded.
Controlled test
After the normal dev_layer assignment in the model loader, the test copies the physical layer's device assignment to each later loop slot. The logical indices and their independent cache allocations are preserved. The experiment applies only to inkling2_loop with full GPU offload in layer split mode, and uses an environment switch to run A/B/A with one binary.
if (params.split_mode == LLAMA_SPLIT_MODE_LAYER && act_gpu_layers == n_layer_all + 1) {
if (const auto * loop = dynamic_cast<const llama_model_inkling2_loop *>(this)) {
for (int il = loop->n_phys; il < n_layer_all; ++il) {
pimpl->dev_layer[il] = pimpl->dev_layer[loop->layer_phys(il)];
}
}
}
| Run | pp2048 tok/s | tg256 tok/s | Slots with mismatched KV and recurrent placement | Scheduler graph splits |
|---|---|---|---|---|
| A1: normal assignment | 172.34 | 19.67 | 14 | 265 |
| B: co-located state | 196.36 | 25.87 | 0 | 17 |
| A2: normal assignment | 161.87 | 19.38 | 14 | 265 |
B is +17.5% prefill and +32.5% decode relative to the mean of the two controls. In a 32K-configured server smoke test, all 32 greedy token IDs and all 320 reported top-10 log probabilities matched exactly. Minimum sampled free VRAM on the tighter GPU increased from 3,625 to 4,547 MiB. That smoke prompt was short. Longer-prompt equivalence is still being tested. A separate patched split sweep found that moving the whole core onto one GPU was slower than retaining 1/3.
Would a scoped change to co-locate the independent per-pass state with the shared weights be welcome?
Hi @CISC , I saw that #32734 was closed and archived without any explanation or notice. I’m happy to wait for Piotr’s Flash Attention work as requested. Was there a concern with the placement change itself, or would you prefer that I retest it once the attention work is available? I’d like to understand what would be useful before opening anything else. The tested diff is still available on my fork.
CC: @pwilkin
When I ran ggml-org/Inkling-2-Mini-GGUF:IQ4_NL split over two GPUs, its at 0 prompt it starts at 25 tps and quickly falls off the cliff, being <10 tps at 70k generation. If I force llama.cpp to use single GPU and reduce ub=128 (which I never have to do), tps rises to >50 tps at 16k prompt.
Another data point for this, on very different hardware: 2× GTX 1070 (Pascal, sm_61, 8 GB each), Windows 11, CUDA 12.9, layer split.
Setup
- llama.cpp master
e6443bd(24 Nov), built for sm_61 unsloth/Inkling-2-Mini-GGUF,Mainline_Support/Inkling-2-Mini-UD-IQ3_XXS.gguf_filellama-server -ngl 99 -sm layer -ts 12,36 -c 8192 -fa on -ub 128, greedy, 3 prompts × 384 tokens- (
-ts 12,36because the default split counts the 48 cache slots and put ~10.5 GB of weights on GPU 0, which failed to load)
What I saw
sched_reserve: graph: nodes = 11513, splits = 265- A per-op timing run showed the expert matmuls were only ~25–30% of GPU time; the rest was hundreds of small ops per split, with pass 2/3 of layers 6..11 reading weights on CUDA0 and KV/conv state on CUDA1.
Change tested (same idea as #32734): give each extra-pass cache slot the device of the physical layer it shares weights with, right after the repeating layers are assigned in load_tensors:
for (int il = 0; il < n_layer_all; ++il) {
pimpl->dev_layer[il] = get_layer_buft_list(il);
}
if (const auto * lp = dynamic_cast<const llama_model_inkling2_loop *>(this)) {
for (int il = lp->n_phys; il < n_layer_all; ++il) {
pimpl->dev_layer[il] = pimpl->dev_layer[lp->layer_phys(il)];
}
}
Results (same build, same flags, only this change):
| splits | tok/s (tg, 384 tokens) | |
|---|---|---|
| upstream placement | 265 | 11.4 |
| slots co-located with weights | 17 | 17.0 (+49%) |
+ --spec-type draft-dspark, --spec-draft-n-max 1 |
17 | 20.0 |
- Greedy output was byte-identical to upstream placement on all three prompts (as expected: only placement changes).
- VRAM stayed balanced (≈6.3 / 6.6 GB at 8K context).
- Note: these tok/s include a local patch that allows CUDA graphs on Pascal (upstream disables them below Volta); without that patch upstream placement gives 8.4 tok/s. The split reduction itself is independent of it.
Happy to rerun anything specific (e.g. after the Flash Attention work lands) if that helps the review.
Thanks @controlcloude for testing this on two GTX 1070s and sharing the setup. Seeing the same 265 → 17 graph split reduction as on my two T4s, with a 49% decode gain and identical greedy output on all three prompts, is a great independent check.
@CISC , given the Pascal and Turing results, would you be open to reviewing a new PR for the placement fix from #32734? I can rerun the A/B on two T4s with a 32K prompt on top of Piotr’s Flash Attention work (#32740) and post the results here first if that would help.
@CISC @pwilkin I ran the 32K retest on two T4s after CUDA Flash Attention landed (a386950, -fa on). Thanks again @controlcloude for checking the placement change on Pascal.
With the same binary and a 32,768-token uncached prompt, the placement fix took prefill from 217.57 to 261.95 tok/s (+20.4%) and decode from 11.76 to 25.33 tok/s (+115.3%) versus the mean of the two stock runs. Graph splits went from 283 to 7, and misplaced slots went from 14 to 0 in each cache. All 128 greedy token IDs matched, though some top-10 probabilities differed.
I've opened #33198