[Diffusion] Add native KV cache initialization and Scheduler-managed block allocation (#6094)

Signed-off-by: zwhzzz0821 <zwhzzz0821@users.noreply.github.com>
Co-authored-by: zwhzzz0821 <zwhzzz0821@users.noreply.github.com>
This commit is contained in:
Yukim1andzwhzzz0821 authored and GitHub committed 2026-08-18 07:00:24 +00:00
1 parent b283215c28
commit 0a1846aa45
33 files changed
+2609 -265

No files matched your search

+35
View File
@@ -5,10 +5,12 @@ from collections.abc import Callable
from typing import TYPE_CHECKING, Any
from vllm.utils.import_utils import resolve_obj_by_qualname
from vllm.v1.kv_cache_interface import KVCacheConfig, KVCacheSpec
from vllm_omni.diffusion.data import OmniDiffusionConfig
if TYPE_CHECKING:
from vllm_omni.diffusion.request import OmniDiffusionRequest
from vllm_omni.diffusion.sched.interface import DiffusionSchedulerOutput
from vllm_omni.diffusion.worker.utils import BaseRunnerOutput
@@ -115,6 +117,39 @@ class DiffusionExecutor(ABC):
"""
return None
def get_kv_cache_specs(self) -> list[dict[str, KVCacheSpec]]:
"""Collect rank-local native specs after every Worker loads its model."""
result = self.collective_rpc(
"get_kv_cache_specs",
unique_reply_rank=0,
exec_all_ranks=True,
)
if not isinstance(result, list):
raise TypeError(f"get_kv_cache_specs returned {type(result).__name__}, expected list")
return result
def determine_available_kv_memory(self, profile_requests: list[OmniDiffusionRequest]) -> list[int]:
"""Profile and collect the KV memory budget on every Worker rank."""
result = self.collective_rpc(
"determine_available_kv_memory",
args=(profile_requests,),
unique_reply_rank=0,
exec_all_ranks=True,
)
if not isinstance(result, list) or not all(isinstance(value, int) for value in result):
raise TypeError("determine_available_kv_memory must return list[int]")
return result
def set_kv_cache_configs(self, kv_cache_configs: list[KVCacheConfig]) -> None:
"""Send each native rank-local config back to all Workers."""
# The default control-plane RPC mode executes on every rank and has
# rank 0 return the gathered rank statuses, so failures on nonzero
# ranks are not silently dropped.
self.collective_rpc("set_kv_cache_configs", args=(kv_cache_configs,))
@abstractmethod
def shutdown(self) -> None:
"""Shutdown the executor and release resources."""
@@ -465,16 +465,14 @@ class MultiprocDiffusionExecutor(DiffusionExecutor):
for new_req in new_reqs:
validate_new_request_data_identity(new_req)
has_diffusion_kv_metadata = any(new_req.diffusion_kv_metadata is not None for new_req in new_reqs)
# DP multi-concurrency: when DLO+AllGather is active and multiple
# requests are scheduled, send ALL requests in one broadcast RPC.
# Each rank picks req[rank % len(reqs)] and computes independently.
# requests are scheduled, send every complete NewRequestData envelope
# in one broadcast RPC. Each rank picks one envelope, keeping its
# request and Diffusion KV metadata inseparable.
# All ranks reply (unique_reply_rank=None) so we collect dp_size
# responses and match by dp_rank.
if (
len(new_reqs) > 1
and not has_diffusion_kv_metadata
and getattr(self.od_config, "enable_distributed_layerwise_offload", False)
and getattr(self.od_config, "dlo_use_allgather", True)
):
@@ -507,12 +505,11 @@ class MultiprocDiffusionExecutor(DiffusionExecutor):
f"empty prompt request IDs: {empty_prompt_ids}."
)
reqs_list = [nr.req for nr in new_reqs]
try:
results = self.collective_rpc(
"execute_model",
timeout=_DLO_DP_WAVE_TIMEOUT_S,
args=(reqs_list, self.od_config, scheduler_output.kv_prefetch_job),
args=(new_reqs, self.od_config, scheduler_output.kv_prefetch_job),
unique_reply_rank=None,
exec_all_ranks=True,
)