[Core] Add xxHash as a high-performance hash option for accelerating prefix caching (#29163)

Signed-off-by: LuminolT <lumischen01@gmail.com>
Signed-off-by: Lumis Chen <lumischen01@gmail.com>
Co-authored-by: Russell Bryant <rbryant@redhat.com>
This commit is contained in:
Lumis Chen
2025-12-04 00:06:57 +08:00
committed by GitHub
parent 5aa9b09040
commit 9bcf92295a
7 changed files with 332 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ from typing import Any, NewType, TypeAlias, overload
from vllm import envs
from vllm.config import VllmConfig
from vllm.logger import init_logger
from vllm.utils.hashing import sha256_cbor
from vllm.utils.hashing import sha256_cbor, xxhash_cbor
from vllm.utils.math_utils import cdiv
from vllm.utils.mem_constants import GiB_bytes
from vllm.v1.kv_cache_interface import (
@@ -83,18 +83,19 @@ logger = init_logger(__name__)
#
# The function `init_none_hash` initializes this variable globally.
NONE_HASH: BlockHash
_CBOR_HASH_FUNCTIONS = frozenset({sha256_cbor, xxhash_cbor})
def init_none_hash(hash_fn: Callable[[Any], bytes]):
global NONE_HASH
hash_seed = os.getenv("PYTHONHASHSEED")
if hash_seed is None and hash_fn is sha256_cbor:
if hash_seed is None and hash_fn in _CBOR_HASH_FUNCTIONS:
logger.warning(
"PYTHONHASHSEED is not set. This will lead to non-reproducible "
"block-hashes when using sha256_cbor as the hash function."
"Consider setting PYTHONHASHSEED to a fixed value for "
"reproducibility."
"block-hashes when using CBOR-based hash functions such as "
"sha256_cbor or xxhash_cbor. Consider setting PYTHONHASHSEED to a "
"fixed value for reproducibility."
)
if hash_seed is None: