Repository navigation
cuda: compute every src1 column in the TQ fused and cuBLAS paths (multi-sequence ubatches on hybrid models) - #414
Merged
TheTom merged 1 commit intoNov 11, 2026
Conversation
The fused TQ decode path (ggml_cuda_mul_mat_tq) and the TQ4_1S cuBLAS path took
their column count from src1->ne[1] alone, and the dispatch checked only ne11
against MMVQ_MAX_BATCH_SIZE. A hybrid model's GDN output projection (ssm_out in
qwen35 / qwen35moe) multiplies a 2D weight by [K, n_seq_tokens, n_seqs]. With
several sequences in one ubatch, which is what llama-perplexity does by default
and what a server with parallel slots does, only the first sequence's columns were
computed and the rest of dst was left as whatever the buffer held.
On Qwen3.8-27B-TQ3_1S, llama-perplexity -c 512 -b 2048 gave [1]4.54 [2]1778.7
[3]256.0 at -ub 1: the first sequence right, the others garbage. With -b 512 (one
sequence per batch) it was [1]4.54 [2]6.33 [3]5.97.
For contiguous src1 and dst against a 2D weight the batch dims fold into the
column count exactly, so count every src1 row (ggml_nrows) in both paths and in
the dispatch. A batched (3D/4D) weight is not a single matrix; it now takes the
stride-aware cuBLAS fallback instead of the TQ fast paths.
test-backend-ops gets TQ3_1S / TQ4_1S MUL_MAT cases with src1 batch dims
(nr = {2,1}, {3,1}, {2,2}) on both sides of the fused decode limit.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 8, 2026
Owner
|
Thanks @jasstrong, merged. The per-chunk perplexity tables on three AMD cards made the bug obvious. The new MUL_MAT cases also fail on base kernels and pass with this PR on a GB10. |
jasstrong
pushed a commit
to jasstrong/llama-cpp-turboquant
that referenced
this pull request
Nov 11, 2026
… into the TQ3_4S stack One conflict, in ggml_cuda_graph_check_compatibility: TheTom#412 moved is_tq_w inside the MUL_MAT_ID branch so source-less nodes are not dereferenced, and this branch adds TQ3_4S to that test. Resolved as TheTom#412's placement with TQ3_4S added. TheTom#414's tq_ncols change to the fused TQ condition merged cleanly with this branch's TQ3_4S additions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 21, 2026
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.
What
On hybrid GDN models (qwen35, qwen35moe) with TQ weights, every sequence but the first in a multi-sequence ubatch gets garbage output.
The fused TQ decode path (
ggml_cuda_mul_mat_tq) and the TQ4_1S cuBLAS path take their column count fromsrc1->ne[1]only, and the dispatch checks onlyne11 <= MMVQ_MAX_BATCH_SIZE. A hybrid model's GDN output projection (ssm_out) multiplies a 2D weight by[K, n_seq_tokens, n_seqs]. With several sequences in one ubatch, only the first sequence's columns are computed, and the rest ofdstkeeps whatever the buffer held before.Several sequences per ubatch is what
llama-perplexitydoes by default (n_batch / n_ctx sequences per batch). It's also what a server with parallel slots does. Instrumenting the dispatch on Qwen3.8-27B at-b 2048 -ub 1shows the shape directly:For contiguous
src1anddstagainst a 2D weight, the batch dims fold into the column count exactly. So this PR counts everysrc1row (ggml_nrows) in both paths and in the dispatch. A batched (3D/4D) weight is not one matrix, so it now takes the stride-aware cuBLAS fallback instead of the TQ fast paths.Results
llama-perplexity -c 512 --chunks 3, per-chunk values.-b 2048puts 4 sequences in each batch;-b 512puts one.The same with TQ4_1S weights (Qwen3.8-27B-TQ4_1S,
GGML_TQ_NATIVE=1), where the fused path and the TQ4_1S cuBLAS path both apply:Tests
test-backend-opsgets TQ3_1S and TQ4_1SMUL_MATcases withsrc1batch dims (nr = {2,1}, {3,1}, {2,2}, n = 1, 3, 8), on both sides of the fused-decode limit.On all three cards (MI210 gfx90a, RX 7900 XTX gfx1100, PRO V620 gfx1030; ROCm 7.2.3),
-o MUL_MAT, withGGML_TQ_NATIVE=1so TQ4_1S stays TQ4_1S on the device:Limits of this testing
ne[1]-only count and is fixed here too.🤖 Generated with Claude Code