Skip to content

Fix CPU backend abort on DeepSeek V4 PRO: use DS4_N_OUT_GROUP for attention-output grouping#511

Open
mrighini wants to merge 1 commit into
antirez:mainfrom
mrighini:fix-cpu-pro-n-out-group
Open

Fix CPU backend abort on DeepSeek V4 PRO: use DS4_N_OUT_GROUP for attention-output grouping#511
mrighini wants to merge 1 commit into
antirez:mainfrom
mrighini:fix-cpu-pro-n-out-group

Conversation

@mrighini

@mrighini mrighini commented Jul 6, 2026

Copy link
Copy Markdown

Fix CPU backend abort on DeepSeek V4 PRO

The CPU reference path aborts at prefill layer 1 on any DeepSeek V4 PRO model with
grouped Q8_0 tensor has an unexpected layout. Flash is unaffected.

Root cause

layer_grouped_out_one(), layer_grouped_out_one_decode_scratch(), and
layer_grouped_out_batch() hardcode the attention-output group count to 8 (the Flash value).
PRO's shape profile sets n_out_group = 16, so with the literal 8 the code computes
group_dim = n_head_dim * (n_head / 8) = 512 * (128 / 8) = 8192, while PRO's attn_output_a
tensor has dim[0] = 512 * (128 / 16) = 4096 → the layout check in the grouped-Q8_0 matmul fails
and ds4_die() fires.

Fix

Use the existing DS4_N_OUT_GROUP macro (= g_ds4_shape.n_out_group) instead of the literal 8
at the three call sites. rank = 1024 is shared across profiles, so no other change is needed.
Flash takes the identical path (macro == 8); PRO now prefills all 61 layers.

-    const uint32_t n_groups = 8;
+    const uint32_t n_groups = DS4_N_OUT_GROUP;

Testing (per CONTRIBUTING.md)

Backend: CPU (make cpu), x86-64 Linux (Ubuntu 24.04, Xeon w9-3595X).

Model (Q2 imatrix) Before After
Flash (DeepSeek-V4-Flash-IQ2XXS…imatrix) coherent, ~3 t/s unchanged, coherent, ~3 t/s
PRO (DeepSeek-V4-Pro-IQ2XXS…Instruct-imatrix) abort at prefill layer 1 coherent, all 61 layers, ~0.95 t/s

Command:

./ds4 -m <model>.gguf --cpu -t 60 -c 2048 -n 48 --nothink -p "In one short paragraph, explain how vaccines work."

Note: I validated on the CPU backend via manual smoke tests (Flash output byte-path is
unchanged since the macro resolves to 8 for Flash; PRO output is coherent). I did not run the
full ds4_test regression suite, which builds the default GPU backend (nvcc) unavailable on this
CPU-only host — happy to run any specific check you suggest.

Fixes #510

🤖 Generated with Claude Code

…ention-output grouping

The CPU reference path hardcoded the attention-output group count to 8 (the
Flash value) in layer_grouped_out_one(), layer_grouped_out_one_decode_scratch(),
and layer_grouped_out_batch(). PRO uses n_out_group = 16, so the grouped Q8_0
matmul computed group_dim = n_head_dim * (n_head / 8) = 8192 while the actual
attn_output_a tensor has dim[0] = 4096, tripping

    ds4_die("grouped Q8_0 tensor has an unexpected layout")

at prefill layer 1. Replace the literal 8 with the existing DS4_N_OUT_GROUP macro
(g_ds4_shape.n_out_group): 8 for Flash, 16 for PRO. Flash is unaffected (macro
== 8); PRO Flash now runs on the CPU backend and produces coherent output.

Tested (CPU backend, x86-64 Linux, Xeon w9-3595X):
- Flash Q2 (DeepSeek-V4-Flash-IQ2XXS...imatrix): unchanged, coherent, ~3 t/s
- PRO Q2 (DeepSeek-V4-Pro-IQ2XXS...Instruct-imatrix): previously aborted at
  prefill layer 1; now coherent, ~0.95 t/s

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPU backend aborts on DeepSeek V4 PRO: grouped Q8_0 tensor has an unexpected layout

1 participant