[Frontend][Core] Add release_kv_cache_memory() API (#44890)
Signed-off-by: Dakai An <dakaian108@gmail.com> Signed-off-by: AlanFokCo <alanfok2868@gmail.com> Signed-off-by: aoshen02 <aoshen@inferact.ai> Signed-off-by: Dakai An <77474977+andakai@users.noreply.github.com> Co-authored-by: AlanFokCo <alanfok2868@gmail.com> Co-authored-by: aoshen02 <aoshen@inferact.ai> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
AlanFokCo
aoshen02
OpenAI Codex
parent
a524f80b1f
commit
092bdd6d57
+27
-2
@@ -957,12 +957,15 @@ class EngineCore:
|
||||
pause_future.add_done_callback(pause_complete)
|
||||
return future
|
||||
|
||||
def wake_up(self, tags: list[str] | None = None):
|
||||
def wake_up(self, tags: list[str] | None = None) -> bool:
|
||||
"""Wake up the engine from sleep.
|
||||
|
||||
Args:
|
||||
tags: Tags to wake up. Use ["scheduling"] for level 0 wake up.
|
||||
|
||||
Returns:
|
||||
Whether all executor memory is resident again (fully awake).
|
||||
|
||||
"""
|
||||
if tags is not None and "scheduling" in tags:
|
||||
# Remove "scheduling" from tags if there are other tags to process.
|
||||
@@ -973,8 +976,30 @@ class EngineCore:
|
||||
|
||||
# Partial wakes intentionally keep the remaining allocations asleep.
|
||||
# Resume scheduling only once all executor memory is resident again.
|
||||
if not self.model_executor.is_sleeping:
|
||||
fully_awake = not self.model_executor.is_sleeping
|
||||
if fully_awake:
|
||||
self.resume_scheduler()
|
||||
return fully_awake
|
||||
|
||||
def release_kv_cache_memory(self) -> None:
|
||||
"""Discard KV cache physical memory. Requires a completed pause
|
||||
and all executor memory to be resident. Kept requests are recomputed
|
||||
after wake-up.
|
||||
"""
|
||||
if not (
|
||||
self.is_scheduler_paused()
|
||||
and not self.scheduler.has_requests()
|
||||
and not self.batch_queue
|
||||
):
|
||||
raise RuntimeError(
|
||||
"release_kv_cache_memory() requires a completed pause first"
|
||||
)
|
||||
if self.model_executor.is_sleeping:
|
||||
raise RuntimeError(
|
||||
"release_kv_cache_memory() requires all executor memory to be resident"
|
||||
)
|
||||
self._reset_caches()
|
||||
self.model_executor.discard(("kv_cache",))
|
||||
|
||||
def is_sleeping(self) -> bool:
|
||||
"""Check if engine is sleeping at any level."""
|
||||
|
||||
Reference in New Issue
Block a user