Skip to content

opencl: apply the noshuffle row‐alignment rule to q4_K, q5_K and q8_0 from q6_K (bug fix) - #28575

Merged
lhez merged 1 commit into
ggml-org:masterfrom
qualcomm:hq/opencl-noshuffle-row-alignment
Sep 13, 2026
Merged

lhez merged 1 commit into
ggml-org:masterfrom
qualcomm:hq/opencl-noshuffle-row-alignment

Conversation

@wanghqc

@wanghqc wanghqc commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR is to fix a bug that shows up in the three types by extending the rules in q6_k.

  • The transposed layout packs two rows per 32‐bit texel and the GEMV reads it at an ne1/2 texel stride with an exact‐cover dispatch, so it is only addressable when the row count is aligned.
  • Those three types read the same packing as q6_K, and an unaligned ne1 >= 512 is admitted and misread ‐ a wrong answer, not a crash, reachable by any model with an unaligned row count.
  • This PR is to generalise the rule to all four types.

Additional information

Requirements

  • I have read and agree with the contributing guidelines Yes
  • AI usage disclosure: Yes, used for debugging. Code reviewed manully.

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend labels Sep 7, 2026
@lhez
lhez marked this pull request as ready for review September 12, 2026 06:20
@lhez
lhez requested a review from a team as a code owner September 12, 2026 06:20
…, not just q6_K

use_adreno_kernels() gates the transposed ("noshuffle") weight layout on
ne1 % 128 == 0 for q6_K alone. q4_K, q5_K and q8_0 read the same packing and are
admitted with no alignment check, so an unaligned row count reaches a kernel
that cannot address it and the weight is read misaligned -- a wrong answer, not
a crash. Any model with an unaligned row count is affected; an odd lm_head
vocabulary is the common case.

The layout packs 2 rows per 32-bit texel and the GEMV reads it at an ne1/2 texel
stride with an exact-cover dispatch, so the bound is ne1 % 64 == 0. It is not
128: a q8_0 attention weight of ne1 = 2880 is a multiple of 64 but not of 128
and is correct, and declining it would cost prefill for nothing.

On an Adreno 840 this takes test-backend-ops MUL_MAT from 1018/1023 to
1023/1023; the five failures are q4_K and q5_K at m = 1023, k = 4096.
@lhez
lhez force-pushed the hq/opencl-noshuffle-row-alignment branch from fa6fd27 to 16025da Compare September 12, 2026 18:13
@lhez
lhez merged commit 56b9eb2 into ggml-org:master Sep 13, 2026
32 of 36 checks passed
@BrewTestBot BrewTestBot mentioned this pull request Sep 14, 2026
1 task done
quimmedes pushed a commit to quimmedes/cafe-llama.cpp that referenced this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants