Conversation
OverviewAnalysis of 114,917 functions across 14 binaries reveals minimal performance impact from commit d0e14f7 implementing n-gram embedding infrastructure. Modified: 43 functions (0.037%), new: 71, removed: 10, unchanged: 114,793 (99.89%). Power Consumption Changes:
Function AnalysisRoot Cause: Most Impacted Functions (libllama.so):
Improved Functions:
Other analyzed functions showed proportional changes consistent with the 50% structure size increase, all occurring in initialization paths rather than inference hot paths. Additional FindingsImpact Isolation: Changes are well-contained to KV cache initialization. Per-token inference overhead is <10ns (<0.01% of token generation time). GPU operations (CUDA, Metal, HIP, Vulkan) remain unchanged with 0% impact on matrix operations and attention mechanisms. The implementation maintains trivial copyability and cache-friendly layout. Code marked "wip" with TODO for optimizing O(n) linear scan in 🔎 Full breakdown: Loci Inspector. |
7077d25 to
62123f6
Compare
6efe498 to
8db062d
Compare
Note
Source pull request: ggml-org/llama.cpp#19167
Target support: https://huggingface.co/meituan-longcat/LongCat-Flash-Lite
NOTE: I'm having quite limited time recently, but quite interested by the idea of ngram embedding. Pushing this PR in a rough state mostly for discussions.
The most complex part of the model is to integrate the idea of "ngram cache" inside llama.cpp. That means new tokens can "look back" to see N tokens that were added in the past.
For example: when I given ngram_n = 3 and given 5 input tokens t0, t1, t2, t3, t4. Each token can "see" these ngrams:
This sounds similar to SWA logic but I can't wrap my head around how to reuse the code inside
set_input_kq_mask_impl. CC @ggerganov if you have any ideas.And to store the token ID of each position,
llama_kv_cell_extis extended to store this, quite similar to x/y position for m-rope.The current implementation does return the ngram, what's left to do is to use this info to calculate the hash (quite simple, just some multiplications and modulo):