[Feature] Add fault tolerance framework (simplified) for DP+EP external LB deployments (#44428)
Signed-off-by: fangyuchu <fangyuchu@qq.com> Signed-off-by: a798347923 <2645302020@qq.com> Signed-off-by: TianZhuo <2770730562@qq.com> Signed-off-by: a798347923 <39047817+a798347923@users.noreply.github.com> Signed-off-by: 205150940 <112750056+205150940@users.noreply.github.com> Signed-off-by: w00689259 <wangzhuo66@huawei.com> Signed-off-by: zWaNg3 <37772915+zWaNg3@users.noreply.github.com> Signed-off-by: zWaNg3 <389750525@qq.com> Signed-off-by: yzchang-plus <1078477584@qq.com> Signed-off-by: Jade Zheng <zheng.shoujian@outlook.com> Co-authored-by: zWaNg3 <37772915+zWaNg3@users.noreply.github.com> Co-authored-by: a798347923 <2645302020@qq.com> Co-authored-by: TianZhuo <2770730562@qq.com> Co-authored-by: 205150940 <112750056+205150940@users.noreply.github.com> Co-authored-by: a798347923 <39047817+a798347923@users.noreply.github.com> Co-authored-by: w00689259 <wangzhuo66@huawei.com> Co-authored-by: zWaNg3 <389750525@qq.com> Co-authored-by: yzchang-plus <1078477584@qq.com> Co-authored-by: Jade Zheng <zheng.shoujian@outlook.com>
This commit is contained in:
co-authored by
zWaNg3
a798347923
TianZhuo
205150940
a798347923
w00689259
zWaNg3
yzchang-plus
Jade Zheng
parent
33ef67e9fb
commit
0b0bd2b5f6
@@ -31,6 +31,8 @@ FINISH_REASON_STRINGS = ("stop", "length", "abort", "error", "repetition")
|
||||
|
||||
EEP_NOTIFICATION_CALL_ID = -1
|
||||
|
||||
FT_STATUS_CALL_ID = -2
|
||||
|
||||
|
||||
class EEPNotificationType(enum.Enum):
|
||||
NEW_CORE_ENGINES_INIT_READY = "NEW_CORE_ENGINES_INIT_READY"
|
||||
@@ -282,3 +284,9 @@ class ReconfigureRankType(enum.IntEnum):
|
||||
|
||||
KEEP_CURRENT_RANK = -1
|
||||
SHUTDOWN_CURRENT_RANK = -2
|
||||
|
||||
|
||||
class EngineStatusType(enum.IntEnum):
|
||||
HEALTHY = 0
|
||||
DEAD = 1
|
||||
UNHEALTHY = 2
|
||||
|
||||
@@ -44,6 +44,7 @@ from vllm.v1.engine.input_processor import InputProcessor
|
||||
from vllm.v1.engine.output_processor import OutputProcessor, RequestOutputCollector
|
||||
from vllm.v1.engine.parallel_sampling import ParentRequest
|
||||
from vllm.v1.executor import Executor
|
||||
from vllm.v1.fault_tolerance.utils import FaultToleranceRequest, FaultToleranceResult
|
||||
from vllm.v1.metrics.loggers import (
|
||||
StatLoggerFactory,
|
||||
StatLoggerManager,
|
||||
@@ -1041,6 +1042,15 @@ class AsyncLLM(EngineClient):
|
||||
finally:
|
||||
set_scaling_elastic_ep(False)
|
||||
|
||||
async def handle_fault(
|
||||
self, fault_tolerance_request: FaultToleranceRequest
|
||||
) -> FaultToleranceResult:
|
||||
"""send fault tolerance instruction to the engine"""
|
||||
return await self.engine_core.handle_fault(fault_tolerance_request)
|
||||
|
||||
async def get_status(self):
|
||||
return await self.engine_core.get_status()
|
||||
|
||||
@property
|
||||
def is_running(self) -> bool:
|
||||
# Is None before the loop is started.
|
||||
|
||||
@@ -78,6 +78,11 @@ from vllm.v1.engine.utils import (
|
||||
get_physical_gpu_ids_for_local_dp_rank,
|
||||
)
|
||||
from vllm.v1.executor import Executor
|
||||
from vllm.v1.fault_tolerance.engine_core_sentinel import (
|
||||
FT_UTILITY_METHOD,
|
||||
EngineCoreSentinel,
|
||||
fault_tolerant_wrapper,
|
||||
)
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig, get_kv_cache_spec_kind
|
||||
from vllm.v1.metrics.stats import SchedulerIterationDetails, SchedulerStats
|
||||
from vllm.v1.outputs import ModelRunnerOutput
|
||||
@@ -1070,6 +1075,16 @@ class EngineCoreProc(EngineCore):
|
||||
internal_dp_balancing,
|
||||
)
|
||||
|
||||
# Initialize fault tolerance settings.
|
||||
self.enable_fault_tolerance = (
|
||||
vllm_config.parallel_config.enable_fault_tolerance
|
||||
)
|
||||
if self.enable_fault_tolerance:
|
||||
self.ft_sentinel = EngineCoreSentinel(
|
||||
engine=self,
|
||||
parallel_config=vllm_config.parallel_config,
|
||||
)
|
||||
|
||||
# Background Threads and Queues for IO. These enable us to
|
||||
# overlap ZMQ socket IO with GPU since they release the GIL,
|
||||
# and to overlap some serialization/deserialization with the
|
||||
@@ -1355,6 +1370,7 @@ class EngineCoreProc(EngineCore):
|
||||
"""Returns true if shutdown has not been requested."""
|
||||
return self.shutdown_state == EngineShutdownState.RUNNING
|
||||
|
||||
@fault_tolerant_wrapper
|
||||
def run_busy_loop(self):
|
||||
"""Core busy loop of the EngineCore."""
|
||||
while self._handle_shutdown():
|
||||
@@ -1672,6 +1688,14 @@ class EngineCoreProc(EngineCore):
|
||||
except Exception:
|
||||
self._handle_request_preproc_error(req)
|
||||
continue
|
||||
elif request_type == EngineCoreRequestType.UTILITY:
|
||||
request = generic_decoder.decode(data_frames)
|
||||
client_idx, call_id, method, args = request
|
||||
if method == FT_UTILITY_METHOD:
|
||||
self.ft_sentinel.handle_command(
|
||||
client_idx, call_id, args[0]
|
||||
)
|
||||
continue
|
||||
else:
|
||||
request = generic_decoder.decode(data_frames)
|
||||
|
||||
@@ -2021,6 +2045,7 @@ class DPEngineCoreProc(EngineCoreProc):
|
||||
and self.step_counter % self.prefill_schedule_interval != 0
|
||||
)
|
||||
|
||||
@fault_tolerant_wrapper
|
||||
def run_busy_loop(self):
|
||||
"""Core busy loop of the EngineCore for data parallel case."""
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from multiprocessing.queues import Queue
|
||||
from threading import Thread
|
||||
from typing import Any, TypeAlias, TypeVar
|
||||
|
||||
import msgspec
|
||||
import msgspec.msgpack
|
||||
import zmq
|
||||
import zmq.asyncio
|
||||
@@ -35,6 +36,7 @@ from vllm.utils.network_utils import (
|
||||
)
|
||||
from vllm.v1.engine import (
|
||||
EEP_NOTIFICATION_CALL_ID,
|
||||
FT_STATUS_CALL_ID,
|
||||
EEPNotificationType,
|
||||
EngineCoreOutputs,
|
||||
EngineCoreReadyResponse,
|
||||
@@ -56,6 +58,11 @@ from vllm.v1.engine.utils import (
|
||||
launch_core_engines,
|
||||
)
|
||||
from vllm.v1.executor import Executor
|
||||
from vllm.v1.fault_tolerance.engine_core_sentinel import FT_UTILITY_METHOD
|
||||
from vllm.v1.fault_tolerance.utils import (
|
||||
FaultToleranceRequest,
|
||||
FaultToleranceResult,
|
||||
)
|
||||
from vllm.v1.pool.late_interaction import get_late_interaction_engine_index
|
||||
from vllm.v1.serial_utils import MsgpackDecoder, MsgpackEncoder, bytestr
|
||||
|
||||
@@ -272,6 +279,14 @@ class EngineCoreClient(ABC):
|
||||
) -> list[_R]:
|
||||
raise NotImplementedError
|
||||
|
||||
async def handle_fault(
|
||||
self, fault_tolerance_request: FaultToleranceRequest
|
||||
) -> FaultToleranceResult:
|
||||
raise NotImplementedError
|
||||
|
||||
async def get_status(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class InprocClient(EngineCoreClient):
|
||||
"""
|
||||
@@ -971,6 +986,14 @@ class AsyncMPClient(MPClient):
|
||||
self.client_count = client_count
|
||||
self.client_index = client_index
|
||||
self.outputs_queue = asyncio.Queue[EngineCoreOutputs | Exception]()
|
||||
|
||||
# locally-cached engine status
|
||||
self._engine_status: dict[int, dict] = {}
|
||||
if self.vllm_config.parallel_config.enable_fault_tolerance:
|
||||
self._engine_status = {
|
||||
rank: {"id": rank, "status": "healthy"}
|
||||
for rank in self.engine_ranks_managed
|
||||
}
|
||||
try:
|
||||
# If we are running in an asyncio event loop, start the queue task.
|
||||
# Otherwise, it will be started lazily. If it is not started here,
|
||||
@@ -994,7 +1017,7 @@ class AsyncMPClient(MPClient):
|
||||
output_handler: (
|
||||
Callable[[AsyncMPClient, EngineCoreOutputs], Awaitable[None]] | None
|
||||
) = getattr(self.__class__, "process_engine_outputs", None)
|
||||
_self_ref = weakref.ref(self) if output_handler else None
|
||||
_self_ref = weakref.ref(self)
|
||||
output_socket = resources.output_socket
|
||||
assert output_socket is not None
|
||||
|
||||
@@ -1025,6 +1048,14 @@ class AsyncMPClient(MPClient):
|
||||
asyncio.create_task(
|
||||
notification_callback_handler(_self, notification_data)
|
||||
)
|
||||
elif outputs.utility_output.call_id == FT_STATUS_CALL_ID:
|
||||
_self = _self_ref()
|
||||
if not _self:
|
||||
return
|
||||
if outputs.utility_output.result is not None:
|
||||
_self._engine_status[outputs.engine_index] = (
|
||||
outputs.utility_output.result.result
|
||||
)
|
||||
else:
|
||||
_process_utility_output(
|
||||
outputs.utility_output, utility_results
|
||||
@@ -1196,6 +1227,25 @@ class AsyncMPClient(MPClient):
|
||||
"collective_rpc", method, timeout, args, kwargs
|
||||
)
|
||||
|
||||
async def handle_fault(
|
||||
self, ft_request: FaultToleranceRequest
|
||||
) -> FaultToleranceResult:
|
||||
res = await self.call_utility_async(FT_UTILITY_METHOD, ft_request)
|
||||
result = msgspec.convert(res, FaultToleranceResult)
|
||||
if not result.success:
|
||||
status = self._engine_status.get(self.engine_ranks_managed[0])
|
||||
if status is not None:
|
||||
status["last_ft_request_id"] = result.request_id
|
||||
status["ft_error"] = result.reason
|
||||
return result
|
||||
|
||||
async def get_status(self):
|
||||
return {
|
||||
"schema_version": 1,
|
||||
"total_engines": len(self.engine_ranks_managed),
|
||||
"engines": list(self._engine_status.values()),
|
||||
}
|
||||
|
||||
|
||||
class DPAsyncMPClient(AsyncMPClient):
|
||||
"""Asyncio-compatible client for multi-proc, multi-engine (data parallel)
|
||||
|
||||
@@ -234,9 +234,6 @@ class CoreEngineProcManager:
|
||||
if exitcode != 0 and not self.manager_stopped.is_set():
|
||||
self.failed_proc_name = proc.name
|
||||
if died_sentinels:
|
||||
# Any engine exit currently triggers a shutdown. Future
|
||||
# work (e.g., Elastic and fault-tolerant EP) will add finer-grained
|
||||
# handling for different exit scenarios.
|
||||
break
|
||||
|
||||
self.shutdown()
|
||||
|
||||
Reference in New Issue
Block a user