[HiCache] fix: Mooncake Dummy Client mode for hybrid Mamba models (#25278)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Teng Ma <stmatengss@users.noreply.github.com>
This commit is contained in:
co-authored by
Cursor Agent
Teng Ma
parent
1051a8456f
commit
d45ee3f6c5
@@ -296,6 +296,52 @@ class MooncakeBaseStore:
|
||||
|
||||
class MooncakeStore(HiCacheStorage, MooncakeBaseStore):
|
||||
|
||||
@staticmethod
|
||||
def _standalone_required_bytes(mem_pool: Any) -> int:
|
||||
"""Compute total bytes of host buffers that must be visible to the real client.
|
||||
|
||||
In standalone (dummy client) mode, the real mooncake_client process needs
|
||||
to map any host buffers we will later pass by pointer via register_buffer().
|
||||
For hybrid models, that includes KV + sidecar pools (e.g. Mamba temporal/conv).
|
||||
"""
|
||||
# Prefer a generic "hybrid pool" accessor when present.
|
||||
total = 0
|
||||
seen_ptrs: set[int] = set()
|
||||
|
||||
def _add_tensor(t: Optional[torch.Tensor]):
|
||||
nonlocal total
|
||||
if t is None:
|
||||
return
|
||||
try:
|
||||
ptr = int(t.data_ptr())
|
||||
except Exception:
|
||||
return
|
||||
if ptr in seen_ptrs:
|
||||
return
|
||||
seen_ptrs.add(ptr)
|
||||
total += int(t.numel() * t.element_size())
|
||||
|
||||
# Always include the anchor KV buffer if present.
|
||||
_add_tensor(getattr(mem_pool, "kv_buffer", None))
|
||||
|
||||
# HostPoolGroup: include each pool's hybrid buffers when available.
|
||||
entries = getattr(mem_pool, "entries", None)
|
||||
if entries:
|
||||
for entry in entries:
|
||||
host_pool = getattr(entry, "host_pool", None)
|
||||
if host_pool is None:
|
||||
continue
|
||||
# KV pool anchor memory is already covered, but harmless if added twice.
|
||||
_add_tensor(getattr(host_pool, "kv_buffer", None))
|
||||
for buf in getattr(host_pool, "get_hybrid_pool_buffer", lambda: [])():
|
||||
_add_tensor(buf)
|
||||
return total
|
||||
|
||||
# Single HostKVCache-like pool: add its sidecar buffers if any.
|
||||
for buf in getattr(mem_pool, "get_hybrid_pool_buffer", lambda: [])():
|
||||
_add_tensor(buf)
|
||||
return total
|
||||
|
||||
def __init__(
|
||||
self, storage_config: HiCacheStorageConfig = None, mem_pool: HostKVCache = None
|
||||
):
|
||||
@@ -351,8 +397,9 @@ class MooncakeStore(HiCacheStorage, MooncakeBaseStore):
|
||||
"Please set standalone_storage=False "
|
||||
"or upgrade Mooncake by 'pip install mooncake --upgrade'."
|
||||
)
|
||||
required_bytes = self._standalone_required_bytes(mem_pool)
|
||||
ret_code = self.store.setup_dummy(
|
||||
mem_pool.size * mem_pool.size_per_token,
|
||||
required_bytes,
|
||||
DEFAULT_LOCAL_BUFFER_SIZE, # Zero copy interface does not need local buffer
|
||||
self.config.client_server_address,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user