Eval bug: deepseek4 file with no ratio-4 (CSA) layer crashes with integer division by zero in the llama_kv_cache constructor

Aperta Adatta ai principianti
#32,424 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@rishitha2625 ci sta già lavorando.

Dal 17/11/2026.

  • #32501 di @rishitha2625 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Inizia in src/llama-kv-cache.cpp, nella configurazione della rotazione attention del costruttore di llama_kv_cache, e segui come l'override DeepSeek gestisce una cache senza layer. Proteggi la configurazione della rotazione o il loop da una larghezza della head pari a zero; il lavoro è completato quando il caricamento del modello DeepSeek4 descritto, senza un layer ratio-4, non va più in crash durante la creazione del contesto. Il report fornisce un comando di riproduzione, ma non indica alcun test specifico.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
136k
Fork
25.7k
Merge medio
2g 1h
PR unite (30g)
524

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ggml-org/llama.cpp

Tutte le issue di ggml-org/llama.cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.