Skip to content

[sycl] XMX enablement 0/4 - Fix Q6_K precision - #32726

Merged
Titaniumtown merged 1 commit into
ggml-org:masterfrom
cwriter:xmx-enablement-0/4
Nov 27, 2026
Merged

Titaniumtown merged 1 commit into
ggml-org:masterfrom
cwriter:xmx-enablement-0/4

Conversation

@cwriter

@cwriter cwriter commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This is the first patch of a series of 5 patches to extend the XMX online-dequant work.

This is a bugfix patch for q6: While the canonical (normal layout) path used f32 to dequantize, dequantize_block_q6_K_reorder used the native type of *d, which can be f16.

Additional information

  • Qwen3.5-0.8B: first and later decodes, restored states, prefills up to 8 tokens bit-identical;
    test-llama-context state_load, cp_h, cp_d pass (failed before).
  • test-backend-ops (B60, JIT, F16): MUL_MAT 2431/2431, MUL_MAT_ID 1189/1189.

Fixes

test-llama-context (Qwen3.5-0.8B UD-Q4_K_XL, B60, AOT) fails on master (13/17), this PR reaches 16/17 by fixing state_load, cp_h, cp_d

Requirements

  • I have read and agree with the contributing guidelines - YES
  • AI usage disclosure: YES, Opus 5.5 discovered the reordering issue during benchmark / KLD runs and tracked down the fix and provided the implementation

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language labels Nov 21, 2026
@cwriter cwriter changed the title [SYCL]: WIP XMX enablement 0/4 - Fix Q6_K precision and reordering selection [sycl]: XMX enablement 0/4 - Fix Q6_K precision and reordering selection Nov 21, 2026
@cwriter
cwriter marked this pull request as ready for review November 21, 2026 21:31
@cwriter
cwriter requested a review from a team as a code owner November 21, 2026 21:31
@cwriter cwriter changed the title [sycl]: XMX enablement 0/4 - Fix Q6_K precision and reordering selection [sycl] XMX enablement 0/4 - Fix Q6_K precision and reordering selection Nov 21, 2026
Comment on lines 5246 to 5249
opt_for_reorder(&ctx, src0, src1, dst, mul_mat_algo::DMMV);
ggml_sycl_op_mul_mat<no_quantize_q8_1>(ctx, src0, src1, dst, ggml_sycl_op_dequantize_mul_mat_vec);
} else if (use_mul_mat_vec_q) {
opt_for_reorder(&ctx, src0, src1, dst, mul_mat_algo::MMVQ);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two cases something we should try and fix as well? DMMV and MMVQ seem unaffected by your changes from my read of the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, so there were 2 issues:

  • A bug causing lower precision than intended
  • A reordering priority selection, leading to worse performance

The first one affected the dequantization of reordered q6_k (dequantize_block_q6_K_reorder). The canonical storage format (handled by dequantize_block_q6_K already uses f32 casts) . As far as I can tell, DMMV and MMVQ also use the standard reordered dequantization functions, so they should also profit from the first fix.

For the 2nd one, the issue is that the first kernel taking a path would realize late that it needs to reorder. Once the format is reordered, it can only take the reordered paths. Essentially:

  • An input comes along in canonical format
  • We select an execution backend (DMMV/MMVQ/XMX/...)
  • XMX is slower for most inputs than reorder. XMX is not eligible. It takes DMMV.
  • DMMV reorders and runs (slower)
  • The next input comes along
  • Now, we have a reordered format. Because of this, XMX is faster and better, and it is selected
  • XMX runs (faster)

Instead, what we would do now is:

  • An input comes along in canonical format
  • We check (through the DMMV path) that it is possible to reorder, and reorder if possible - otherwise, nothing happens
  • We select the backend for the now reordered format. XMX wins this by a mile, so it is chosen.
  • We run XMX

The "issue" if we do not do this: Benchmarks are all over the place: The first time we see a tensor, it's slow. After that, fast. Correctnesswise: Not an issue. But for benchmarking, you're getting wildly varying results before you have really exercised all experts. Which is a bit annoying.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I share the background/history of these codes.

  1. we choose the mul_mat code path according to the tensors' shape, data type.
  2. then we find the code path not work well for all cases.
    so, we added the next code to change the code path for small tuning to get better performance.by:
 if (!g_ggml_sycl_prioritize_dmmv && ((should_reorder_tensor(ctx, dst) &&
                                          ggml_sycl_supports_reorder_mmvq(src0->type)))) {...}
  1. I update above code to tune for Arc770.

The flow is:
set code path -> update it for special cases -> update for special GPU (Arc770).
These codes have nothing to decide/execute reorder.

Next, we decide and execute the recorder in every mul_mat sub path, like if (use_dequantize_mul_mat_vec) {....}

The code flow is clear for them:

  1. set the code path.
  2. in every sub path, decide and execute the reorder.

But following new code mix them and make it complex:

choose(); //set code path
    if () {
        opt_for_reorder(); //decide/execute the reorder
        if (extra0->optimized_feature.reorder) {
            choose(); //set code path again
        }
    }

It will make it hard to understand and maintain code for both code path and reorder.

I suggest refactoring it to following the legacy style.

Reminder:

  • reorder decide/execute is implemented in same function. it can be called in any mul_mat functions.
  • code path choice is complex and impact more LLMs. suggest update a little per PR.

Thank you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arthw
Yes, I see. I will remove the reorder part from this PR and keep only the correctness fix.
The way of the PR is also more of a bandaid. I will spend some gray matter and tokens on seeing if we can somehow make this a bit more deterministic - I think the "kernels modify weights while running" makes sense from the perspective of "the first execution unit (GPU/NPU/CPU) that sees this node optimizes it for itself", but doing this at runtime is flimsy, has issues with SYCL Graph Replay (making it slow), and makes it harder to share weights across different backends.
Ideally, we could say "I already know that this device prefers having data in this format (under side conditions of memory constraints, sharing, ...), so let's load it this way (canonical/reordered, for these input sizes) in the first place" - this reduces decisions at runtime for "read-mostly" ("rewrite, then read") workloads. I know the warmup is supposed to be doing this, but has limited success in my experience.

Thanks!

@Titaniumtown

Copy link
Copy Markdown
Contributor

@cwriter Could you ask Claude how to reproduce your test? Could be interesting to add coverage for this case, interesting bug!

@cwriter

cwriter commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@Titaniumtown

Compile with SYCL F16 mode, then:
Test run:
test-llama-context -m /models/qwen35-08b/Qwen3.5-0.8B-UD-Q4_K_XL.gguf -ngl 99

Output:

Output
threads: 16
0.08.845.218 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.08.845.231 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.09.140.520 I cmn  common_promp: saved session before last token to dump_state.Qwen3.5-0.8B-UD-Q4_K_XL.gguf.bin, n_new = 100
baseline        OK
0.09.396.226 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.09.396.234 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
seq_rm          OK
0.09.567.530 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.09.567.534 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
generate_tokens_compare: error: NMSE at step 0 is 2.848349e-04 (threshold 1.0e-05)
state_load      FAIL
0.09.740.865 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.09.740.872 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
generate_tokens_compare: error: NMSE at step 0 is 2.848349e-04 (threshold 1.0e-05)
cp_h            FAIL
0.09.945.622 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.09.945.629 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
generate_tokens_compare: error: NMSE at step 0 is 2.848349e-04 (threshold 1.0e-05)
cp_d            FAIL
0.10.097.130 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.097.138 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
cp_h_s          OK
0.10.255.702 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.255.707 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
cp_d_s          OK
0.10.397.737 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.397.745 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
rt              OK
0.10.602.940 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.602.948 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
ps              OK
0.10.854.532 E state_read_data: mismatched key type (1 != -1, layer 7)
0.10.876.442 E state_seq_set_data: error loading state: failed to restore kv cache
0.11.123.875 E state_read_data: mismatched key type (1 != -1, layer 7)
0.11.128.235 E llama_state_seq_load_file: error loading sequence state file: failed to restore kv cache
rf              OK
0.11.170.554 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.170.564 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.188.354 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.188.363 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.242.895 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.242.900 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.293.830 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.293.835 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.299.284 E state_read_data: incompatible key rotation (256 instead of 0)
set_seq_state: seq set data length 0 does not match expected length 20208652
0.11.314.367 E state_seq_set_data: error loading state: failed to restore kv cache
rot             OK
0.11.331.408 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.331.416 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.358.578 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
cp_d            FAIL
0.10.097.130 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.097.138 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
cp_h_s          OK
0.10.255.702 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.255.707 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
cp_d_s          OK
0.10.397.737 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.397.745 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
rt              OK
0.10.602.940 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.10.602.948 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
ps              OK
0.10.854.532 E state_read_data: mismatched key type (1 != -1, layer 7)
0.10.876.442 E state_seq_set_data: error loading state: failed to restore kv cache
0.11.123.875 E state_read_data: mismatched key type (1 != -1, layer 7)
0.11.128.235 E llama_state_seq_load_file: error loading sequence state file: failed to restore kv cache
rf              OK
0.11.170.554 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.170.564 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.188.354 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.188.363 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.242.895 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.242.900 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.293.830 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.293.835 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.299.284 E state_read_data: incompatible key rotation (256 instead of 0)
set_seq_state: seq set data length 0 does not match expected length 20208652
0.11.314.367 E state_seq_set_data: error loading state: failed to restore kv cache
rot             OK
0.11.331.408 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.331.416 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.11.358.569 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.358.578 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
frag            OK
0.11.912.489 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.11.912.499 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
noalloc         OK
comp_padding    SKIP  requires DeepSeek V4 or V4.1
rollback        OK
rollback_bound  OK
replay          FAIL  multi-seq split replay logits mismatch (max diff 0.238268, nmse 0.000478, first difference at index 0)
0.15.414.732 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.15.414.738 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.15.658.969 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.15.658.974 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
0.15.917.495 W resolve_fused_ops: layer 3 is assigned to device SYCL0 but Flash Attention over K/V rows is assigned to device CPU (usually due to missing support)
0.15.917.502 W resolve_fused_ops: Flash Attention over K/V rows not supported, set to disabled
shared          OK

cases    : 18
passed   : 13
skipped  : 1
failed   : 4

dequantize_block_q6_K_reorder multiplied a half d, so the products were
rounded in half precision, while dequantize_block_q6_K converts d to float
first. The same weight dequantized to different f16 values depending on its
layout, so prefill results changed once a decode had reordered the weights.
Every other reordered dequant kernel already uses float.

Assisted-by: Claude Opus 5.5
@cwriter cwriter changed the title [sycl] XMX enablement 0/4 - Fix Q6_K precision and reordering selection [sycl] XMX enablement 0/4 - Fix Q6_K precision Nov 26, 2026
@cwriter

cwriter commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@arthw Reduced, it's almost ridiculously tiny now, but the fix is still valid I guess 😄

@arthw arthw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good job!

Thank you!

@Titaniumtown
Titaniumtown merged commit ed2153e into ggml-org:master Nov 27, 2026
25 of 30 checks passed
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 SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants