UPSTREAM PR #18729: lookup, lookahead: fix crash when n_ctx not specified - #875
Open
loci-dev wants to merge 1 commit into
Open
UPSTREAM PR #18729: lookup, lookahead: fix crash when n_ctx not specified#875loci-dev wants to merge 1 commit into
loci-dev wants to merge 1 commit into
Conversation
Since PR #16653 (Dec 15, 2025), the default n_ctx is 0 to enable automatic
GPU memory fitting. This causes llama-lookup and llama-lookahead to crash
when run without explicit -c flag:
GGML_ASSERT(batch.seq_id[batch.n_tokens] && "llama_batch size exceeded")
Root cause: Both examples use params.n_ctx directly for batch initialization,
but params.n_ctx remains 0 even after the context is properly initialized
to n_ctx_train internally.
Bug history:
- Nov 2023: lookahead.cpp created (PR #4207) with params.n_ctx pattern
- Dec 2023: lookup.cpp created (PR #4484) with same pattern
- Nov 2024: default n_ctx changed to 4096 (PR #10136) - bug dormant
- Dec 2025: default n_ctx changed to 0 (PR #16653) - bug activated
The bug was dormant for 2+ years because params.n_ctx defaulted to 512,
then 4096. PR #16653 changed it to 0 for GPU auto-fitting, triggering
the crash.
Fix: Use llama_n_ctx(ctx) to get the actual runtime context size, matching
the pattern already used elsewhere in lookup.cpp (line 72) and in
speculative.cpp/speculative-simple.cpp.
Tested: llama-lookup now works without -c flag (12.5% acceptance on
Gemma-3-1B).
Note: llama-lookahead has a separate pre-existing issue with sequence
initialization (n_seq_max=1 vs W+G+1 needed) that is unrelated to this fix.
loci-dev
temporarily deployed
to
PROD__AL_DEMO
January 10, 2026 00:49 — with
GitHub Actions
Inactive
|
Explore the complete analysis inside the Version Insights I've generated a summary report for your project. The analysis shows that Pull Request #875 for the llama.cpp repository (owned by auroralabs-loci) has no significant performance regressions. Key highlights:
The comparison between the base version (b3ffacf1-edb0-11f0-a055-c529586b3e1a) and target version (b675fbc1-edbe-11f0-a055-c529586b3e1a) indicates this is a performance-neutral change with no concerning degradation. |
loci-dev
force-pushed
the
main
branch
27 times, most recently
from
January 13, 2026 23:09
8e509d5 to
63d526f
Compare
loci-dev
force-pushed
the
main
branch
30 times, most recently
from
January 21, 2026 13:23
48924ee to
fb5dc2f
Compare
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.
Mirrored from ggml-org/llama.cpp#18729
Summary
Fixes a crash in
llama-lookupandllama-lookaheadwhen run without explicit-cflag:Root Cause
Both examples use
params.n_ctxdirectly for batch initialization:Since #16653 changed the default
n_ctxto 0 (for GPU auto-fitting),params.n_ctxremains 0 even after the context is properly initialized. This creates a zero-sized batch that crashes on the firstcommon_batch_add().Bug History
This bug was dormant for 2+ years:
The pattern was always incorrect, but only triggered when
n_ctxdefault became 0.Fix
Use
llama_n_ctx(ctx)to get the actual runtime context size:This matches:
lookup.cpp:72formax_context_sizespeculative.cppandspeculative-simple.cppTesting
Note
llama-lookaheadhas a separate pre-existing issue with sequence initialization (n_seq_max=1when it needsW+G+1) that is unrelated to this batch size fix.