Skip to content

cuda : avoid repeated warmup after stable graph replay - #29768

Draft
joelagnel wants to merge 1 commit into
ggml-org:masterfrom
joelagnel:pr/cuda-graph-warmup
Draft

joelagnel wants to merge 1 commit into
ggml-org:masterfrom
joelagnel:pr/cuda-graph-warmup

Conversation

@joelagnel

@joelagnel joelagnel commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Recapture a changed graph at once after it has replayed unchanged, if no
node changes op or starts or stops running a kernel. Keep the initial
warmup, and reset it when graph properties keep changing or a node
changes.

Benchmark results on RTX 5090:

llama-batched-bench -c 131072 -b 2048 -ub 512 -npp 15872 -ntg 512 -npl 8 -ngl 99 -t 4 -tb 4 -fa on -ctk f16 -ctv f16 -kvu -lv 5

Configuration:
- RTX 5090, Windows x64, driver 617.14, CUDA 12.9.
- Qwen3.8-27B Q4_K_M.

+------------------------+------------+-------------------------+------------------+------------------+
|       Workload         | Mean effect|         95% CI          | With patch       | Without patch    |
+------------------------+------------+-------------------------+------------------+------------------+
| llama-batched-bench    |   +1.14%   | +0.44% to +1.84%        | 299.21 tok/s mean| 295.85 tok/s mean|
|                        |            |                         | 299.82 median    | 295.80 median    |
+------------------------+------------+-------------------------+------------------+------------------+

I also tested thoroughly on RTXspark (NVIDIA N1X) and DGX Spark (GB10)
and for those, no statistically significant improvement or regression
was detected.

@joelagnel
joelagnel requested a review from a team as a code owner September 30, 2026 19:55
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Sep 30, 2026
@joelagnel
joelagnel force-pushed the pr/cuda-graph-warmup branch from 3cbbc04 to bd154f9 Compare October 1, 2026 22:48
@joelagnel
joelagnel marked this pull request as draft October 7, 2026 22:50
@joelagnel
joelagnel force-pushed the pr/cuda-graph-warmup branch from bd154f9 to c604639 Compare October 7, 2026 22:50
@gaugarg-nv

Copy link
Copy Markdown
Contributor

This PR is going to be incompatible with #22155 that can cause cudaDeviceSynchronize on a shape change.

If you capture graph in such a case, it will break.

@joelagnel
joelagnel force-pushed the pr/cuda-graph-warmup branch from c604639 to 6f69429 Compare October 8, 2026 15:08
@joelagnel

Copy link
Copy Markdown
Contributor Author

@gaugarg-nv, thanks a lot, I agree there is a chance of cudaDeviceSynchronize during capture. I updated the PR to exclude legacy CUDA pool case. Tested on my devices.

@joelagnel
joelagnel force-pushed the pr/cuda-graph-warmup branch from 6f69429 to ae89254 Compare October 12, 2026 14:48
@joelagnel
joelagnel marked this pull request as ready for review October 12, 2026 14:49
@joelagnel
joelagnel force-pushed the pr/cuda-graph-warmup branch from ae89254 to f69225e Compare October 12, 2026 14:52
Recapture a changed graph at once after it has replayed unchanged, if no
node changes op or starts or stops running a kernel.  Keep the initial
warmup, and reset it when graph properties keep changing or a node
changes.

Benchmark results on RTX 5090:

llama-batched-bench -c 131072 -b 2048 -ub 512 -npp 15872 -ntg 512 -npl 8 -ngl 99 -t 4 -tb 4 -fa on -ctk f16 -ctv f16 -kvu -lv 5

Configuration:
- RTX 5090, Windows x64, driver 617.14, CUDA 12.9.
- Qwen3.8-27B Q4_K_M.

+------------------------+------------+-------------------------+------------------+------------------+
|       Workload         | Mean effect|         95% CI          | With patch       | Without patch    |
+------------------------+------------+-------------------------+------------------+------------------+
| llama-batched-bench    |   +1.14%   | +0.44% to +1.84%        | 299.21 tok/s mean| 295.85 tok/s mean|
|                        |            |                         | 299.82 median    | 295.80 median    |
+------------------------+------------+-------------------------+------------------+------------------+

I also tested thoroughly on RTXspark (NVIDIA N1X) and DGX Spark (GB10)
and for those, no statistically significant improvement or regression
was detected.

Assisted-by: Codex
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
@gaugarg-nv

Copy link
Copy Markdown
Contributor

@joelagnel Can you test dflash2 and MTP (chose draft length of 7 and 15 for both) with some p_min value that would change the batch size during target verification?

In these cases, I would expect cudaGraphExecUpdate to fail more frequently and that can cause perf regression with this change.

@joelagnel
joelagnel marked this pull request as draft October 23, 2026 10:52
francisab added a commit to francisab/llama.cpp that referenced this pull request Oct 24, 2026
Assisted-by: GitHub Copilot

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
francisab added a commit to francisab/llama.cpp that referenced this pull request Oct 24, 2026
Assisted-by: GitHub Copilot

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants