Fix NONE_HASH import: use module ref instead of from-import (value binding bug)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -142,6 +142,7 @@ class MooncakeConnectorMetadata(KVConnectorMetadata):
|
||||
# Hash table sync: scheduler → worker (for direct RDMA read)
|
||||
self.hash_table_updates: dict[str, int] = {} # hex hash → block_id
|
||||
self.hash_table_removals: set[str] = set()
|
||||
self.token_hash_updates: dict[str, int] = {} # str(hash(tokens)) → block_id
|
||||
|
||||
def add_new_req(
|
||||
self,
|
||||
|
||||
@@ -69,10 +69,11 @@ class MooncakeBootstrapServer:
|
||||
self.server: uvicorn.Server | None = None
|
||||
|
||||
# Direct RDMA read support
|
||||
self._hash_table: dict[str, int] = {} # hex BlockHash → block_id (legacy)
|
||||
self._kv_info: dict | None = None # set by worker at register_kv_caches
|
||||
self._pinned: dict[str, list[int]] = {} # pin_token → block_ids
|
||||
self._block_pool = None # set by scheduler for token-based lookup
|
||||
self._hash_table: dict[str, int] = {} # hex BlockHash → block_id
|
||||
self._token_hash_table: dict[str, int] = {} # str(hash(token_tuple)) → block_id
|
||||
self._kv_info: dict | None = None
|
||||
self._pinned: dict[str, list[int]] = {}
|
||||
self._block_pool = None
|
||||
|
||||
def __del__(self):
|
||||
self.shutdown()
|
||||
@@ -227,14 +228,10 @@ class MooncakeBootstrapServer:
|
||||
) -> tuple[list[int | None], list[int]]:
|
||||
"""Look up cached blocks by computing hashes using the synced hash table.
|
||||
|
||||
Computes block hashes from token_ids using the same hash function
|
||||
as the scheduler, then looks up in the synced _hash_table.
|
||||
Uses module-level NONE_HASH (accessed via module ref to get latest value
|
||||
after init_none_hash is called).
|
||||
"""
|
||||
from vllm.v1.core.kv_cache_utils import (
|
||||
BlockHash,
|
||||
hash_block_tokens,
|
||||
NONE_HASH,
|
||||
)
|
||||
import vllm.v1.core.kv_cache_utils as kv_utils
|
||||
from vllm.utils.hashing import sha256_cbor
|
||||
|
||||
block_size = self._kv_info.get("block_size", 512) if self._kv_info else 512
|
||||
@@ -244,19 +241,20 @@ class MooncakeBootstrapServer:
|
||||
|
||||
block_ids: list[int | None] = []
|
||||
pinned_ids: list[int] = []
|
||||
prev_hash = NONE_HASH
|
||||
prev_hash = kv_utils.NONE_HASH # module-level ref, always current
|
||||
|
||||
for i in range(num_blocks):
|
||||
block_tokens = tuple(token_ids[i * block_size:(i + 1) * block_size])
|
||||
block_hash = hash_block_tokens(sha256_cbor, prev_hash, block_tokens, None)
|
||||
block_hash = kv_utils.hash_block_tokens(
|
||||
sha256_cbor, prev_hash, block_tokens, None)
|
||||
prev_hash = block_hash
|
||||
|
||||
bid = self._hash_table.get(block_hash.hex())
|
||||
if i == 0:
|
||||
table_sample = next(iter(self._hash_table)) if self._hash_table else "empty"
|
||||
logger.info(
|
||||
"_lookup_by_tokens: block0 hash=%s, NONE_HASH=%s, table_sample=%s",
|
||||
block_hash.hex()[:16], NONE_HASH.hex()[:16], table_sample[:16])
|
||||
"_lookup: hash=%s NONE=%s tbl=%s",
|
||||
block_hash.hex()[:12], kv_utils.NONE_HASH.hex()[:12], table_sample[:12])
|
||||
if bid is not None:
|
||||
block_ids.append(bid)
|
||||
pinned_ids.append(bid)
|
||||
|
||||
Reference in New Issue
Block a user