Repository navigation
webgpu : fix CI by keeping scratch alloc sizes monotonic in batch length - #31422
Merged
Merged
Conversation
The flash attention vec path and the MMVQ path append a scratch area after dst, but get_alloc_size only accounted for it when the current batch takes that path. The size was therefore not monotonic in the batch length: a graph reserved at n_ubatch (tiled path, no scratch) or at one token did not cover batches of 2 to 19 query rows, and GGML_SCHED_NO_REALLOC builds aborted on an unexpected reallocation. Pass the row count to both path predicates and size the scratch with the row count clamped to the longest batch the short path serves.
yomaytk
approved these changes
Oct 30, 2026
yomaytk
left a comment
Member
There was a problem hiding this comment.
Thanks! Yes, reserving the scratch for the largest small-path batch looks fine, and the changes looks good to me.
yomaytk
reviewed
Oct 30, 2026
4 of 11 tasks
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Nov 6, 2026
…gth (ggml-org#31422) * webgpu: keep scratch alloc sizes monotonic in the batch length The flash attention vec path and the MMVQ path append a scratch area after dst, but get_alloc_size only accounted for it when the current batch takes that path. The size was therefore not monotonic in the batch length: a graph reserved at n_ubatch (tiled path, no scratch) or at one token did not cover batches of 2 to 19 query rows, and GGML_SCHED_NO_REALLOC builds aborted on an unexpected reallocation. Pass the row count to both path predicates and size the scratch with the row count clamped to the longest batch the short path serves. * nit: align the mmvq pipeline key with clang-format 22 * webgpu: address review @yomaytk, name the mat-vec row threshold (cherry picked from commit 1c5ed70)
gagallo7
pushed a commit
to tetherto/qvac-fabric-llm.cpp
that referenced
this pull request
Nov 10, 2026
…gth (ggml-org#31422) * webgpu: keep scratch alloc sizes monotonic in the batch length The flash attention vec path and the MMVQ path append a scratch area after dst, but get_alloc_size only accounted for it when the current batch takes that path. The size was therefore not monotonic in the batch length: a graph reserved at n_ubatch (tiled path, no scratch) or at one token did not cover batches of 2 to 19 query rows, and GGML_SCHED_NO_REALLOC builds aborted on an unexpected reallocation. Pass the row count to both path predicates and size the scratch with the row count clamped to the longest batch the short path serves. * nit: align the mmvq pipeline key with clang-format 22 * webgpu: address review @yomaytk, name the mat-vec row threshold Assisted-by: Claude Code (cherry picked from commit 1c5ed70)
iancris
pushed a commit
to tetherto/qvac-fabric-llm.cpp
that referenced
this pull request
Nov 19, 2026
…gth (ggml-org#31422) * webgpu: keep scratch alloc sizes monotonic in the batch length The flash attention vec path and the MMVQ path append a scratch area after dst, but get_alloc_size only accounted for it when the current batch takes that path. The size was therefore not monotonic in the batch length: a graph reserved at n_ubatch (tiled path, no scratch) or at one token did not cover batches of 2 to 19 query rows, and GGML_SCHED_NO_REALLOC builds aborted on an unexpected reallocation. Pass the row count to both path predicates and size the scratch with the row count clamped to the longest batch the short path serves. * nit: align the mmvq pipeline key with clang-format 22 * webgpu: address review @yomaytk, name the mat-vec row threshold (cherry picked from commit 1c5ed70) Backport: ggml_webgpu_can_use_mmvq keeps fabric's dst argument, n_rows goes after it. Assisted-by: Claude Opus 5.5
gianni-cor
pushed a commit
to tetherto/qvac-fabric-llm.cpp
that referenced
this pull request
Nov 19, 2026
…gth (ggml-org#31422) (#559) * webgpu: keep scratch alloc sizes monotonic in the batch length The flash attention vec path and the MMVQ path append a scratch area after dst, but get_alloc_size only accounted for it when the current batch takes that path. The size was therefore not monotonic in the batch length: a graph reserved at n_ubatch (tiled path, no scratch) or at one token did not cover batches of 2 to 19 query rows, and GGML_SCHED_NO_REALLOC builds aborted on an unexpected reallocation. Pass the row count to both path predicates and size the scratch with the row count clamped to the longest batch the short path serves. * nit: align the mmvq pipeline key with clang-format 22 * webgpu: address review @yomaytk, name the mat-vec row threshold (cherry picked from commit 1c5ed70) Backport: ggml_webgpu_can_use_mmvq keeps fabric's dst argument, n_rows goes after it. Assisted-by: Claude Opus 5.5 Co-authored-by: Pascal <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Since #31300, the self-hosted WebGPU CI fails in test-llama-context: the comp_padding case on the DeepSeek V4 models aborts with "unexpected graph reallocation", on both the Apple and NVIDIA runners.
The cause is in how WebGPU sizes some tensors. For small batches, flash attention (under 20 query rows) and MMVQ (up to 4 rows) take a faster path that needs extra scratch space right after the output, and get_alloc_size only counted that space when the current batch took the small path.
So the size did not grow with the batch. The graph reserved at n_ubatch takes the large path and gets no scratch, the one reserved at one token gets scratch for a single row, and a 5-token batch ends up needing more than either: 95072 bytes for a FLASH_ATTN_EXT output reserved at 65536.
This PR always reserves the scratch of the largest batch the small path can serve, so a reservation made at n_ubatch covers every smaller batch.
Additional information
This follows what Metal already does for its flash attention temp buffer.
Tested on a rootless container with an RTX PRO 6000, with the CI Dawn release and GGML_SCHED_NO_REALLOC=ON. comp_padding now passes on both models, the main ctest label of the job is 17/17, and test-backend-ops on WebGPU passes for FLASH_ATTN_EXT and MUL_MAT.
Fixes #31346 (the WebGPU part that remained after #31344).
Requirements