spec: fix segfault error on long prompts for eagle3#24707
Merged
Conversation
This was referenced Jun 16, 2026
ggerganov
approved these changes
Jun 17, 2026
papamoose
pushed a commit
to papamoose/llama.cpp
that referenced
this pull request
Jun 27, 2026
TheTom
added a commit
to TheTom/llama-cpp-turboquant
that referenced
this pull request
Jul 2, 2026
…xtracted from upstream ggml-org#24707 minus the unrelated eagle3 fix)
adrianhoehne
pushed a commit
to adrianhoehne/llama.cpp
that referenced
this pull request
Jul 5, 2026
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.
Overview
Fix #24637
Root cause:
Eagle3 speculative decoding crashes with a segmentation on long prompts. The draft decoder sizes its input-embeddings batch with the wrong embedding dimension, producing an out-of-bounds read that only manifests once the prompt is long enough for the copy offset to cross the allocated buffer.
Printing
n_embd_inp/n_embd/n_embd_outshows a draft-only mismatch (Gemma4 26B-A4B):Eagle3 sets
n_embd_inp = target_layers * target_hidden(8448) for the draft encoder, but the draft decoder consumes g_embeddings of widthn_embd(2816).decode()sizes the embd batch withn_embd_inp(), soubatch_add()reads 8448 floats/row from a 2816-wide buffer → out-of-bounds. The offset scales with prompt length, so short prompts work and long prompts segfault.A one-liner works
arch == EAGLE3 ? n_embd : n_embd_inp()(see https://github.com/ruixiang63/llama.cpp/blob/7dd72f620185f74e75eaf4d265783207eb7708d2/src/llama-context.cpp#L1695), but it adds an arch-specific branch to the generic decode path.Instead, this PR stops overloading
n_embd_inp:n_embd_inp_enc(): encoder input dim, falls back ton_embd_inp()target_layers * target_hiddeninn_embd_inp_enc_impl, son_embd_inp() == n_embdagainencode()/ draft encoder usen_embd_inp_enc();decode()unchangedNo-op for non-eagle3 models:
n_embd_inp_enc()returnsn_embd_inp()whenever the field is 0.Tested on gemma-4-26B target + eagle3 draft, ~30K-token prompt: segfaults before, completes after.
Note
During testing, I found low long-context acceptance is a draft-model limitation, not an implementation bug.
This EAGLE3 draft (gemma-4-26B speculator) accepts well on short prompts but collapses on long ones (~30K): per-position
0.14, 0, 0, 0, mean length ~1.15.Cross-checked against the vLLM reference (same draft + target + prompt) — it reports the same:
Per-position acceptance rate: 0.139, 0.013, 0.000, 0.000, mean 1.15.Since the reference engine reproduces it, this is a draft-model quality issue. Looking deeper: its
rope_theta = 10000short-range RoPE doesn't extrapolate to long context.Requirements