[Feature] Support Prefill-Decode disaggregation via vLLM KV transfer (#2220)
Signed-off-by: LiuBingyu <liubingyu62@gmail.com>
This commit is contained in:
1 parent
b88d3ce75e
commit
a5a4998ece
11 files changed
+1672
-48
No files matched your search
@@ -23,9 +23,19 @@ logger = logging.getLogger(__name__)
|
||||
class PDDisaggregationMixin:
|
||||
"""Mixin supplying PD disaggregation helpers to OmniBase."""
|
||||
|
||||
def _get_pd_separation_pair(self) -> tuple[int, int] | None:
|
||||
"""PD prefill/decode indices when ``_init_pd_state`` ran; else ``None``.
|
||||
|
||||
Partial test doubles may skip ``OmniBase.__init__``; treat missing state as
|
||||
no PD disaggregation instead of raising ``AttributeError``.
|
||||
"""
|
||||
return getattr(self, "_pd_separation_pair", None)
|
||||
|
||||
def _init_pd_state(self) -> None:
|
||||
"""Initialise PD disaggregation state."""
|
||||
self._pd_separation_pair: tuple[int, int] | None = self._detect_pd_separation()
|
||||
self._pd_separation_pair: tuple[int, int] | None = self.detect_pd_separation_from_stage_configs(
|
||||
self.stage_configs
|
||||
)
|
||||
self._pd_connector_info: dict[str, Any] | None = None
|
||||
self._pd_kv_params_by_req: dict[str, dict[str, Any]] = {}
|
||||
self._pd_kv_params_lock = threading.Lock()
|
||||
@@ -40,11 +50,19 @@ class PDDisaggregationMixin:
|
||||
d_id,
|
||||
)
|
||||
|
||||
def _detect_pd_separation(self) -> tuple[int, int] | None:
|
||||
"""Scan stage_list for a prefill/decode pair. Returns (p_id, d_id) or None."""
|
||||
@staticmethod
|
||||
def detect_pd_separation_from_stage_configs(stage_configs: list[Any]) -> tuple[int, int] | None:
|
||||
"""Scan stage configs for a prefill/decode pair.
|
||||
|
||||
Returns:
|
||||
(prefill_idx, decode_idx) if one pair exists, None if not found.
|
||||
|
||||
Raises:
|
||||
ValueError: if multiple candidate PD pairs are found.
|
||||
"""
|
||||
prefill_by_id: dict[int, int] = {}
|
||||
decode_indices: list[int] = []
|
||||
for i, stage in enumerate(self.stage_list):
|
||||
for i, stage in enumerate(stage_configs):
|
||||
if getattr(stage, "is_prefill_only", False):
|
||||
prefill_by_id[i] = i
|
||||
sid = getattr(stage, "stage_id", i)
|
||||
@@ -55,7 +73,7 @@ class PDDisaggregationMixin:
|
||||
|
||||
pd_pairs: list[tuple[int, int]] = []
|
||||
for j in decode_indices:
|
||||
source_ids = getattr(self.stage_list[j], "engine_input_source", [])
|
||||
source_ids = getattr(stage_configs[j], "engine_input_source", [])
|
||||
for src in source_ids:
|
||||
if src in prefill_by_id:
|
||||
pd_pairs.append((prefill_by_id[src], j))
|
||||
@@ -107,10 +125,11 @@ class PDDisaggregationMixin:
|
||||
|
||||
def _validate_pd_separation_config(self) -> None:
|
||||
"""Validate PD stage configurations are consistent."""
|
||||
assert self._pd_separation_pair is not None
|
||||
p_id, d_id = self._pd_separation_pair
|
||||
p_stage = self.stage_list[p_id]
|
||||
d_stage = self.stage_list[d_id]
|
||||
pair = self._get_pd_separation_pair()
|
||||
assert pair is not None
|
||||
p_id, d_id = pair
|
||||
p_stage = self.stage_configs[p_id]
|
||||
d_stage = self.stage_configs[d_id]
|
||||
|
||||
def _get_kv_cfg(stage: "OmniStage") -> dict[str, Any]:
|
||||
ea = stage.engine_args
|
||||
@@ -158,11 +177,12 @@ class PDDisaggregationMixin:
|
||||
|
||||
def _get_pd_connector_info(self) -> dict[str, Any] | None:
|
||||
"""Extract prefill engine KV connector info."""
|
||||
if self._pd_separation_pair is None:
|
||||
pair = self._get_pd_separation_pair()
|
||||
if pair is None:
|
||||
return None
|
||||
|
||||
p_id, _ = self._pd_separation_pair
|
||||
p_stage = self.stage_list[p_id]
|
||||
p_id, _ = pair
|
||||
p_stage = self.stage_configs[p_id]
|
||||
|
||||
ea = p_stage.engine_args
|
||||
kv_cfg = getattr(ea, "kv_transfer_config", None)
|
||||
@@ -241,18 +261,17 @@ class PDDisaggregationMixin:
|
||||
|
||||
def _is_pd_routing(self, stage_id: int, next_stage_id: int) -> bool:
|
||||
"""True when edge stage_id → next_stage_id is the prefill→decode boundary."""
|
||||
return self._pd_separation_pair is not None and self._pd_separation_pair == (
|
||||
stage_id,
|
||||
next_stage_id,
|
||||
)
|
||||
pair = self._get_pd_separation_pair()
|
||||
return pair is not None and pair == (stage_id, next_stage_id)
|
||||
|
||||
def _maybe_expand_sampling_params(self, sampling_params_list: list) -> list:
|
||||
"""Auto-duplicate thinker SP for decode stage when user provides N-1 params."""
|
||||
if self._pd_separation_pair is None:
|
||||
pair = self._get_pd_separation_pair()
|
||||
if pair is None:
|
||||
return sampling_params_list
|
||||
if len(sampling_params_list) != len(self.stage_list) - 1:
|
||||
if len(sampling_params_list) != len(self.stage_configs) - 1:
|
||||
return sampling_params_list
|
||||
p_id, d_id = self._pd_separation_pair
|
||||
p_id, d_id = pair
|
||||
sp_list = list(sampling_params_list)
|
||||
sp_list.insert(d_id, sp_list[p_id])
|
||||
return sp_list
|
||||
|
||||
Reference in new issue
Block a user