From 0bfa394affbf62db60390411294ae6c67cb24455 Mon Sep 17 00:00:00 2001 From: Yuanhang Sun Date: Fri, 24 Oct 2025 23:53:13 +0800 Subject: [PATCH] [Fix]: HiCache hasher failed when EAGLE mode enabled (#12025) --- python/sglang/srt/mem_cache/hicache_storage.py | 8 +++++++- .../mem_cache/storage/hf3fs/mini_3fs_metadata_server.py | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/mem_cache/hicache_storage.py b/python/sglang/srt/mem_cache/hicache_storage.py index ac9cb2917..27f963c54 100644 --- a/python/sglang/srt/mem_cache/hicache_storage.py +++ b/python/sglang/srt/mem_cache/hicache_storage.py @@ -19,7 +19,13 @@ def get_hash_str(token_ids: List[int], prior_hash: str = None) -> str: hasher.update(bytes.fromhex(prior_hash)) for t in token_ids: - hasher.update(t.to_bytes(4, byteorder="little", signed=False)) + if isinstance(t, tuple): + # EAGLE bigram mode: hash both elements to uniquely identify the bigram + for elem in t: + hasher.update(elem.to_bytes(4, byteorder="little", signed=False)) + else: + # Regular mode: single integer token + hasher.update(t.to_bytes(4, byteorder="little", signed=False)) return hasher.hexdigest() diff --git a/python/sglang/srt/mem_cache/storage/hf3fs/mini_3fs_metadata_server.py b/python/sglang/srt/mem_cache/storage/hf3fs/mini_3fs_metadata_server.py index 414d13adc..03fec2080 100644 --- a/python/sglang/srt/mem_cache/storage/hf3fs/mini_3fs_metadata_server.py +++ b/python/sglang/srt/mem_cache/storage/hf3fs/mini_3fs_metadata_server.py @@ -3,8 +3,9 @@ import atexit import json import logging import threading +from collections import OrderedDict from pathlib import Path -from typing import Dict, List, Optional, OrderedDict, Tuple +from typing import Dict, List, Optional, Tuple import orjson import requests @@ -136,7 +137,7 @@ class GlobalMetadataState: num_pages = data["num_pages"] rank_meta = RankMetadata(num_pages) rank_meta.free_pages = data["free_pages"] - rank_meta.key_to_index = dict(data["key_to_index"]) + rank_meta.key_to_index = OrderedDict(data["key_to_index"]) self.ranks[rank_id] = rank_meta logging.info( f"Successfully loaded metadata for {len(self.ranks)} ranks."