spec : save the dynamic ngram cache file - #22055
Conversation
2e1c956 to
430c0ca
Compare
d5448ea to
ba99720
Compare
cf7a308 to
8ae6c04
Compare
afc3295 to
dc2ab62
Compare
89b10b8 to
5c5bea4
Compare
e3017a4 to
268d95e
Compare
|
The new parameters are never populated. Did you test this change? What is the goal of this PR? |
b4ad275 to
4fe77aa
Compare
|
first of all, thanks for taking the time to review my PR! TBH, my initial scope for this PR (after coming across the TODO on line 930 of common/speculative.cpp) was to move the The way I went about testing my changes was using the below command: P.S: In the |
719eb8b to
5282e3c
Compare
Upstream PR ggml-org/llama.cpp#22055 adds save-on-destruction for the ngram_cache speculative impl, replacing the older save_dynamic/save_static bool toggles (which were always false in our tree — dead code). Hand-port notes: - common/common.h:343-347 — add n_draft field to common_params_speculative_ngram_cache so callers can configure draft size without source edits (was hard-coded to 8 via TODO). - common/speculative.cpp:643-746 — drop save_dynamic/save_static bools, keep the static/dynamic cache paths as const members. Constructor signature trimmed accordingly. - common/speculative.cpp:705-731 — new destructor merges every per-seq context cache (sinfos[i].ngram_cache_context) into an aggregate, then merges that into the base on-disk static + dynamic caches and writes them back via common_ngram_cache_save. Our impl is multi-seq (vs upstream's single-seq), so we aggregate first. - common/speculative.cpp:797-810 — create_state_ngram_cache returns std::unique_ptr now so the writing destructor only fires on real teardown (not when a temporary by-value copy goes out of scope inside the factory). - common/speculative.cpp:1030-1035 — call site uses std::move into impls. Skipped: no test for this in upstream PR. Smoke test on eliza-1-0_8b-32k: model loads, generates coherent text, prompt 132 t/s / gen 58 t/s (no regression — non-speculative path unaffected; ngram_cache is opt-in via --spec-type ngram-cache). Refs: ggml-org/llama.cpp#22055
|
I just ran into the same TODO, what is the state of this pr? |
|
Hello! I intend to work on this PR very soon. |
5282e3c to
bec53e3
Compare
bec53e3 to
62666c1
Compare
fd42db4 to
8bb282b
Compare
* save the cache at the common_speculative_impl_ngram_cache destruction * catch std::ifstream::failure the way llama-lookup does, so a permission/read failure cannot replace the file
8bb282b to
4335d1b
Compare
|
@ggerganov kind reminder for a code review of this PR, that simply saves the dynamic ngram cache file (when a path is provided) to the filesystem on object destruction. Thanks in advance! |
Overview
When we select the
COMMON_SPECULATIVE_TYPE_NGRAM_CACHEspeculative implementation we create a newcommon_speculative_state_ngram_cachestate usingcreate_state_ngram_cache, where we instantiate the new state by specifying various parameters (e.g,n_draft,save_staticandsave_dynamic) by hardcoding them.Instead we remove those options and only depend on the existence of lookup_cache_dynamic and lookup_cache_static (both user provided) for enabling the saving and updating the dynamic cache into a file.
on object destruction check if the above functionality is supported (i.e. if the lookup_cache_dynamic path is provided by the user) then merge all of the ngram_cache_context from each sequence info and save the final common_ngram_cache to a file using common_ngram_cache_save.
catch std::ifstream::failure the way llama-lookup does, so a permission/read failure cannot replace the file
Additional information
Add self‑speculative decoding (no draft model required)#18471
Requirements