[Elastic EP] Async preparation (#47288)

Signed-off-by: Itay Alroy <ialroy@nvidia.com>
This commit is contained in:
Itay Alroy
2026-07-28 05:19:13 -07:00
committed by GitHub
parent d2bfc6fe20
commit 35efdf6b34
21 changed files with 701 additions and 677 deletions
-2
View File
@@ -35,8 +35,6 @@ FT_STATUS_CALL_ID = -2
class EEPNotificationType(enum.Enum):
NEW_CORE_ENGINES_INIT_READY = "NEW_CORE_ENGINES_INIT_READY"
NEW_CORE_ENGINES_WEIGHTS_INIT_READY = "NEW_CORE_ENGINES_WEIGHTS_INIT_READY"
RECONFIGURE_FINISHED = "RECONFIGURE_FINISHED"
SHUTDOWN_COMPLETE = "SHUTDOWN_COMPLETE"
+26 -19
View File
@@ -109,6 +109,7 @@ class AsyncLLM(EngineClient):
maybe_register_config_serialize_by_value()
self.vllm_config = vllm_config
self._elastic_ep_lock = asyncio.Lock()
self.model_config = vllm_config.model_config
self.observability_config = vllm_config.observability_config
@@ -998,17 +999,27 @@ class AsyncLLM(EngineClient):
"waiting for requests to drain."
)
async def _drain_requests_for_elastic_ep(self, drain_timeout: int) -> None:
try:
logger.info(
"VLLM_ELASTIC_EP_DRAIN_REQUESTS is set, "
"waiting for requests to drain before scaling"
)
await self.wait_for_requests_to_drain(drain_timeout)
except BaseException:
set_scaling_elastic_ep(False)
raise
async def scale_elastic_ep(
self, new_data_parallel_size: int, drain_timeout: int = 300
):
"""
Scale up or down the data parallel size by adding or removing
engine cores.
Args:
new_data_parallel_size: The new number of data parallel workers
drain_timeout:
Maximum time to wait for requests to drain (seconds)
"""
"""Scale the elastic EP data parallel size."""
async with self._elastic_ep_lock:
await self._scale_elastic_ep(new_data_parallel_size, drain_timeout)
async def _scale_elastic_ep(
self, new_data_parallel_size: int, drain_timeout: int
) -> None:
old_data_parallel_size = self.vllm_config.parallel_config.data_parallel_size
if old_data_parallel_size == new_data_parallel_size:
logger.info(
@@ -1017,12 +1028,7 @@ class AsyncLLM(EngineClient):
)
return
if envs.VLLM_ELASTIC_EP_DRAIN_REQUESTS:
logger.info(
"VLLM_ELASTIC_EP_DRAIN_REQUESTS is set, "
"waiting for requests to drain before scaling"
)
await self.wait_for_requests_to_drain(drain_timeout)
await self.engine_core.prepare_elastic_ep(new_data_parallel_size)
# recreate stat loggers
if new_data_parallel_size > old_data_parallel_size and self.log_stats:
@@ -1042,11 +1048,12 @@ class AsyncLLM(EngineClient):
self.logger_manager.log_engine_initialized()
set_scaling_elastic_ep(True)
try:
await self.engine_core.scale_elastic_ep(new_data_parallel_size)
self.vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
finally:
set_scaling_elastic_ep(False)
if envs.VLLM_ELASTIC_EP_DRAIN_REQUESTS:
await self._drain_requests_for_elastic_ep(drain_timeout)
await self.engine_core.commit_elastic_ep()
self.vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
set_scaling_elastic_ep(False)
async def handle_fault(
self, fault_tolerance_request: FaultToleranceRequest
+3
View File
@@ -376,6 +376,9 @@ class DPCoordinatorProc:
eng_index = outputs.engine_index
scheduler_stats = outputs.scheduler_stats
if scheduler_stats:
# Elastic EP stats may arrive while the engine list changes.
if eng_index >= len(self.engines):
continue
# 1. Updated request load stats - update our local
# state with these.
stats = self.engines[eng_index].request_counts
+36 -39
View File
@@ -327,8 +327,9 @@ class EngineCore:
vllm_config.validate_block_size()
# Initialize kv cache and warmup the execution
self.model_executor.initialize_from_config(kv_cache_configs)
if not envs.VLLM_ELASTIC_EP_SCALE_UP_LAUNCH:
self.model_executor.compile_or_warm_up_model()
elapsed = time.time() - start
compile_time = vllm_config.compilation_config.compilation_time
@@ -993,9 +994,7 @@ class EngineCore:
raise NotImplementedError
def _eep_send_engine_core_notification(
self,
notification_type: EEPNotificationType,
vllm_config: VllmConfig | None = None,
self, notification_type: EEPNotificationType
):
raise NotImplementedError
@@ -1070,11 +1069,6 @@ class EngineCoreProc(EngineCore):
self.addresses = addresses
self.process_input_queue_block = True
if envs.VLLM_ELASTIC_EP_SCALE_UP_LAUNCH:
self._eep_send_engine_core_notification(
EEPNotificationType.NEW_CORE_ENGINES_INIT_READY,
vllm_config=vllm_config,
)
self._init_data_parallel(vllm_config)
super().__init__(
@@ -2096,12 +2090,16 @@ class DPEngineCoreProc(EngineCoreProc):
self._maybe_publish_request_counts()
if self.eep_scaling_state is not None:
_ = self.eep_scaling_state.progress()
if self.eep_scaling_state.is_complete():
if self.eep_scaling_state.worker_type == "removing":
state = self.eep_scaling_state
if state.commit_requested or not state.is_ready_for_switch():
state.progress()
if state.is_complete():
if state.worker_type == "removing":
raise SystemExit
self.process_input_queue_block = True
self.eep_scaling_state = None
elif not state.commit_requested and state.is_ready_for_switch():
self.process_input_queue_block = True
executed = self._process_engine_step()
self._maybe_publish_request_counts()
@@ -2171,7 +2169,7 @@ class DPEngineCoreProc(EngineCoreProc):
def reinitialize_distributed(
self, reconfig_request: ReconfigureDistributedRequest
) -> None:
) -> str:
from copy import deepcopy
from vllm.distributed.elastic_ep.elastic_state import ElasticEPScalingState
@@ -2203,7 +2201,10 @@ class DPEngineCoreProc(EngineCoreProc):
== ReconfigureRankType.SHUTDOWN_CURRENT_RANK
)
self.eep_scaling_state = ElasticEPScalingState(
if self.eep_scaling_state is not None:
raise RuntimeError("Elastic EP reconfiguration is already active")
state = ElasticEPScalingState(
model_executor=self.model_executor,
engine_core=self,
vllm_config=self.vllm_config,
@@ -2212,30 +2213,34 @@ class DPEngineCoreProc(EngineCoreProc):
scale_type="scale_down" if is_scale_down else "scale_up",
reconfig_request=reconfig_request,
)
self.eep_scaling_state = state
self.process_input_queue_block = False
logger.info(
"[Elastic EP] Received reconfiguration request and starting scaling up/down"
)
return state.ready_key
def commit_prepared_elastic_ep(self) -> None:
state = self.eep_scaling_state
if state is None or state.commit_requested or not state.is_ready_for_switch():
raise RuntimeError("No prepared Elastic EP reconfiguration is ready")
state.commit_requested = True
self.process_input_queue_block = False
logger.info("[Elastic EP] Committing prepared reconfiguration")
def _eep_send_engine_core_notification(
self,
notification_type: EEPNotificationType,
vllm_config: VllmConfig | None = None,
self, notification_type: EEPNotificationType
):
"""
Send notifications to EngineCoreClient, which can then forward
the notifications to other engine core processes. It is used for:
1) In scale up: new core engines to notify existing core engines
that they are ready;
2) In scale down: removing core engines to notify EngineCoreClient
1) In scale down: removing core engines to notify EngineCoreClient
so EngineCoreClient can release their ray placement groups;
3) Both scale up/down: to notify EngineCoreClient that existing
2) Both scale up/down: to notify EngineCoreClient that existing
core engines have already switched to the new parallel setup.
"""
if vllm_config is None:
dp_rank = self.vllm_config.parallel_config.data_parallel_rank
else:
dp_rank = vllm_config.parallel_config.data_parallel_rank
dp_rank = self.vllm_config.parallel_config.data_parallel_rank
notification_data = (notification_type.value, dp_rank)
outputs = EngineCoreOutputs(
utility_output=UtilityOutput(
@@ -2257,22 +2262,11 @@ class DPEngineCoreProc(EngineCoreProc):
):
socket.send_multipart(encoder.encode(outputs))
def eep_handle_engine_core_notification(
self, notification_type: str | EEPNotificationType
):
"""
Handle notification received from EngineCoreClient
(forwarded from new core engines).
"""
assert self.eep_scaling_state is not None
if isinstance(notification_type, str):
notification_type = EEPNotificationType(notification_type)
self.eep_scaling_state.handle_notification(notification_type)
def _eep_scale_up_before_kv_init(self):
from vllm.distributed.elastic_ep.elastic_state import ElasticEPScalingState
self.eep_scaling_state = ElasticEPScalingState(
self.ignore_start_dp_wave = True
state = ElasticEPScalingState(
model_executor=self.model_executor,
engine_core=self,
vllm_config=self.vllm_config,
@@ -2281,7 +2275,10 @@ class DPEngineCoreProc(EngineCoreProc):
scale_type="scale_up",
reconfig_request=None,
)
self.eep_scaling_state.run_pre_kv_init_states()
if self.eep_scaling_state is not None:
raise RuntimeError("Elastic EP reconfiguration is already active")
self.eep_scaling_state = state
state.run_pre_kv_init_states()
self.process_input_queue_block = False
+174 -136
View File
@@ -225,7 +225,10 @@ class EngineCoreClient(ABC):
running state."""
raise NotImplementedError
async def scale_elastic_ep(self, new_data_parallel_size: int) -> None:
async def commit_elastic_ep(self) -> None:
raise NotImplementedError
async def prepare_elastic_ep(self, new_data_parallel_size: int) -> None:
raise NotImplementedError
async def get_output_async(self) -> EngineCoreOutputs:
@@ -1490,6 +1493,7 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
)
assert len(self.core_engines) > 1
self._prepared_elastic_ep: tuple[int, int] | None = None
self.eng_start_index = (
len(self.core_engines) * self.client_index
@@ -1603,31 +1607,16 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
if len(cache.pending_notifications[notification_type]) >= abs(
cache.num_new_core_engines
):
if notification_type == EEPNotificationType.SHUTDOWN_COMPLETE:
assert isinstance(self.resources.engine_manager, CoreEngineActorManager)
assert cache.num_new_core_engines < 0
old_dp_size = len(cache.existing_core_engines)
new_dp_size = old_dp_size + cache.num_new_core_engines
self.resources.engine_manager.scale_down_elastic_ep(
old_dp_size, new_dp_size
)
else:
await asyncio.gather(
*[
self._call_utility_async(
"eep_handle_engine_core_notification",
notification_type,
engine=engine,
)
for engine in cache.existing_core_engines
]
)
cache.pending_notifications[notification_type] = set()
if notification_type in [
EEPNotificationType.SHUTDOWN_COMPLETE,
EEPNotificationType.NEW_CORE_ENGINES_WEIGHTS_INIT_READY,
]:
self.eep_scaling_cache = None
engine_manager = self.resources.engine_manager
assert isinstance(engine_manager, CoreEngineActorManager)
assert cache.num_new_core_engines < 0
old_dp_size = len(cache.existing_core_engines)
new_dp_size = old_dp_size + cache.num_new_core_engines
engine_manager.scale_down_elastic_ep(old_dp_size, new_dp_size)
self.vllm_config.parallel_config.data_parallel_size_local = len(
engine_manager.local_engine_actors
)
self.eep_scaling_cache = None
async def abort_requests_async(self, request_ids: list[str]) -> None:
if not request_ids or self.resources.engine_dead:
@@ -1651,31 +1640,46 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
) -> None:
await self._send_input(EngineCoreRequestType.ABORT, request_ids, engine)
async def scale_elastic_ep(self, new_data_parallel_size: int) -> None:
"""Scale elastic EP data parallel size"""
async def commit_elastic_ep(self) -> None:
"""Commit prepared elastic EP scaling."""
prepared = self._prepared_elastic_ep
if prepared is None:
raise RuntimeError("Elastic EP scaling has not been prepared")
new_data_parallel_size, num_redundant_experts = prepared
cur_data_parallel_size = len(self.core_engines)
assert new_data_parallel_size != cur_data_parallel_size, (
f"new_data_parallel_size {new_data_parallel_size} must be "
f"different from cur_data_parallel_size {cur_data_parallel_size}"
if new_data_parallel_size > cur_data_parallel_size:
await self._commit_scale_up_elastic_ep(new_data_parallel_size)
else:
await self._commit_scale_down_elastic_ep(new_data_parallel_size)
self.vllm_config.parallel_config.eplb_config.num_redundant_experts = (
num_redundant_experts
)
self._prepared_elastic_ep = None
async def prepare_elastic_ep(self, new_data_parallel_size: int) -> None:
"""Prepare elastic EP scaling without routing requests to new engines."""
if (prepared := self._prepared_elastic_ep) is not None:
if prepared[0] == new_data_parallel_size:
return
raise RuntimeError("Elastic EP scaling is already prepared")
cur_data_parallel_size = len(self.core_engines)
assert self.vllm_config.parallel_config.data_parallel_backend == "ray", (
"Only ray DP backend supports scaling elastic EP"
)
scale_up = new_data_parallel_size > cur_data_parallel_size
if scale_up:
await self._scale_up_elastic_ep(
cur_data_parallel_size, new_data_parallel_size
)
parallel_config = self.vllm_config.parallel_config
num_experts = self.vllm_config.model_config.get_num_experts()
num_redundant_experts = (
num_experts + parallel_config.eplb_config.num_redundant_experts
) * new_data_parallel_size // cur_data_parallel_size - num_experts
if new_data_parallel_size < cur_data_parallel_size:
await self._prepare_scale_down_elastic_ep(new_data_parallel_size)
else:
await self._scale_down_elastic_ep(
cur_data_parallel_size, new_data_parallel_size
await self._prepare_scale_up_elastic_ep(
new_data_parallel_size, num_redundant_experts
)
self._prepared_elastic_ep = new_data_parallel_size, num_redundant_experts
async def _eep_wait_for_setup_switch_complete(self) -> None:
def _eep_wait_for_setup_switch_complete(self) -> asyncio.Future:
"""
Wait for core engines to switch to the new setup.
@@ -1687,9 +1691,26 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
future = asyncio.get_running_loop().create_future()
self.utility_results[EEP_NOTIFICATION_CALL_ID] = future
self._ensure_output_queue_task()
await future
return future
def _setup_elastic_ep_reconfig_bootstrap(self) -> tuple[str, int]:
def _wait_for_new_engine_ready(self, new_core_engines: list[bytes]) -> None:
new_engine_identities = set(new_core_engines)
sync_input_socket = zmq.Socket.shadow(self.input_socket)
while new_engine_identities:
if not sync_input_socket.poll(timeout=VLLM_ENGINE_READY_TIMEOUT_S * 1000):
raise TimeoutError(
f"Timed out waiting for new engine core processes to "
f"start. Waited "
f"{VLLM_ENGINE_READY_TIMEOUT_S}s (configured by "
f"VLLM_ENGINE_READY_TIMEOUT_S). To increase the "
f"timeout, set the environment variable: "
f"VLLM_ENGINE_READY_TIMEOUT_S=<seconds>"
)
identity, payload = sync_input_socket.recv_multipart()
new_engine_identities.discard(identity)
self._apply_ready_response(payload)
def _setup_elastic_ep_reconfig_bootstrap(self) -> None:
from vllm.distributed.utils import create_tcp_store
from vllm.utils.network_utils import get_open_ports_list
@@ -1709,36 +1730,36 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
)
parallel_config._coord_store_port = store.port
self._coord_store = store
return ip, store.port
async def _scale_up_elastic_ep(
self, cur_data_parallel_size: int, new_data_parallel_size: int
) -> None:
"""Scale up the data parallel size by creating new engine cores
and reconfiguring existing ones."""
cur_data_parallel_size = len(self.core_engines)
self.eep_scaling_cache = ElasticScalingCache(
existing_core_engines=self.core_engines.copy(),
num_new_core_engines=new_data_parallel_size - cur_data_parallel_size,
pending_notifications=dict(),
def _make_reconfig_request(
self,
new_data_parallel_size: int,
rank_type: ReconfigureRankType = ReconfigureRankType.KEEP_CURRENT_RANK,
) -> ReconfigureDistributedRequest:
parallel_config = self.vllm_config.parallel_config
return ReconfigureDistributedRequest(
new_data_parallel_size=new_data_parallel_size,
new_data_parallel_rank=rank_type,
new_data_parallel_rank_local=ReconfigureRankType.KEEP_CURRENT_RANK,
new_data_parallel_master_ip=parallel_config.data_parallel_master_ip,
new_data_parallel_master_port=parallel_config.data_parallel_master_port,
new_data_parallel_master_port_list=parallel_config._data_parallel_master_port_list,
coord_store_port=parallel_config._coord_store_port,
)
parallel_config = self.vllm_config.parallel_config
ip, coord_store_port = self._setup_elastic_ep_reconfig_bootstrap()
async def _prepare_scale_up_elastic_ep(
self,
new_data_parallel_size: int,
num_redundant_experts: int,
) -> None:
"""Prepare scale up by creating new engine cores and reconfiguring
existing ones."""
self._setup_elastic_ep_reconfig_bootstrap()
# Phase 1: Send reconfig messages to existing engines
reconfig_futures = []
for engine in self.core_engines:
reconfig_request = ReconfigureDistributedRequest(
new_data_parallel_size=new_data_parallel_size,
new_data_parallel_rank=ReconfigureRankType.KEEP_CURRENT_RANK,
new_data_parallel_rank_local=ReconfigureRankType.KEEP_CURRENT_RANK,
new_data_parallel_master_ip=ip,
new_data_parallel_master_port=parallel_config.data_parallel_master_port,
new_data_parallel_master_port_list=parallel_config._data_parallel_master_port_list,
coord_store_port=coord_store_port,
)
reconfig_request = self._make_reconfig_request(new_data_parallel_size)
coro = self._call_utility_async(
"reinitialize_distributed", reconfig_request, engine=engine
)
@@ -1746,51 +1767,54 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
# Phase 2: Create new engines
assert isinstance(self.resources.engine_manager, CoreEngineActorManager)
parallel_config.eplb_config.num_redundant_experts = 0
start_new_worker_future = asyncio.to_thread(
self.resources.engine_manager.scale_up_elastic_ep,
self.vllm_config,
new_data_parallel_size,
num_redundant_experts,
)
wait_future = self._eep_wait_for_setup_switch_complete()
# Phase 3: Wait for new engines to be created
# and reconfig messages to be received
await asyncio.gather(start_new_worker_future, *reconfig_futures)
ready_keys = [future.result() for future in reconfig_futures]
ready_keys.extend(
f"eep_ready/{rank}"
for rank in range(len(self.core_engines), new_data_parallel_size)
)
await asyncio.to_thread(self._coord_store.wait, ready_keys)
logger.info("[Elastic EP] Successfully started new engines")
# Create new CoreEngine objects for the new engines
new_engine_identities = set()
for i in range(cur_data_parallel_size, new_data_parallel_size):
new_engine = i.to_bytes(2, "little")
self.core_engines.append(new_engine)
# NOTE(yongji): we don't update lb_engines here,
# we let run_engine_stats_update_task to update it.
new_engine_identities.add(new_engine)
async def _commit_scale_up_elastic_ep(self, new_data_parallel_size: int) -> None:
new_core_engines = [
rank.to_bytes(2, "little")
for rank in range(len(self.core_engines), new_data_parallel_size)
]
# Wait for ready messages from new engines on the input socket
sync_input_socket = zmq.Socket.shadow(self.input_socket)
while new_engine_identities:
if not sync_input_socket.poll(
timeout=VLLM_ENGINE_READY_TIMEOUT_S * 1000 # convert to ms
):
raise TimeoutError(
f"Timed out waiting for new engine core processes to "
f"start. Waited "
f"{VLLM_ENGINE_READY_TIMEOUT_S}s (configured by "
f"VLLM_ENGINE_READY_TIMEOUT_S). To increase the "
f"timeout, set the environment variable: "
f"VLLM_ENGINE_READY_TIMEOUT_S=<seconds>"
)
identity, payload = sync_input_socket.recv_multipart()
new_engine_identities.discard(identity)
self._apply_ready_response(payload)
await self.pause_scheduler_async(mode="keep", clear_cache=False)
wait_future = self._eep_wait_for_setup_switch_complete()
finish_futures = [
asyncio.create_task(
self._call_utility_async("commit_prepared_elastic_ep", engine=engine)
)
for engine in self.core_engines
]
try:
await asyncio.gather(*finish_futures)
await wait_future
self._wait_for_new_engine_ready(new_core_engines)
except Exception:
wait_future.cancel()
raise
# NOTE(yongji): Before we schedule any requests on the new workers,
# we should wait for them to switch to the new setup.
await wait_future
self.core_engines.extend(new_core_engines)
# Update the parallel config
self.vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
parallel_config = self.vllm_config.parallel_config
parallel_config.data_parallel_size = new_data_parallel_size
if isinstance(self.resources.engine_manager, CoreEngineActorManager):
parallel_config.data_parallel_size_local = len(
self.resources.engine_manager.local_engine_actors
)
# Notify coordinator about scale up through existing
# stats_update_task connection
self._ensure_stats_update_task()
@@ -1803,10 +1827,23 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
"[Elastic EP] Scale up completed, new data parallel size: %s",
new_data_parallel_size,
)
await self.resume_scheduler_async()
async def _scale_down_elastic_ep(
self, cur_data_parallel_size: int, new_data_parallel_size: int
) -> None:
async def _prepare_scale_down_elastic_ep(self, new_data_parallel_size: int) -> None:
self._setup_elastic_ep_reconfig_bootstrap()
reconfig_futures = []
for engine in self.core_engines[:new_data_parallel_size]:
reconfig_request = self._make_reconfig_request(new_data_parallel_size)
coro = self._call_utility_async(
"reinitialize_distributed", reconfig_request, engine=engine
)
reconfig_futures.append(asyncio.create_task(coro))
ready_keys = await asyncio.gather(*reconfig_futures)
await asyncio.to_thread(self._coord_store.wait, ready_keys)
async def _commit_scale_down_elastic_ep(self, new_data_parallel_size: int) -> None:
"""Scale down the data parallel size by shutting down and
reconfiguring existing engine cores."""
cur_data_parallel_size = len(self.core_engines)
@@ -1817,50 +1854,51 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
pending_notifications=dict(),
)
parallel_config = self.vllm_config.parallel_config
ip, coord_store_port = self._setup_elastic_ep_reconfig_bootstrap()
old_core_engines = self.core_engines
# NOTE(yongji): Immediately stop sending requests to the removing engines.
self.core_engines = old_core_engines[:new_data_parallel_size]
self.lb_engines = self.lb_engines[:new_data_parallel_size]
removed_dp_size = cur_data_parallel_size - new_data_parallel_size
pause_modes = ["keep"] * new_data_parallel_size + ["abort"] * removed_dp_size
pause_futures = [
self._call_utility_async("pause_scheduler", mode, False, engine=engine)
for mode, engine in zip(pause_modes, old_core_engines)
]
await asyncio.gather(*pause_futures)
assert isinstance(self.resources.engine_manager, CoreEngineActorManager)
self.resources.engine_manager.remove_run_refs_for_scale_down(removed_dp_size)
wait_future = self._eep_wait_for_setup_switch_complete()
reconfig_futures = []
for cur_dp_rank, engine in enumerate(self.core_engines):
reconfig_request = ReconfigureDistributedRequest(
new_data_parallel_size=new_data_parallel_size,
new_data_parallel_rank=ReconfigureRankType.KEEP_CURRENT_RANK,
new_data_parallel_rank_local=ReconfigureRankType.KEEP_CURRENT_RANK,
new_data_parallel_master_ip=ip,
new_data_parallel_master_port=parallel_config.data_parallel_master_port,
new_data_parallel_master_port_list=parallel_config._data_parallel_master_port_list,
coord_store_port=coord_store_port,
)
if cur_dp_rank >= new_data_parallel_size:
reconfig_request.new_data_parallel_rank = (
ReconfigureRankType.SHUTDOWN_CURRENT_RANK
for cur_dp_rank, engine in enumerate(old_core_engines):
if cur_dp_rank < new_data_parallel_size:
coro = self._call_utility_async(
"commit_prepared_elastic_ep", engine=engine
)
else:
reconfig_request = self._make_reconfig_request(
new_data_parallel_size,
ReconfigureRankType.SHUTDOWN_CURRENT_RANK,
)
coro = self._call_utility_async(
"reinitialize_distributed", reconfig_request, engine=engine
)
coro = self._call_utility_async(
"reinitialize_distributed", reconfig_request, engine=engine
)
reconfig_futures.append(asyncio.create_task(coro))
# NOTE(yongji): Immediately stop sending requests to the removing engines.
self.core_engines = self.core_engines[:new_data_parallel_size]
self.lb_engines = self.lb_engines[:new_data_parallel_size]
wait_future = self._eep_wait_for_setup_switch_complete()
try:
await asyncio.gather(*reconfig_futures)
await asyncio.gather(*reconfig_futures)
self.vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
self._ensure_stats_update_task()
scale_down_marker = msgspec.msgpack.encode(
("SCALE_ELASTIC_EP", new_data_parallel_size)
)
await self.first_req_send_socket.send(scale_down_marker)
await wait_future
await self.resume_scheduler_async()
except Exception:
wait_future.cancel()
raise
self.vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
self._ensure_stats_update_task()
scale_down_marker = msgspec.msgpack.encode(
("SCALE_ELASTIC_EP", new_data_parallel_size)
)
await self.first_req_send_socket.send(scale_down_marker)
# NOTE(yongji): Unlike scaling up,
# here we don't actually need to wait for the setup switch to complete.
# We may want to remove it in the future.
await wait_future
logger.info(
"[Elastic EP] Scale down completed, new data parallel size: %s",
new_data_parallel_size,
+8 -23
View File
@@ -821,7 +821,10 @@ class CoreEngineActorManager:
return placement_groups, local_dp_ranks
def scale_up_elastic_ep(
self, cur_vllm_config: VllmConfig, new_data_parallel_size: int
self,
cur_vllm_config: VllmConfig,
new_data_parallel_size: int,
num_redundant_experts: int,
) -> None:
import copy
@@ -864,6 +867,9 @@ class CoreEngineActorManager:
if new_data_parallel_size > 1:
_apply_dp_identity_suffix(dp_vllm_config, rank)
dp_vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
dp_vllm_config.parallel_config.eplb_config.num_redundant_experts = (
num_redundant_experts
)
dp_vllm_config.parallel_config.placement_group = pg
# Check if this placement group is on the head node
@@ -906,39 +912,18 @@ class CoreEngineActorManager:
self.created_placement_groups.append(pg)
self.placement_group_is_local.append(local_client)
ray.get(
[
actor.wait_for_init.remote()
for actor in (
self.local_engine_actors[-new_local_engines:]
if new_local_engines > 0
else []
)
+ self.remote_engine_actors[
-(len(placement_groups) - new_local_engines) :
]
]
)
actors = (
self.local_engine_actors[-new_local_engines:]
if new_local_engines > 0
else []
) + self.remote_engine_actors[-(len(placement_groups) - new_local_engines) :]
ray.get([actor.wait_for_init.remote() for actor in actors])
for actor in actors:
ref = actor.run.remote()
self.run_refs.append(ref)
self.actor_run_ref_dict[actor] = ref
cur_vllm_config.parallel_config.data_parallel_size = new_data_parallel_size
# Update old_vllm_config with new data_parallel_size_local if any new
# local engines were added
if new_local_engines > 0:
cur_vllm_config.parallel_config.data_parallel_size_local += (
new_local_engines
)
def scale_down_elastic_ep(
self, cur_data_parallel_size: int, new_data_parallel_size: int
) -> None: