Repository navigation
[sycl] XMX enablement 0/4 - Fix Q6_K precision - #32726
Conversation
| 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I share the background/history of these codes.
- we choose the mul_mat code path according to the tensors' shape, data type.
- 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)))) {...}
- 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:
- set the code path.
- 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!
There was a problem hiding this comment.
@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!
|
@cwriter Could you ask Claude how to reproduce your test? Could be interesting to add coverage for this case, interesting bug! |
|
Compile with SYCL F16 mode, then: Output: Output |
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
45b1b83 to
6c86596
Compare
|
@arthw Reduced, it's almost ridiculously tiny now, but the fix is still valid I guess 😄 |
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_reorderused the native type of*d, which can be f16.Additional information
test-llama-contextstate_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 fixingstate_load,cp_h,cp_dRequirements