Skip to content

Slow decode on RTX 4090 and windows #55

Open

Description

@gtrak

I see inconsistent GPU usage and 100% CPU usage across 16 cores of 7950x3d, and gallocr_realloc log spam. I got 90 tok/s at 16k context and 55 tok/s at 32k context, running like this: python scripts/server.py --port 1234 --max-ctx 32768

What MinMax 2.5 thinks is the issue:

Root cause: Every speculative decoding step builds a new ggml compute graph with a different number of nodes, triggering ggml_gallocr_reserve which reallocates the GPU buffer (~1.2GB) each time. This is the performance bottleneck, not the attention computation itself.
Why it happens: The DDTree structure varies per iteration based on accepted tokens, so the graph topology changes constantly, preventing buffer reuse.
The fix would be: Pre-reserve the maximum buffer size once (call ggml_gallocr_reserve with the max possible graph) rather than re-evaluating each step. This requires estimating the max graph size upfront.

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.26200.
-- The C compiler identification is MSVC 19.44.35222.0
-- The CXX compiler identification is MSVC 19.44.35222.0
-- The CUDA compiler identification is NVIDIA 13.0.48 with host compiler MSVC 19.44.35222.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: C:/ProgramData/mingw64/mingw64/bin/gcc.exe
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Warning: ccache not found - consider installing it for faster compilation or disable this warning with GGML_CCACHE=OFF
-- CMAKE_SYSTEM_PROCESSOR: AMD64
-- CMAKE_GENERATOR_PLATFORM: x64
-- GGML_SYSTEM_ARCH: x86
-- Including CPU backend
-- Found OpenMP_C: -openmp (found version "2.0")
-- Found OpenMP_CXX: -openmp (found version "2.0")
CMake Warning at deps/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt:84 (message):
  OpenMP not found
Call Stack (most recent call first):
  deps/llama.cpp/ggml/src/CMakeLists.txt:446 (ggml_add_cpu_backend_variant_impl)
-- Could NOT find OpenMP_CUDA (missing: OpenMP_CUDA_FLAGS OpenMP_CUDA_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_CUDA_FOUND) (found version "2.0")
-- x86 detected
-- Performing Test HAS_AVX_1
-- Performing Test HAS_AVX_1 - Success
-- Performing Test HAS_AVX2_1
-- Performing Test HAS_AVX2_1 - Success
-- Performing Test HAS_FMA_1
-- Performing Test HAS_FMA_1 - Success
-- Performing Test HAS_AVX512_1
-- Performing Test HAS_AVX512_1 - Success
-- Adding CPU backend variant ggml-cpu: /arch:AVX512 GGML_AVX512
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/include;C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/include/cccl (found version "13.0.48")
-- CUDA Toolkit found
-- Using CMAKE_CUDA_ARCHITECTURES=89 CMAKE_CUDA_ARCHITECTURES_NATIVE=89-real
-- Could NOT find NCCL (missing: NCCL_LIBRARY NCCL_INCLUDE_DIR) 
-- Warning: NCCL not found, performance for multiple CUDA GPUs will be suboptimal
-- Including CUDA backend
-- ggml version: 0.9.11
-- ggml commit:  b6ffab4a9
-- Could NOT find OpenMP_CUDA (missing: OpenMP_CUDA_FLAGS OpenMP_CUDA_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_CUDA_FOUND) (found version "2.0")

