[kv_offload+HMA][4/N]: Support sliding window lookup (#36645)

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Co-authored-by: Nicolò Lucchesi <nlucches@redhat.com>
This commit is contained in:
Or Ozeri
2026-04-20 12:53:51 +03:00
committed by GitHub
co-authored by Nicolò Lucchesi
parent 2aab9acf48
commit f774ba028a
7 changed files with 269 additions and 78 deletions
+7 -13
View File
@@ -7,8 +7,7 @@ This class runs in the scheduler, tracks which blocks are offloaded
and their address.
The class provides the following primitives:
lookup() - find the length of the maximal series of blocks,
starting from the first one, that are all offloaded.
lookup() - check whether a single block is offloaded and ready.
prepare_load() - prepare given blocks to be read.
The given blocks will be protected from eviction.
This function returns a LoadSpec which encapsulates
@@ -91,23 +90,18 @@ class OffloadingEvent:
class OffloadingManager(ABC):
@abstractmethod
def lookup(
self,
keys: Iterable[OffloadKey],
req_context: ReqContext,
) -> int | None:
def lookup(self, key: OffloadKey, req_context: ReqContext) -> bool | None:
"""
Finds the length of the maximal series of blocks, starting from the
first one, that are all offloaded.
Checks whether a single block is offloaded and ready to be read.
Args:
keys: the keys identifying the blocks to lookup.
key: the key identifying the block to lookup.
req_context: per-request context (e.g. kv_transfer_params).
Returns:
An integer representing the maximal number of blocks that
are currently offloaded, or None if the lookup should be retried
later. Returning None will delay the request handling by the vLLM
True if the block is offloaded and ready, False if not,
or None if the lookup should be retried later.
Returning None will delay the request handling by the vLLM
scheduler.
"""
pass
+3 -12
View File
@@ -84,18 +84,9 @@ class CPUOffloadingManager(OffloadingManager):
# --- OffloadingManager interface ---
def lookup(
self,
keys: Iterable[OffloadKey],
req_context: ReqContext,
) -> int | None:
hit_count = 0
for key in keys:
block = self._policy.get(key)
if block is None or not block.is_ready:
break
hit_count += 1
return hit_count
def lookup(self, key: OffloadKey, req_context: ReqContext) -> bool | None:
block = self._policy.get(key)
return block is not None and block.is_ready
def prepare_load(
self,
+12 -13
View File
@@ -27,8 +27,9 @@ class FilterReusedOffloadingManager(OffloadingManager):
All methods are delegated to the *backing* manager. Two methods are
intercepted:
* ``lookup`` — records each visited key in an internal LRU counter.
* ``prepare_store`` — filters out keys that have not yet
* ``lookup`` — records the visited key in an internal LRU
counter, then delegates to the backing manager.
crossed the threshold *before* calling the backing
``prepare_store``.
@@ -66,18 +67,16 @@ class FilterReusedOffloadingManager(OffloadingManager):
# Intercepted methods
# ------------------------------------------------------------------
def lookup(self, keys: Iterable[OffloadKey], req_context: ReqContext) -> int | None:
"""Record each key, then delegate lookup to backing manager."""
keys = list(keys)
for key in keys:
if key in self.counts:
self.counts.move_to_end(key)
self.counts[key] += 1
else:
if len(self.counts) >= self.max_tracker_size:
self.counts.popitem(last=False) # evict LRU
self.counts[key] = 1
return self._backing.lookup(keys, req_context)
def lookup(self, key: OffloadKey, req_context: ReqContext) -> bool | None:
"""Record the key, then delegate lookup to backing manager."""
if key in self.counts:
self.counts.move_to_end(key)
self.counts[key] += 1
else:
if len(self.counts) >= self.max_tracker_size:
self.counts.popitem(last=False) # evict LRU
self.counts[key] = 1
return self._backing.lookup(key, req_context)
def prepare_store(
self, keys: Iterable[OffloadKey], req_context: ReqContext