review: scope KV receive consensus to the TP group, compare full KV state

Address both P1 review comments:

- The exchange now runs on the stage's tensor-model-parallel group
  (vLLM parallel state) instead of pt.world. World also holds DP
  replicas and PP stages working on different requests, so the old
  group could mix verdicts across requests and — worse — deadlock if
  one replica skipped the exchange (dummy request) while another
  entered it. Within the TP group every skip guard is symmetric.

- Ranks now exchange (primary_received, sorted applied-KV roles)
  instead of a bare flag, using the same field enumeration as
  apply/broadcast, so partially-received CFG companion KV
  (cfg_text/cfg_img) diverging between ranks is caught too. Verdict is
  identical-state-everywhere: any divergence clears KV on every rank;
  symmetric absence is kept because it is consistent (Bagel's empty
  unconditional branch).

Local e2e rerun of test_bagel[tp_vae_patch_parallel_2] passed and the
new path fired on a real divergence (one rank primary+metadata, the
other only cfg_kv_request_ids) — both ranks fell back together.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
tzhouamandClaude Fable 5 committed 2026-08-01 16:29:29 +08:00
1 parent 0eda607077
commit bac3eafc18
3 files changed
+163 -74

No files matched your search

@@ -69,6 +69,12 @@ class _TransferTopoConfig:
sp_rank: int
sp_group: Any
world: Any
# The stage's tensor-model-parallel group (vLLM parallel state). Only the
# ranks in this group execute the same request in lockstep — DP replicas
# and PP stages in ``world`` do not — so per-request consensus exchanges
# must use this group, never ``world``.
tp_group: Any = None
tp_size: int = 1
@property
def is_leader(self) -> bool:
@@ -636,6 +642,16 @@ class OmniKVTransferManager:
else:
role = ReceiveRole.LEADER if world_rank == 0 else ReceiveRole.FOLLOWER
# The stage's TP group comes from vLLM parallel state (the TP-sharded
# LM path); it may legitimately be uninitialized on non-TP stages.
try:
from vllm.distributed.parallel_state import get_tp_group
tp_group = get_tp_group()
tp_size = tp_group.world_size
except Exception:
tp_group, tp_size = None, 1 # vLLM TP not initialized
return _TransferTopoConfig(
role=role,
tp_active=tp_active,
@@ -646,6 +662,8 @@ class OmniKVTransferManager:
sp_rank=sp_rank,
sp_group=sp_group,
world=world,
tp_group=tp_group,
tp_size=tp_size,
)
def _resolve_sender_info(
@@ -1762,25 +1780,33 @@ class OmniKVTransferManager:
return self._unpack_kv_payload(combined)
def _tp_local_receive_consensus(self, req: Any, received: bool) -> bool:
"""All-or-nothing receive verdict across pure-TP ranks (LOCAL role).
"""Identical-KV-state verdict across pure-TP ranks (LOCAL role).
In pure TP every rank fetches its own KV shard with an independent
timeout and ``distribute_kv_cache`` is a no-op, so a single rank's
silent miss sends only that rank into the pipeline's no-KV prefill —
it then enters TP collectives its peers never join, and the NCCL
watchdog kills the worker (#5627). Exchange per-rank receive flags;
if any rank missed, every rank drops its KV so all take the same
fallback path together.
watchdog kills the worker (#5627). Each rank reports a signature of
its applied KV state — the primary-receive flag plus the set of
applied payload roles, so partially-received CFG companion KV
(``cfg_text``/``cfg_img``) diverging between ranks is caught too. If
the signatures differ, every rank drops its KV so all take the same
fallback path together; identical-but-partial state is kept, since
symmetric absence is consistent (e.g. Bagel's empty unconditional
branch).
The skip guards below depend only on topology, config, and the
request id — identical on every rank — so ranks always agree on
whether the exchange happens.
The exchange runs over the stage's tensor-parallel group only: those
are the ranks executing this request in lockstep. ``world`` would
also contain DP replicas / PP stages working on different requests —
mixing their flags corrupts the verdict, and a replica skipping the
exchange (dummy request) while another enters it would deadlock.
Within the TP group the skip guards below depend only on topology,
config, and the request id — identical on every TP rank — so ranks
always agree on whether the exchange happens.
"""
pt = self.topo_config
group = pt.world
if not (pt.is_local and pt.tp_active) or group is None:
return received
if getattr(group, "world_size", 1) <= 1:
group = pt.tp_group
if not (pt.is_local and pt.tp_active) or group is None or pt.tp_size <= 1:
return received
if not self.config.need_recv_cache:
return received
@@ -1788,30 +1814,28 @@ class OmniKVTransferManager:
if request_id is None or OmniDiffusionRequest.is_dummy_run_request_id(request_id):
return received
signature = (bool(received), tuple(sorted(self._collect_request_kv_payload(req))))
if group.rank_in_group == 0:
flags = [bool(received)]
flags.extend(bool(group.recv_object(src=src)) for src in range(1, group.world_size))
all_received = all(flags)
group.broadcast_object(all_received, src=0)
signatures = [signature]
signatures.extend(group.recv_object(src=src) for src in range(1, pt.tp_size))
consistent = all(sig == signature for sig in signatures)
group.broadcast_object(consistent, src=0)
else:
group.send_object(bool(received), dst=0)
all_received = bool(group.broadcast_object(None, src=0))
group.send_object(signature, dst=0)
consistent = bool(group.broadcast_object(None, src=0))
if not all_received:
if received:
logger.warning(
"KV receive for %s missed on a peer TP rank; dropping this rank's "
"KV so all ranks take the no-KV fallback together instead of "
"desyncing TP collectives",
request_id,
)
self._clear_request_kv_payload(req)
else:
logger.warning(
"KV receive for %s missed on this or a peer TP rank; all ranks fall back without KV",
request_id,
)
return all_received
if not consistent:
logger.warning(
"KV state for %s diverged across TP ranks (this rank: received=%s, roles=%s); "
"dropping KV on every rank so all take the no-KV fallback together "
"instead of desyncing TP collectives",
request_id,
signature[0],
list(signature[1]),
)
self._clear_request_kv_payload(req)
return False
return received
def receive_multi_kv_cache_distributed(
self,