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
Open
Fix CPU backend abort on DeepSeek V4 PRO: use DS4_N_OUT_GROUP for attention-output grouping#511mrighini wants to merge 1 commit into
mrighini wants to merge 1 commit into
Conversation
…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>
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.
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(), andlayer_grouped_out_batch()hardcode the attention-output group count to8(the Flash value).PRO's shape profile sets
n_out_group = 16, so with the literal8the code computesgroup_dim = n_head_dim * (n_head / 8) = 512 * (128 / 8) = 8192, while PRO'sattn_output_atensor has
dim[0] = 512 * (128 / 16) = 4096→ the layout check in the grouped-Q8_0 matmul failsand
ds4_die()fires.Fix
Use the existing
DS4_N_OUT_GROUPmacro (= g_ds4_shape.n_out_group) instead of the literal8at the three call sites.
rank = 1024is shared across profiles, so no other change is needed.Flash takes the identical path (macro == 8); PRO now prefills all 61 layers.
Testing (per CONTRIBUTING.md)
Backend: CPU (
make cpu), x86-64 Linux (Ubuntu 24.04, Xeon w9-3595X).DeepSeek-V4-Flash-IQ2XXS…imatrix)DeepSeek-V4-Pro-IQ2XXS…Instruct-imatrix)Command:
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_testregression suite, which builds the default GPU backend (nvcc) unavailable on thisCPU-only host — happy to run any specific check you suggest.
Fixes #510
🤖 Generated with Claude Code