common : back the static ngram cache with a constmap - #7
Open
jadidbourbaki wants to merge 2 commits into
Open
jadidbourbaki wants to merge 2 commits into
jadidbourbaki wants to merge 2 commits into
Conversation
jadidbourbaki
force-pushed
the
ngram-cache-constmap
branch
from
September 26, 2026 16:04
814b350 to
5832aa9
Compare
jadidbourbaki
added this pull request to stack #8
September 26, 2026 16:43
jadidbourbaki
removed this pull request from stack #8
September 26, 2026 16:47
jadidbourbaki
added this pull request to stack #9
September 26, 2026 16:47
jadidbourbaki
force-pushed
the
ngram-cache-constmap
branch
from
September 26, 2026 17:07
5832aa9 to
e96338d
Compare
jadidbourbaki
removed this pull request from stack #9
September 26, 2026 17:07
jadidbourbaki
changed the base branch from
ngram-cache-outer-map
to
ngram-cache-inner-vector
September 26, 2026 17:07
jadidbourbaki
added this pull request to stack #11
September 26, 2026 17:07
jadidbourbaki
force-pushed
the
ngram-cache-constmap
branch
2 times, most recently
from
September 26, 2026 17:59
948eb38 to
bdd4ea7
Compare
jadidbourbaki
force-pushed
the
ngram-cache-constmap
branch
from
September 26, 2026 18:13
bdd4ea7 to
899dc75
Compare
jadidbourbaki
force-pushed
the
ngram-cache-constmap
branch
from
September 26, 2026 18:35
899dc75 to
b90b281
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.
Stacked on #10.
I replaced the static n-gram cache with a read-only cache built on fastconstmap by
@lemire. AVerifiedConstMapmaps each 2-gram to a span of one contiguous array of (token, count) pairs sorted by token. The context and dynamic caches are unchanged.990afd0undervendor/constmapand pinned it inscripts/sync_vendor.py.llama-lookup-createwrites the static cache in a new file format.llama-lookupandllama-lookup-statsread it.common_ngram_cache_drafttakes the static cache as aconst common_ngram_cache_static *, and all sequences incommon/speculative.cppshare one static cache.llama-lookup-mergestill reads and writes the old format, so it keeps working for dynamic caches.Results
I borrowed the benchmark setup from ggml-org/llama.cpp#5479, which builds the static cache from WikiText-103 and runs with a context of 4096 tokens. Since this PR makes no algorithmic changes to lookup decoding, the dataset mainly matters for the acceptance rate, which stays almost identical. The metrics that change are the latency per drafted token, the load time of the static cache, and the memory used by the static cache.
I ran
llama-lookup-statson WikiText-103 test with static caches built from prefixes of WikiText-103 train. Each value is the median of 3 runs on the CPU of an Apple M4 Pro with 14 cores and 48 GB of memory, running macOS 26.5.1. A corpus size of 0 means no static cache. #10 is the baseline.The benchmark code and full tables are in ngram-cache-bench.