Activity

  1. added
    question
    on Apr 28, 2026
  2. davide221 commented on Apr 28, 2026

    @davide221
    Contributor

    Did you try adding the sliding window parameter? It should help stabilize decoding

  3. gtrak commented on Apr 29, 2026

    @gtrak
    Author

    I tried a few things, --fa-window 0 had no effect, tried pulling main and bumping cuda to 13.2 as well. No change.

    [step 271] committed=2353 last_tok=1910 tree_N=23 accept=4 next=1
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    [step 272] committed=2357 last_tok=1 tree_N=23 accept=9 next=1690
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    [step 273] committed=2366 last_tok=1690 tree_N=23 accept=10 next=854
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    [step 274] committed=2376 last_tok=854 tree_N=23 accept=6 next=328
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    [step 275] committed=2382 last_tok=328 tree_N=23 accept=5 next=220
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    [step 276] committed=2387 last_tok=220 tree_N=23 accept=2 next=15
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ggml_gallocr_alloc_graph: reallocating buffers automatically
    ggml_gallocr_needs_realloc: graph has different number of nodes
    ```
    
  4. gtrak commented on Apr 29, 2026

    @gtrak
    Author

    It's working on wsl2! after some cuda LD_PRELOAD hacks:

    Image
  5. dusterbloom commented on Apr 29, 2026

    @dusterbloom
    Collaborator

    @gtrak I worked a little to see if I could reproduce your problem on windows. Do you mind trying this PR I do not have a 4090, so I cannot truly see if it helps or not. I rather have your review and eventually then push or shelve. Thanks in advance

  6. gtrak commented on Apr 29, 2026

    @gtrak
    Author

    I'll give it a shot later. I get 30-40 tok/s at 160k q8 context on regular llama.cpp 3.6-27b-q4-k-m. I'm hoping this can beat it.

  7. gtrak commented on Apr 29, 2026

    @gtrak
    Author

    I think that PR fixed the realloc logs, but something else is still slowing it down. WSL on the same PR runs a bit faster, but I would prefer to not need WSL. If you can give me some pointers, I am happy to profile it, but new to this toolchain. It's also not fully utilizing the GPU, not sure if that's expected, 200w in wsl.

  8. dusterbloom commented on Apr 30, 2026

    @dusterbloom
    Collaborator

    One likely Windows-specific gotcha: the original ggml_gallocr_needs_realloc messages are behind
    #ifndef NDEBUG, so seeing them strongly suggests the native Windows binary was built without
    NDEBUG — probably Debug.

    With Visual Studio/MSVC generators, -DCMAKE_BUILD_TYPE=Release is not sufficient for the actual
    build; you also need cmake --build ... --config Release, or use Ninja with
    -DCMAKE_BUILD_TYPE=Release.

    Could you retry with a fresh Release build?

    cd lucebox-hub\dflash
    cmake -B build-release -S . -A x64 -DCMAKE_CUDA_ARCHITECTURES=89
    cmake --build build-release --config Release --target test_dflash --parallel
    python scripts\server.py --bin build-release\Release\test_dflash.exe --port 1234 --max-ctx 32768

    If you prefer Ninja:

      cmake -B build-release -S . -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=89
      cmake --build build-release --target test_dflash -j
      python scripts\server.py --bin build-release\test_dflash.exe --port 1234 --max-ctx 32768
    

    After that, please paste the final [timing] block. If native Windows is still slower in Release, the
    timing lines should tell us whether the remaining bottleneck is compute, graph build, logits
    transfer, or host/device sync.

  9. added
    bug
    on May 1, 2026
  10. added theissue type on May 1, 2026
  11. gtrak commented on May 1, 2026

    @gtrak
    Author

    OK, fresh build over f3777be.

    [timing] per-step averages over 232 steps (ms):
      draft_build    1.62
      draft_copyfeat 4.59
      draft_set      1.70
      draft_compute  33.07
      draft_logits   4.38
      snapshot_ssm   0.00
      verify_build   1.30
      verify_set     0.64
      verify_compute 101.66
      verify_logits  0.00
      accept         4.55
      restore_ssm    0.00
      replay_build   0.00
      replay_set     0.00
      replay_compute 0.00
      replay_logits  0.00
      ----- sum     153.51
    
    [timing] per-step averages over 23 steps (ms):
      draft_build    0.17
      draft_copyfeat 1.09
      draft_set      24.07
      draft_compute  103.62
      draft_logits   4.60
      snapshot_ssm   0.00
      verify_build   1.23
      verify_set     0.90
      verify_compute 339.23
      verify_logits  0.00
      accept         4.15
      restore_ssm    0.00
      replay_build   0.00
      replay_set     0.00
      replay_compute 0.00
      replay_logits  0.00
      ----- sum     479.06
    
  12. gtrak commented on May 4, 2026

    @gtrak
    Author

    Is it clear what's happening from the timing blocks?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugquestion

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions