Eval bug: deepseek4 file with no ratio-4 (CSA) layer crashes with integer division by zero in the llama_kv_cache constructor
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in src/llama-kv-cache.cpp at the llama_kv_cache constructor’s attention rotation setup and trace how the DeepSeek override handles a cache with no layers. Guard rotation setup or the loop against zero head width; done means loading the described DeepSeek4 model without a ratio-4 layer no longer crashes during context creation. The report gives a reproduction command, but names no specific test.
Written by the indexing model from the issue text.
Description
Name and Version
Reproduced on a CPU-only Windows build (MSVC) of commit 5676dfbe0. The code involved is unchanged on master at c7518dbec5.
Operating systems
Windows (the arithmetic is not platform-specific; on Linux this should surface as SIGFPE)
GGML backends
CPU
Models
A deepseek4 GGUF whose compress_ratios contain no ratio-4 layer, i.e. only ratio 0, or ratio 0 and ratio 128. These were small synthetic test files. The published DeepSeek-V4-Flash file has ratio-4 layers and is not affected.
Problem description & steps to reproduce
Loading a deepseek4 model that has no ratio-4 (CSA) layer crashes while the context is created, before any token is evaluated:
llama-debug -m <deepseek4 file without a ratio-4 layer> -p "..." --save-logits -ngl 0 --no-warmup
The process exits with 0xC0000094 (STATUS_INTEGER_DIVIDE_BY_ZERO).
The cause is in the llama_kv_cache constructor (src/llama-kv-cache.cpp), in the branch that sets up the attention rotation:
bool attn_rot_k =
!attn_rot_disable &&
n_embd_head_k_all > 0 &&
ggml_is_quantized(type_k) &&
hparams.n_embd_head_k() % 64 == 0;
// always create Hadamard rotation tensors for DeepSeek lightning indexers
if ((model.arch == LLM_ARCH_DEEPSEEK32 || model.arch == LLM_ARCH_DEEPSEEK4 || ...) &&
hparams.n_embd_head_k_full == hparams.indexer_head_size) {
attn_rot_k = true;
}
if (attn_rot_k) {
n_rot_k = 64;
while (n_embd_head_k_all % (2*n_rot_k) == 0) {
n_rot_k *= 2;
}
}
The first condition requires n_embd_head_k_all > 0, but the DeepSeek override sets attn_rot_k = true without that check. For a deepseek4 model with no ratio-4 layer, the lightning-indexer (LID) cache is constructed with no layers, so its n_embd_head_k_all is 0. Then 0 % (2*n_rot_k) == 0 is always true, n_rot_k doubles until the uint32_t wraps to 0, and the next evaluation of the loop condition computes 0 % 0.
Expected behaviour
A cache with no layers should not get a rotation: either the DeepSeek override should also require n_embd_head_k_all > 0, or the loop should be guarded against a zero head width.
Workaround
Giving the file one ratio-4 layer avoids the crash. In the test files this was a trailing layer with an all-zero attn_output_b, so that it contributes nothing.
First Bad Commit
Not bisected.
Relevant log output
No log line is printed for the affected cache before the crash; the n_rot_k = ... line that follows the loop is never reached.
- Dominant language
- C++
- Stars
- 136k
- Forks
- 26.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 521
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ggml-org/llama.cpp
-
bug-unconfirmed
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Misc. bug: router mode forwards the child's Connection: close, so keep-alive clients fail with 'other side closed'Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
llama-vocab: unbounded id_to_token.resize(n_tokens) from untrusted llama.vocab_size in no_vocab path (783-byte file allocates ~43 GB)Possibly taken @xztakin claimed this 2 days ago. Openbug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Misc. bug: Hexagon: test-backend-ops POOL_2D fails for 128-wide kernels with padding on HTP0 (v73)Openbug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ggml-org/llama.cpp#32598 · 1 comment ·
Maintainers usually reply within 1 day
-
Llama chat webui. bug: scrollbar disappears when the mouse hovers near the top of the code blockPossibly taken A pull request linked to this issue is open or already merged. Openbug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ggml-org/llama.cpp#32465 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
All issues in ggml-org/llama.cpp
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainers usually reply within 2 days
-
arch-based bug niri
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
noctalia-dev/noctalia#5552 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
EchoTools/nevr-runtime#2912 ·
Maintainers usually reply within 1 day