Repository navigation
fix: size Python buffers to the actual context - #2436
Merged
abetlen merged 4 commits intoNov 22, 2026
Merged
Conversation
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.
Fixes #1438.
llama.cpp rounds context capacities up, but Python allocated token history and full logits using the requested
n_ctx. Withn_ctx=200, the native capacity is 256: full-logits generation fails after position 200, and ordinary generation silently loses the remaining evaluated token history.Allocate both buffers using the native capacity already used by completion limits. The existing small-model fixture covers
n_ctx=0, 200 and 256 with both logits modes and explicit full-logits prompt lookup, forcing generation to the context boundary and checking usage and exact token history.Reproducer on main (CPU):
Main raises
ValueError: could not broadcast input array from shape (32000,) into shape (0,); the fix completes normally.The separate implicit logits-mode selection issue is tracked in #2384.
Validation: final regressions give 6 failures and 3 passing controls on original main, then 9 passes with the fix. Full
make test: 35 passed.make lint: passed (Ruff 0.17.6).Environment: macOS arm64 (Apple M5 Pro), Python 3.12.14, native llama.cpp
afe77e18f, built with the installed macOS 26.5 SDK; regression runs use CPU layers.AI assistance: Codex helped diagnose, implement, test and independently review this change.