Skip to content

Commit

Permalink
revise hashing function
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesGaessler committed Apr 29, 2024
1 parent 1d516d3 commit 9684f4c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions common/ngram-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ struct llama_ngram {

struct llama_ngram_hash_function {
size_t operator()(const llama_ngram & ngram) const {
size_t hash = 0;
for (int i = 0; i < LLAMA_NGRAM_MAX; ++i) {
hash ^= std::hash<llama_token>{}(ngram.tokens[i]);
size_t hash = ngram.tokens[0];

for (int i = 1; i < LLAMA_NGRAM_MAX; ++i) {
hash <<= 15;
hash ^= ngram.tokens[i];
}

return hash;
}
};
Expand Down

0 comments on commit 9684f4c

Please sign in to comment.