Skip to content

Commit b9e8b81

Browse files
authored
[Core] Use a faster hash function (LMCache#1020)
* perf: replace sha256 by xxhash Signed-off-by: Zhou Fang <[email protected]> * build: add xxhash to requirements Signed-off-by: Zhou Fang <[email protected]> * style: import Signed-off-by: Zhou Fang <[email protected]> * build: add xxhash to common requirements Signed-off-by: Zhou Fang <[email protected]> --------- Signed-off-by: Zhou Fang <[email protected]>
1 parent 2b8c260 commit b9e8b81

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

lmcache/cache_engine.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
# Standard
1616
from typing import Dict, Iterable, List, Optional, Tuple, Union
17-
import hashlib
1817
import logging
1918
import time
2019

2120
# Third Party
2221
import torch
22+
import xxhash
2323

2424
# First Party
2525
from lmcache.config import LMCacheEngineConfig, LMCacheEngineMetadata
@@ -85,8 +85,7 @@ def _hash(
8585
tokens: torch.Tensor,
8686
prefix_hash: str,
8787
) -> str:
88-
# TODO: change it to a more efficient hash function
89-
hasher = hashlib.sha256()
88+
hasher = xxhash.xxh64()
9089
hasher.update(prefix_hash.encode("ascii"))
9190
hasher.update(tokens.numpy().tobytes())
9291
return hasher.hexdigest()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ requires = [
77
"setuptools_scm>=8",
88
"torch==2.7.0",
99
"wheel",
10+
"xxhash==3.5.0",
1011
]
1112
build-backend = "setuptools.build_meta"
1213

requirements/build.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ setuptools>=77.0.3,<81.0.0
66
setuptools_scm>=8
77
torch==2.7.0 # Corresponds to the version used by vLLM main branch
88
wheel
9+
xxhash==3.5.0

requirements/common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ setuptools_scm>=8
1717
sortedcontainers
1818
torch==2.7.0 # Should correspond to the version used by vLLM main branch
1919
transformers >= 4.51.1
20+
xxhash==3.5.0

0 commit comments

Comments
 (0)