You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Misc. bug: ngram-cache drafting reads before the start of draft for inputs shorter than 4 tokens #30724
I noticed that common_ngram_cache_draft is currently reading before the start of draft when the input has fewer tokens than ngram_max. ngram_start_cd can become negative and wrap in get_token because the early return is currently only checking inp_size < LLAMA_NGRAM_STATIC.
My concern here is that in a release build the out of bounds tokens will become part of the n-gram key and the drafts will depend on whatever memory sits before draft.
From what I can tell, this bug has been around since 2024.
Steps to reproduce:
First build with -DCMAKE_BUILD_TYPE=Debug -DLLAMA_SANITIZE_ADDRESS=ON -DLLAMA_SANITIZE_UNDEFINED=ON. Then run the following command on any short text file that is longer than 128 tokenspbc:
I think we can fix this by just skipping the ngram sizes that can't fit i.e just do a continue when ngram_start_cd < 0.
I am happy to open up a PR with the fix and a regression test.
First Bad Commit
50ccaf5 (#5479). The bug has been present since common/ngram-cache.cpp was added.
Relevant log output
Logs
.../c++/v1/__vector/vector.h:411:12: runtime error: addition of unsigned offset to 0x602000199650 overflowed to 0x602000199648==54406==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000199648 at pc 0x00010700e32c bp 0x00016d39c0e0 sp 0x00016d39c0d8READ of size 4 at 0x602000199648 thread T0 #0 0x00010700e328 in get_token(...) ngram-cache.cpp:56 #1 0x00010700d934 in common_ngram_cache_draft(...) ngram-cache.cpp:175 #2 0x000102a63e68 in main lookup-stats.cpp:920x602000199648 is located 8 bytes before 4-byte region [0x602000199650,0x602000199654)
Activity