Skip to content

[Bug] Tensor split decode up to 2.9x slower since b10715-mix-86bd2d3 possibly "max_cuda_graphs = 64" from #144 (2x RTX 5070 Ti, Windows/WSL2/Linux) #12468

Closed

Description

@floewe

With two GPUs in --split-mode tensor (with or without --spec-type draft-mtp), every Unsloth prebuilt from b10715-mix-86bd2d3 onwards generates at roughly 48 t/s on native Windows, while b10687-mix-67dfc8b and the official ggml-org builds b10715, b11160 and b11320 reach 115 to 129 t/s with the same model file, the same command line and the same hardware.

  • Only the tensor split decode path is affected. Single GPU and --split-mode layer are equally fast in good and bad builds, with or without MTP.
  • Prompt processing is unaffected (about 2000 t/s in all builds), and MTP draft acceptance is the same everywhere (about 90 percent).
  • The Unsloth Linux prebuilts show the same regression under WSL2 on the same machine (factor 2.9). On a rented bare-metal Linux machine with 2x RTX 5070 Ti it is present too, but smaller (about 8 to 30 percent depending on the quant); the official b10715 is unaffected there as well.
  • The affected builds allocate exactly 36 MiB less VRAM per GPU than the good ones, on Windows, WSL2 and Linux.
  • The good build with GGML_CUDA_DISABLE_GRAPHS=1 matches the bad build in speed and VRAM, so the affected builds lose CUDA graph reuse in tensor split mode.
  • Root cause confirmed by rebuilding the release source: changing only static const size_t max_cuda_graphs = 64; (added in MTP for Qwen3.8-Flash-Next llama.cpp#144) to a large value restores full speed; reverting the new graph key does not (details below).

Probably not the same bug as #11349 (single RTX 5070 Ti on Windows): on a single 5070 Ti the affected build is as fast as the good one here, and #11349 also shows slow prefill, which I do not see. It does explain why a single-GPU comparison would not catch this one.

Unless marked otherwise, all numbers are native Windows with the windows-x64-cuda13-newer Unsloth prebuilts and the ggml-org Windows CUDA builds.

Results, native Windows

All runs in one session (01.10.2026), same model file, same flags, one build after the other. "short" is three requests of 600 generated tokens with a 36-token prompt, "long" is one request with a 20335-token prompt.

Build Source short (t/s) long (t/s) prompt (t/s) VRAM per GPU
b10687-mix-67dfc8b Unsloth 121.3 / 123.3 / 120.6 112.1 2052 14672 MiB
b10715 ggml-org 122.6 / 118.0 / 125.6 105.4 2037 14672 MiB
b10715-mix-86bd2d3 Unsloth 50.7 / 50.4 / 50.1 49.4 1994 14636 MiB
b10798-mix-659e406 Unsloth 48.7 / 49.7 / 50.6 49.0 1991 14636 MiB
b10840-mix-d5c17a0 Unsloth 48.3 / 51.1 / 47.6 47.9 2011 14636 MiB
b11030-mix-5ff778e Unsloth 47.8 / 49.9 / 50.4 49.1 2006 14636 MiB
b11160-mix-a6922cc Unsloth 46.3 / 45.2 / 45.3 40.0 2015 14636 MiB
b11160 ggml-org 123.3 / 124.9 / 129.0 109.8 2076 14672 MiB
b11320 ggml-org 116.7 / 116.2 / 128.8 108.0 2061 14672 MiB

b10687, b10715, b10798 and b10840 were measured a second time in a separate run with the same result (good: 115.5 / 114.4 / 119.9, bad: 46.9 to 51.5).

Draft acceptance was between 85 and 93 percent in every build, for example 388/421 (b10687) vs 390/418 (b10715).

WSL2 check

Same machine, Ubuntu 24.04 under WSL2, Unsloth linux-x64-cuda13-newer prebuilts, same model and flags (model loaded from the distro's ext4):

Build short (t/s) long (t/s) VRAM per GPU
b10687-mix-67dfc8b 95.4 / 104.1 / 101.9 97.6 14700 MiB
b10715-mix-86bd2d3 35.5 / 36.6 / 34.4 31.6 14664 MiB

Same step, same 36 MiB difference, so it is not tied to the Windows binaries. WSL2 still uses the Windows NVIDIA driver, so this is not a bare-metal Linux result. The ggml-org builds were not run under WSL2.

Bare-metal Linux check

Rented machine (vast.ai), 2x RTX 5070 Ti 16 GB, driver 595.91.07, Ubuntu 24.04.4, kernel 6.8.0-138, nvidia-smi topo -p2p r reports CNS between the two GPUs. Unsloth linux-x64-cuda13-newer prebuilts; ggml-org b10715 built from tag b10715 (662a0b0) with CUDA 13.2, -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120. ctx 32768, no mmproj, otherwise the same flags. Three short runs each, long prompt in brackets.

Model / mode Unsloth b10687-mix-67dfc8b Unsloth b10715-mix-86bd2d3 ggml-org b10715
Q4_K_M, tensor, MTP 127.0 / 133.2 / 135.7 (120.6) 114.4 / 125.9 / 124.0 (118.8) 132.0 / 136.8 / 135.1 (122.9)
Q4_K_M, tensor, no MTP 69.3 / 69.6 / 69.7 (64.7) 64.8 / 64.9 / 65.0 (64.1) 69.2 / 69.5 / 69.7 (65.1)
Q4_K_M, layer, MTP 93.8 / 96.7 / 95.8 (84.5) 94.7 / 93.5 / 90.3 (83.1) 93.3 / 94.9 / 89.8 (82.5)
Q2_K_XL, tensor, MTP 134.0 / 135.2 / 129.3 (126.7) 93.4 / 92.7 / 94.5 (92.2) 131.2 / 128.4 / 138.1 (130.1)
Q2_K_XL, tensor, no MTP 71.5 / 72.1 / 72.1 (66.3) 54.4 / 54.5 / 54.5 (53.8) 84.6 / 85.8 / 85.7 (78.7)
Q2_K_XL, layer, MTP 101.7 / 99.7 / 102.7 (91.1) 102.3 / 101.5 / 99.7 (94.0) 99.5 / 98.5 / 101.7 (95.5)
Q2_K_XL, single GPU, MTP 99.8 / 98.3 / 100.8 (91.4) 102.0 / 98.2 / 99.9 (89.5) 95.5 / 98.8 / 97.0 (91.8)
Q2_K_XL, single GPU, no MTP 61.6 / 61.5 / 61.7 (55.2) 61.2 / 61.2 / 61.3 (54.9) 59.6 / 59.7 / 59.7 (53.8)

On bare-metal Linux the regression is also there, but smaller: about 30 percent for Q2_K_XL and about 8 percent for Q4_K_M in tensor split mode, compared to a factor of 2.4 to 2.9 on Windows and WSL2 on my machine. Layer split and single GPU are again equal in all three builds. The 36 MiB VRAM difference per GPU shows up here as well (for example 6278 vs 6240 MiB).

It is the tensor split path, not MTP (native Windows)

Same model (UD-Q4_K_M), b10687-mix-67dfc8b vs b10715-mix-86bd2d3:

Mode b10687 short (t/s) b10715 short (t/s) b10687 long b10715 long
tensor split, MTP, ctx 262144 115.5 / 114.4 / 119.9 50.7 / 50.4 / 50.1 103.0 49.4
tensor split, no MTP, ctx 262144 66.2 / 67.1 / 66.8 24.1 / 24.9 / 23.9 59.3 24.0
layer split, MTP, ctx 131072 89.2 / 78.7 / 92.0 91.7 / 88.9 / 90.7 76.0 75.6

Layer split needs ctx 131072 here because it distributes less evenly; at 262144 the MTP context fails to allocate in both builds.

Single GPU, smaller quant of the same model (Qwen3.8-27B-UD-Q2_K_XL.gguf, ctx 32768, CUDA1 only, --split-mode none):

Mode b10687 short (t/s) b10715 short (t/s) b10687 long b10715 long
single GPU, MTP 95.8 / 95.1 / 96.7 93.0 / 96.8 / 98.6 86.5 90.8
single GPU, no MTP 61.4 / 62.6 / 60.8 61.5 / 62.0 / 61.9 55.3 55.2
same Q2 file, tensor split on 2 GPUs, MTP 122.4 / 126.3 / 126.7 44.6 / 43.5 / 41.7 103.3 45.0

Without MTP the drop is the same (factor 2.8). With --split-mode layer and on a single GPU both builds are equal. So the regression is in the SPLIT_MODE_TENSOR decode path, independent of model file and quant.

Where it was introduced

The regression appears between b10687-mix-67dfc8b (good) and b10715-mix-86bd2d3 (bad). The official ggml-org b10715, same upstream build number, is fast (122.6 / 118.0 / 125.6 t/s), so the slowdown is not in upstream code but in the patches carried by the mix. Comparing the release notes, these are the patches added in mix-86bd2d3:

Ruled out: #149. Setting GGML_CUDA_ENABLE_UNIFIED_MEMORY=0 explicitly on b10715-mix-86bd2d3 leaves it at 48.2 to 51.5 t/s. The variable is not set on this machine otherwise.

The affected builds behave as if CUDA graphs were disabled

Native Windows, UD-Q4_K_M, tensor split with MTP, ctx 262144:

CUDA graphs on (default) GGML_CUDA_DISABLE_GRAPHS=1
b10687-mix-67dfc8b 114.3 / 114.7 / 119.0 t/s, 14672 MiB 52.8 / 49.4 / 51.3 t/s, 14636 MiB
b10715-mix-86bd2d3 50.5 / 50.4 / 50.8 t/s, 14636 MiB 49.4 / 53.0 / 53.1 t/s, 14636 MiB

With graphs disabled the good build drops to exactly the level of the bad one, and its VRAM matches the bad build to the MiB. The bad build does not change when graphs are disabled. So in tensor split mode the affected builds effectively run without CUDA graph reuse, which also accounts for the 36 MiB difference.

Of the six patches above, #144 is the only one that touches CUDA graph handling (ggml_cuda_graph_get_key now hashes node count and shapes, and cuda_graphs is capped at 64 entries with LRU eviction).

Confirmed: the max_cuda_graphs = 64 cap from #144

I built the exact release source (llama.cpp-source-commit-92cedc8679d145902ead3f006258e8672eac11e6.tar.gz from the b10715-mix-86bd2d3 release, SHA256 checked) in three variants, CUDA 13.3, -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120 -DGGML_NATIVE=OFF, and ran them in WSL2 with the same flags as above (UD-Q4_K_M, tensor split, MTP, ctx 262144):

Build short (t/s) long (t/s) VRAM per GPU
Unsloth b10687-mix-67dfc8b prebuilt (reference, good) 96.5 / 97.1 / 92.5 88.0 14700 MiB
Unsloth b10715-mix-86bd2d3 prebuilt (reference, bad) 31.6 / 32.3 / 33.4 32.2 14664 MiB
A: source as released 32.5 / 32.2 / 33.4 30.6 14664 MiB
B: ggml_cuda_graph_get_key reverted to return (uint64_t)(uintptr_t) cgraph->nodes[0]; 32.9 / 29.2 / 31.6 32.6 14664 MiB
C: only static const size_t max_cuda_graphs = 64; changed to 1048576 93.8 / 101.2 / 100.9 96.0 14752 MiB

A reproduces the prebuilt exactly. Reverting the new graph key (B) changes nothing. Lifting the cap (C), with everything else unchanged, restores full speed. So in tensor split mode the number of CUDA graphs per context evidently exceeds 64, and the LRU eviction makes them re-capture instead of replay. Single GPU and layer split stay below the cap, which matches them being unaffected.

The diff for C:

--- a/ggml/src/ggml-cuda/common.cuh
+++ b/ggml/src/ggml-cuda/common.cuh
@@ -1453,7 +1453,7 @@
     // a cuda graph instance is only valid for the shapes it captured, so a caller that
     // alternates shapes needs one instance per shape to stay on the graph path
-    static const size_t max_cuda_graphs = 64;
+    static const size_t max_cuda_graphs = 1048576;

That is only a test, not a proposed fix; the right limit (or making it depend on the number of splits) is your call.

Command line

Native Windows, identical for every build, only the executable differs:

llama-server.exe -m Qwen3.8-27B-UD-Q4_K_M.gguf --mmproj mmproj-F16.gguf --mmproj-device CUDA2 ^
  --host 0.0.0.0 --port 8097 --parallel 1 --flash-attn on --no-context-shift ^
  -c 262144 --gpu-layers 99 --fit off --kv-unified ^
  --cache-type-k q8_0 --cache-type-v q8_0 ^
  --split-mode tensor --device CUDA0,CUDA1 ^
  --load-mode dio --jinja --spec-type draft-mtp --spec-draft-n-max 2 --metrics

For the isolation runs only --split-mode, --device, -c and the presence of the two --spec-* flags change, as listed in the tables. The WSL2 runs use the same flags with the Linux binary (and the Q8_0 mmproj from the same repo).

Requests: /v1/chat/completions, temperature 0.3, enable_thinking: false, max_tokens 600.

Model: unsloth/Qwen3.8-27B-GGUF, files Qwen3.8-27B-UD-Q4_K_M.gguf and Qwen3.8-27B-UD-Q2_K_XL.gguf (snapshot 4ca720788d1e01f1bff70c033e0d0028fd02e502), mmproj mmproj-F16.gguf (snapshot f1bfb127c64f7072bdd2cad55f258b9c8b2910fe).

The only notable log line, present in good and bad builds alike:

W set_sampler: backend sampling not supported with SPLIT_MODE_TENSOR; using CPU

No AllReduce fallback warning in any build.

Environment

  • Windows 11 Pro 10.0.26200; WSL2 with Ubuntu 24.04 for the WSL2 check (the bare-metal Linux machine is described in its own section)
  • AMD Ryzen 7 9700X, 64 GB RAM
  • 3x NVIDIA GeForce RTX 5070 Ti 16 GB (SM 120): two for the model (CUDA0, CUDA1), one for the vision projector (CUDA2). Display on the iGPU, the NVIDIA cards drive no display.
  • NVIDIA driver 616.92, CUDA 13.4 driver API
  • Unsloth builds: app-bXXXXX-mix-XXXXXXX-windows-x64-cuda13-newer.zip and, for WSL2, app-bXXXXX-mix-XXXXXXX-linux-x64-cuda13-newer.tar.gz from the GitHub releases, SHA256 checked against the release digest
  • ggml-org builds: llama-bXXXXX-bin-win-cuda-13.4-x64.zip plus cudart-llama-bin-win-cuda-13.4-x64.zip (b10715: the 13.3 packages, the only ones published for that build)

Happy to run a test build or a specific patch reverted if that helps.

Activity

  1. EmergentMonk commented on Oct 1, 2026

    @EmergentMonk

    Excellent report — this is a really nice piece of regression isolation.

    The part that stood out to me is that the failure mode appears to be less about CUDA graphs themselves and more about a fixed cache bound falling below the active reuse working set:

    max_cuda_graphs = 64
    → eviction / recapture pressure
    → graph reuse collapses in tensor-split mode
    → large decode regression

    Your experiment changing only that bound, while separately ruling out the graph-key change, makes that especially convincing.

    I maintain an optimization-pattern catalog called OPT:

    https://github.com/QSOLKCB/OPT

    One of its core rules is not to cargo-cult constants: worker caps, cache sizes, thresholds, tolerances, block sizes, etc. should stay tied to the environment that established them until they are re-measured or derived for the new workload.

    This issue is actually a very good example of that principle. The lesson probably isn't “64 should become 1048576”, but rather that the cache capacity needs to reflect the number of distinct reusable graph states in the active workload/topology, or otherwise avoid pathological eviction.

    I may turn this into a new OPT pattern around working-set-aware cache capacity / reuse-thrash avoidance, with this issue cited as an external real-world example if you're happy with that.

    Really solid debugging work. :-)

  2. floewe commented on Oct 2, 2026

    @floewe
    Author

    Follow-up with numbers on why a cap of 64 cannot work for tensor split.

    How the numbers were obtained

    • Source: the exact release source llama.cpp-source-commit-92cedc8679d145902ead3f006258e8672eac11e6.tar.gz from b10715-mix-86bd2d3, SHA256 checked against the release digest.
    • Instrumentation: a counter in ggml_backend_cuda_context::cuda_graph() in ggml/src/ggml-cuda/common.cuh (patch below). It only counts and does not change any decision. Each time the existing 5 s eviction sweep runs, it prints one line per device to stderr:
      • active: entries whose last_used_time is less than 1 s old, i.e. the graphs the workload is actually cycling through,
      • size / max: current and highest number of entries,
      • created: new entries (each one is a fresh capture),
      • evicted_by_cap: LRU evictions caused by max_cuda_graphs, and fresh: how many of those victims had been used less than 1 s before eviction.
    • Two builds from that source: the counter with max_cuda_graphs = 64 as released, and the counter with only that line changed to 1048576. Built with CUDA 13.3, -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120 -DGGML_NATIVE=OFF -DLLAMA_CURL=OFF, target llama-server.
    • Runs: WSL2 (Ubuntu 24.04) on 2x RTX 5070 Ti 16 GB, driver 616.92. -c 32768 --gpu-layers 99 --fit off --flash-attn on --kv-unified --cache-type-k q8_0 --cache-type-v q8_0 --parallel 1 --jinja, plus the split mode and devices shown in the tables (--split-mode tensor --device CUDA0,CUDA1, --split-mode layer --device CUDA0,CUDA1, or --split-mode none --device CUDA0), and --spec-type draft-mtp --spec-draft-n-max 2 for the MTP rows. Three /v1/chat/completions requests of 600 generated tokens each (temperature 0.3, thinking off), then a 6 s pause so the sweep logs once more after the last request. The tables show the highest active value seen during the run and the last counter line.
    • With MTP each device has two CUDA contexts (target model and MTP draft), each with its own graph cache. The values below are for the target model context; the MTP draft context stayed at about 6 active graphs.
    Counter patch (diagnostic only, does not change behaviour)

    It adds a few counters to the graph cache, increments them where entries are created and evicted, and reuses the existing 5 s sweep to print one line per device. Cache decisions are untouched.

    --- a/ggml/src/ggml-cuda/common.cuh
    +++ b/ggml/src/ggml-cuda/common.cuh
    @@ struct ggml_backend_cuda_context {
         int64_t last_graph_eviction_sweep = 0;
    +    uint64_t gs_created = 0, gs_evict_cap = 0, gs_evict_recent = 0, gs_evict_time = 0, gs_lookups = 0;
    +    size_t   gs_max_size = 0;
     
         ggml_cuda_graph * cuda_graph(uint64_t graph_key) {
             const int64_t time_now = ggml_time_us();
     
             // sweep every 5s, evicting cuda graphs unused for >=10s
             if (time_now - last_graph_eviction_sweep >= 5'000'000) {
                 last_graph_eviction_sweep = time_now;
    +            {
    +                size_t active = 0;
    +                for (const auto & kv : cuda_graphs) {
    +                    if (time_now - kv.second->last_used_time < 1'000'000) active++;
    +                }
    +                fprintf(stderr, "[counter] dev=%d size=%zu max=%zu active_1s=%zu created=%llu evicted_by_cap=%llu fresh=%llu evicted_by_time=%llu lookups=%llu\n",
    +                    device, cuda_graphs.size(), gs_max_size, active,
    +                    (unsigned long long) gs_created, (unsigned long long) gs_evict_cap,
    +                    (unsigned long long) gs_evict_recent, (unsigned long long) gs_evict_time,
    +                    (unsigned long long) gs_lookups);
    +            }
                 for (auto it = cuda_graphs.begin(); it != cuda_graphs.end(); ) {
                     if (time_now - it->second->last_used_time >= 10'000'000) {
    +                    gs_evict_time++;
                         it = cuda_graphs.erase(it);
    @@
                     }
    +                gs_evict_cap++;
    +                if (time_now - lru->second->last_used_time < 1'000'000) gs_evict_recent++;
                     cuda_graphs.erase(lru);
                 }
                 it = cuda_graphs.emplace(graph_key, std::make_unique<ggml_cuda_graph>()).first;
    +            gs_created++;
    +            if (cuda_graphs.size() > gs_max_size) gs_max_size = cuda_graphs.size();
             }
    +        gs_lookups++;
             it->second->last_used_time = time_now;

    (My local copy uses German field names in the log line; renamed here for readability, the logic is identical.)

    Graphs in use at the same time, per device (cap lifted)

    Model (layers) tensor split tensor split + MTP layer split single GPU
    Qwen3.8-27B UD-Q2_K_XL (65) 129 258 2-3 3-4
    gemma-4-31B-it UD-IQ2 (60) 121 – 2-3 –
    Muse-Glimmer-30B UD-Q4_K_XL (52) 105 – 2-3 (with DFlash draft) –

    In tensor split mode each decode step needs 2 x layers + 1 graphs per device, one per segment between the cross-device reductions. Every additional shape doubles that: with MTP the verify step alternates with the normal step, so Qwen needs 258; the other models also briefly reached 242 / 210 at the prompt-to-decode transition. Over a run 700 to 900 entries accumulate; the existing 10 s sweep removes the old ones without any measurable cost.

    So any model with more than about 31 layers exceeds 64 in tensor split mode, even without speculative decoding.

    What the cap of 64 does

    Qwen3.8-27B, tensor split without MTP, cap 64, about two minutes:

    dev=0 size=64 created=229878 evicted_by_cap=229814 of_which_fresh=229750
    dev=1 size=64 created=229991 evicted_by_cap=229927 of_which_fresh=229863
    

    Practically every graph is evicted before its next use and re-captured on every token.

    Speed, same builds, short requests (t/s)

    Same source and flags, measured in an earlier run with the counter compiled in but before its output went to stderr, so these runs carry no counter lines.

    Model, tensor split cap 64 cap lifted factor
    Qwen3.8-27B, MTP 32.0 / 32.1 / 33.1 90.9 / 104.2 / 96.7 3.0
    Qwen3.8-27B, no MTP 14.7 / 15.7 / 15.2 63.5 / 68.8 / 63.2 4.3
    gemma-4-31B-it 17.4 / 18.0 / 17.6 53.5 / 55.4 / 55.2 3.1
    Muse-Glimmer-30B 19.9 / 19.7 / 20.3 56.6 / 57.5 / 58.4 2.9

    Layer split and single GPU are identical with and without the cap for all three models.

    So this is not specific to one model: the common "two 16 GB cards, tensor split" setup is affected for every recent model I tried.

    A possible fix: let the cap grow when it thrashes

    The cap's purpose from 5a08a717, bounding the number of entries when many distinct prefill shapes show up, is preserved by the hard limit below. The single-GPU numbers in that commit message (4 captures for Qwen3.8-27B UD-Q2_K_XL) match mine; the difference only shows up with tensor split.

    Since the working set depends on model depth, split mode and the number of shapes, any fixed value will be too small for some setup. What worked for me is keeping 64 as the starting value but doubling it whenever the LRU victim was still in use less than a second ago, which only happens when the cap is below the working set. A hard limit keeps the case the cap was introduced for bounded, and the existing 10 s sweep still removes stale entries.

    --- a/ggml/src/ggml-cuda/common.cuh
    +++ b/ggml/src/ggml-cuda/common.cuh
    @@ struct ggml_backend_cuda_context {
    -    // a cuda graph instance is only valid for the shapes it captured, so a caller that
    -    // alternates shapes needs one instance per shape to stay on the graph path
    -    static const size_t max_cuda_graphs = 64;
    +    // a cuda graph instance is only valid for the shapes it captured, so a caller that
    +    // alternates shapes needs one instance per shape to stay on the graph path.
    +    // Starts at 64 and doubles whenever the LRU entry would have to be evicted although it
    +    // was used within the last second, i.e. when the cap is below the working set (tensor
    +    // split needs about 2 * n_layers graphs per shape and device). Stale entries are still
    +    // swept after 10 s, and max_cuda_graphs_limit keeps many distinct shapes bounded.
    +    size_t max_cuda_graphs = 64;
    +    static const size_t max_cuda_graphs_limit = 2048;
    @@ ggml_cuda_graph * cuda_graph(uint64_t graph_key) {
                 while (cuda_graphs.size() >= max_cuda_graphs) {
                     auto lru = cuda_graphs.begin();
                     for (auto c = cuda_graphs.begin(); c != cuda_graphs.end(); ++c) {
                         if (c->second->last_used_time < lru->second->last_used_time) {
                             lru = c;
                         }
                     }
    +                if (time_now - lru->second->last_used_time < 1'000'000 && max_cuda_graphs < max_cuda_graphs_limit) {
    +                    max_cuda_graphs = std::min(2 * max_cuda_graphs, max_cuda_graphs_limit);
    +                    continue;
    +                }
                     cuda_graphs.erase(lru);
                 }

    Measured with the same setup as above (this build still had the counter compiled in to show what the cap does; the counter is not part of the proposed change):

    Model, mode cap 64 (released) cap lifted growing cap cap reached
    Qwen3.8-27B, tensor split, MTP 32 t/s 87-97 t/s 93-96 t/s 512
    Qwen3.8-27B, tensor split, no MTP 15 t/s 53-60 t/s 57-61 t/s 512
    gemma-4-31B-it, tensor split 18 t/s 52-55 t/s 54-56 t/s 1024
    Muse-Glimmer-30B, tensor split 20 t/s 57-59 t/s 57 t/s 512
    all three, layer split and single GPU unchanged unchanged unchanged stays at 64
    • With the growing cap no entry was evicted while still in use (fresh = 0 in every run); the few cap evictions that remain are old shapes.
    • Layer split and single GPU never trigger growth, so their behaviour is exactly as before.
    • Gemma reached 1024 because up to 727 entries are alive at the prompt-to-decode transition; still well below the hard limit of 2048.
    • VRAM per GPU ends up the same as with the cap lifted, i.e. the few dozen MiB the reused graphs occupy.
    • Not measured: many distinct shapes within one second (e.g. high concurrency with varied prompt lengths) would also grow the cap, up to the hard limit, so memory use can be higher than with the fixed 64 in that case until the 10 s sweep removes the entries.
    • Not tested with Qwen3.8-Flash-Next, which is too large for this machine. On a single GPU it should stay well below 64 and never trigger growth, but I have not verified that.

    The 1 s threshold and the limit of 2048 are arbitrary values I picked, not tuned ones.

  3. floewe commented on Oct 2, 2026

    @floewe
    Author

    I may turn this into a new OPT pattern around working-set-aware cache capacity / reuse-thrash avoidance, with this issue cited as an external real-world example if you're happy with that.

    Really solid debugging work. :-)

    Thanks, fine with the citation. I gave it a try and made the cap adapt to the graphs actually in use; details in my comment above.

  4. LeoBorcherding commented on Oct 2, 2026

    @LeoBorcherding
    Collaborator

    Thanks for the counter runs, they settle it. A fixed cap can't work for tensor split: it needs about 2 x layers + 1 graphs per device per shape, so anything past ~31 layers thrashes at 64, which is exactly what your evicted_by_cap ≈ created lines show.

    There's already a PR against the MTP carry branch that raises the cap to 512: unslothai/llama.cpp#232. By your numbers that covers steady-state decode for all three models, but not Gemma's 727 live graphs at the prompt-to-decode transition, and a deeper model with MTP will outgrow it the same way 64 was outgrown. Your growing cap avoids picking another number and leaves single GPU and layer split exactly as they are, so I think it's the better fix.

    I've opened it as unslothai/llama.cpp#238 with your patch and numbers, credited to you.

  5. floewe commented on Oct 3, 2026

    @floewe
    Author

    I've opened it as unslothai/llama.cpp#238 with your patch and numbers, credited to you.

    Thanks for picking it up and for the constexpr fix. Happy to re-test #238 on the 2x 5070 Ti setup once it lands in a build.

  6. LeoBorcherding commented on Oct 4, 2026

    @LeoBorcherding
    Collaborator

    @floewe it'd help a lot if you could run it before it's in a build. The branch is fix/cuda-graph-cap-grow on LeoBorcherding/llama.cpp:

    git clone -b fix/cuda-graph-cap-grow https://github.com/LeoBorcherding/llama.cpp
    cd llama.cpp
    cmake -B build -DGGML_CUDA=ON
    cmake --build build --config Release -j
    

    The same tensor-split commands you used for the counter runs are enough. What settles it is decode t/s against b10715 and whether evicted_by_cap stays near zero after warmup. A single-GPU run as a sanity check would be nice too, since that path shouldn't change at all.

  7. floewe commented on Oct 4, 2026

    @floewe
    Author

    @LeoBorcherding

    Tested #238, branch fix/cuda-graph-cap-grow at 5df4722d7. It works as intended.

    Setup

    • Built the branch twice on Linux with CUDA 13.3, -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120 -DGGML_NATIVE=OFF -DLLAMA_CURL=OFF, target llama-server: once unchanged, once with the same diagnostic counter as in my earlier runs (counts and logs only, no change to cache decisions).
    • Baseline: the Unsloth prebuilt b10715-mix-86bd2d3, linux-x64-cuda13-newer.
    • Run in WSL2 (Ubuntu 24.04) on 2x RTX 5070 Ti 16 GB, driver 616.92, same flags as the counter runs: -c 32768 --gpu-layers 99 --fit off --flash-attn on --kv-unified --cache-type-k q8_0 --cache-type-v q8_0 --parallel 1 --jinja, plus split mode and devices as listed, and --spec-type draft-mtp --spec-draft-n-max 2 for the MTP rows. Three requests of 600 tokens each.

    Decode t/s

    Model, mode b10715-mix-86bd2d3 #238 #238 + counter
    Qwen3.8-27B UD-Q2_K_XL, tensor split, MTP 34.2 / 31.7 / 28.6 93.6 / 101.8 / 90.2 88.9 / 96.0 / 94.6
    Qwen3.8-27B UD-Q2_K_XL, tensor split, no MTP 14.3 / 14.4 / 14.1 60.9 / 66.6 / 67.2 65.7 / 63.5 / 66.6
    Qwen3.8-27B UD-Q2_K_XL, layer split, MTP 76.8 / 78.2 / 83.3 80.2 / 84.8 / 83.8 80.2 / 82.9 / 74.2
    Qwen3.8-27B UD-Q2_K_XL, single GPU, MTP 88.8 / 86.7 / 96.6 92.0 / 86.3 / 85.3 85.3 / 93.5 / 84.0
    gemma-4-31B-it UD-IQ2, tensor split 17.5 / 17.4 / 17.2 56.9 / 65.9 / 62.3 55.1 / 56.2 / 57.1
    gemma-4-31B-it UD-IQ2, layer split 44.8 / 45.2 / 45.6 44.7 / 45.1 / 47.2 45.1 / 45.4 / 45.4
    gemma-4-31B-it UD-IQ2, single GPU 46.7 / 48.0 / 46.2 47.3 / 46.9 / 46.0 46.5 / 46.2 / 45.2

    Tensor split is back to the speed of the build with the cap lifted; layer split and single GPU are unchanged.

    Counter, target model context, device 0

    Run cap reached evicted_by_cap of which fresh (< 1 s)
    Qwen, tensor split, no MTP 64 → 128 → 256 → 512 133, constant after warmup 0
    Qwen, tensor split, MTP 64 → 128 → 256 → 512 133, then 524 once 0
    gemma, tensor split 64 → 128 → 256 → 512 → 1024 0 0
    all layer split and single GPU runs stays at 64 0 0
    • fresh is 0 in every line of every run: no graph is evicted while still in use.
    • Qwen without MTP: evicted_by_cap stops at 133 once the cap has reached 512 and does not change over the remaining requests.
    • Qwen with MTP: it rises once from 133 to 524 together with newly created entries, i.e. stale shapes from the previous request being replaced; all victims were older than 1 s, so the cap did not grow further.
    • gemma reaches 1024 (up to 727 live entries at the prompt-to-decode transition) and evicts nothing at all.
    • The at-limit warning from your second commit never appeared; the 2048 limit was not reached in any run.
  8. added a commit that references this issue on Oct 9, 2026
  9. danielhanchen commented on Oct 10, 2026

    @danielhanchen
    Member

    Fixed! The 64 entry cap on the CUDA graph cache that came in with the Qwen3.8-Flash-Next MTP patch was far below what tensor split needs (about 2 x layers + 1 graphs per GPU), so every graph was evicted and re-captured on each token, exactly as your counter runs showed. unslothai/llama.cpp#253 removes the cap and keeps only the 10 s cleanup of unused graphs, the same as upstream, and it ships in b11505-mix-5209c9f and later (latest is b11539-mix-2500203). Thanks a lot for the bisect and the counter patch, they made this easy to pin down.
    To update: download the latest prebuilt from https://github.com/unslothai/llama.cpp/releases/latest, or for Studio use unsloth studio update (Docker: docker exec <container> unsloth-llama-update). Reopen if it still happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions