Prefill slowdown

#9
by vstiff - opened

Hi. The prefill speed on Ryzen AI MAX 395 is starting very fast but is slowing down rapidly in llama.cpp:

n_tokens =   2048, progress = 0.03, t =   4.79 s / 427.87 tokens per second
n_tokens =   4096, progress = 0.06, t =  11.20 s / 365.75 tokens per second
n_tokens =   6144, progress = 0.09, t =  18.03 s / 340.81 tokens per second
n_tokens =   8192, progress = 0.12, t =  25.44 s / 321.97 tokens per second
n_tokens =  10240, progress = 0.15, t =  33.43 s / 306.33 tokens per second
n_tokens =  12288, progress = 0.18, t =  42.39 s / 289.90 tokens per second
n_tokens =  14336, progress = 0.21, t =  53.12 s / 269.85 tokens per second
n_tokens =  16384, progress = 0.24, t =  65.69 s / 249.41 tokens per second
n_tokens =  18432, progress = 0.27, t =  80.67 s / 228.50 tokens per second
n_tokens =  20480, progress = 0.30, t =  96.40 s / 212.46 tokens per second
n_tokens =  22528, progress = 0.33, t = 115.42 s / 195.19 tokens per second
n_tokens =  24576, progress = 0.36, t = 137.20 s / 179.12 tokens per second
n_tokens =  26624, progress = 0.39, t = 162.54 s / 163.80 tokens per second
n_tokens =  28672, progress = 0.41, t = 191.06 s / 150.07 tokens per second
n_tokens =  30720, progress = 0.44, t = 224.39 s / 136.91 tokens per second
n_tokens =  32768, progress = 0.47, t = 259.16 s / 126.44 tokens per second
n_tokens =  34816, progress = 0.50, t = 298.95 s / 116.46 tokens per second
n_tokens =  36864, progress = 0.53, t = 341.22 s / 108.04 tokens per second
n_tokens =  38912, progress = 0.56, t = 389.52 s / 99.90 tokens per second
n_tokens =  40960, progress = 0.59, t = 443.73 s / 92.31 tokens per second
n_tokens =  43008, progress = 0.62, t = 498.41 s / 86.29 tokens per second
n_tokens =  45056, progress = 0.65, t = 560.22 s / 80.43 tokens per second

Is it expected behavior for model's attention, or there is a remedy for it?

Tried changing u_batch on same prompt (cancelled at different times):

u_batch_comparison

Poolside org

Hi @vstiff , thanks for starting this thread. We're looking into it and will release a patch soon and I'll update you.

Hi @vstiff , I haven't managed to replicate prefill TPS decrease on any of NV HW but haven't tested Ryzen AI MAX 395 yet. Can you please share your server command while I'll investigate that platform? Have you enabled DFlash for your S 2.1 tests? Where the other two models running with any speculative decoding model?

llama.cpp build b10088-67b9b0e7f , using Vulkan because ROCm build from github release is 10-20% slower.

cmake llama.cpp -B llama.cpp/build -DBUILD_SHARED_LIBS=OFF -DGGML_HIP=OFF -DGGML_VULKAN=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split

Laguna start args:

llama-server \
    --host 0.0.0.0 --threads-http 4 --alias llm \
    -hf unsloth/Laguna-S-2.1-GGUF:Q4_K_XL \
    -np 1 -fa on --ctx-size 262144 --swa-checkpoints 2 \
    --reasoning-preserve \
    --no-mmap --keep 10000

Removing --swa-checkpoints doesn't change anything in prefill, it was required for Gemma with similar attention, so I used it as a starting point. --reasoning-preserve is added to "debug" non-thinking mode in llama web UI, doesn't change anything in that regard.

I skipped DFlash for first tests because decoding was already quite decent, and because of this comment: https://github.com/ggml-org/llama.cpp/pull/25165#issuecomment-5043878753 haven't tried yet. But it seems like shouldn't affect prefill speed. I just noticed mistake on the chart, it's input tokens, not output. With --ubatch-size 256 Laguna roughly follows Gemma @ 256 line slope:

u_batch_comparison

Other 2 have MTP, Gemma (it's prefill speed is not affected by mtp):

llama-server \
    --host 0.0.0.0 --threads-http 4 --alias llm \
    -hf unsloth/gemma-4-31B-it-qat-GGUF:UD-Q4_K_XL \
    -np 1 -fa on --ctx-size 262144 --swa-checkpoints 2 \
    --ubatch-size 256 \
    --spec-type draft-mtp --spec-draft-n-max 3
    --no-mmap --keep 10000

Qwen (works ok out of the box, didn't experiment with prefill speed, actually in this build Qwen is about ~5tps higher prefill, plotted some previous version):

llama-server \
    --host 0.0.0.0 --threads-http 4 --alias llm \
    -hf "unsloth/Qwen3.5-122B-A10B-MTP-GGUF:UD-Q4_K_XL" \
    -np 1 --ctx-size 262144 \
    --spec-type draft-mtp --spec-draft-n-max 3 \
    --no-mmap --keep 10000

Sign up or log in to comment