Repository navigation
Conversation
Compare shifted integer token slices and skip suffixes without earlier matches. Keep the existing fallback and shared continuation selection. Co-Authored-By: Aiden <aiden@weco.ai>
This branch has not been deployed
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.
TL;DR
LlamaPromptLookupDecoding.find_candidate_pred_tokensduring prompt lookup decoding.pytest tests/test_llama_speculative.py tests/test_llama_chat_format.py tests/test_llama_grammar.pyplus native version/tokenization tests: eight passed.What & Why
Each suffix length currently builds sliding windows and compares every token in every window.
It also collects all matching positions before returning one result.
The new path compares shifted slices for integer token arrays and skips suffix lengths without an earlier matching first token.
Integer suffixes match themselves, so selecting the first full match keeps the same result and slice.
Validation
Measured on Linux x86_64, AMD EPYC 9R14, Python 3.12.13, and NumPy 2.5.4, with CPU affinity and one BLAS thread.
The unchanged native library used a Release CPU build with OpenMP and BLAS disabled.
These measurements cover lookup time, not end-to-end model generation.
Results
All three rows use
max_ngram_size=2and ten requested tokens.The last row passes
np.int64(10)and exercises the existing matching path.Times are per lookup, calculated from 5,120-call batches with nine timing comparisons.
The third row's difference is within measurement noise.
To compare locally, run this command on both revisions:
For the second row, use
ids = np.arange(64, dtype=np.intc).For the last row, resize the seven-token pattern to 128 elements and set
count = np.int64(10).Native checks on the patched source:
Ruff lint and formatting passed across all 29 Python and test files.
The four-file suite including all of
tests/test_llama.pyreached its ten-minute limit duringtest_real_llama, after three passes.The baseline validation had the same model-inference limitation; a full-suite pass is not claimed.
Why this is safe and easy to maintain
The change stays within one method and keeps one shared continuation loop.
The fallback preserves existing behavior for other inputs and unusual argument types.
The lookup tests and seeded checks cover values, slice offsets, dtypes, strides, read-only inputs, and errors.
AI assistance
Codex gpt-6.1-sol generated candidates tracked with Weco Observe.
Codex performed the source selection, validation, and PR preparation; no human review is claimed.
Weco share link: https://dashboard.weco.ai/share/YGQjNo2S_3mnwHD2B150wuOXpqR4MQhL