[RL] Release weight-transfer communicators without stopping inference (#61060)

Signed-off-by: aoshen02 <aoshen@inferact.ai>
Signed-off-by: fh3 <a@b>
This commit is contained in:
aoshen02
2026-10-11 21:15:14 +08:00
committed by GitHub
parent c85616efc6
commit bd5bbce6e4
22 changed files with 181 additions and 14 deletions
+1 -3
View File
@@ -514,9 +514,7 @@ class WeightTransferEngine(ABC, Generic[TInitInfo, TUpdateInfo]):
@abstractmethod
def shutdown(self) -> None:
"""Shutdown the weight transfer engine.
This should be called when the worker is shutting down.
"""
"""Release transfer resources without shutting down the inference worker."""
raise NotImplementedError
+9 -1
View File
@@ -60,7 +60,7 @@ class HTTPVLLMWeightSyncClient:
Mirrors `vllm/entrypoints/rl/online/api_router.py`:
`/init_weight_transfer_engine`, `/start_weight_update`, `/update_weights`,
`/finish_weight_update`.
`/finish_weight_update`, `/shutdown_weight_transfer_engine`.
"""
def __init__(self, base_url: str, timeout: float = 300) -> None:
@@ -78,6 +78,9 @@ class HTTPVLLMWeightSyncClient:
def init_weight_transfer_engine(self, init_info: dict[str, Any]) -> None:
self._post("init_weight_transfer_engine", {"init_info": init_info})
def shutdown_weight_transfer_engine(self) -> None:
self._post("shutdown_weight_transfer_engine")
def start_weight_update(self) -> None:
self._post("start_weight_update")
@@ -109,6 +112,11 @@ class RayVLLMWeightSyncClient:
request = WeightTransferInitRequest(init_info=init_info)
ray.get([h.init_weight_transfer_engine.remote(request) for h in self.handles])
def shutdown_weight_transfer_engine(self) -> None:
import ray
ray.get([h.shutdown_weight_transfer_engine.remote() for h in self.handles])
def start_weight_update(self) -> None:
import ray
@@ -449,5 +449,7 @@ class M2NWeightTransferEngine(
torch.accelerator.synchronize()
self._handle.destroy()
self._handle = None
self.model_update_group = None
if self.model_update_group is not None:
self.model_update_group.destroy()
self.model_update_group = None
self._parameter_destinations = []
@@ -410,4 +410,6 @@ class M2NTrainerWeightTransferEngine(TrainerWeightTransferEngine[M2NTrainerInitI
if self._executor is not None:
self._executor.shutdown()
self._executor = None
self.group = None
if self.group is not None:
self.group.destroy()
self.group = None
@@ -229,7 +229,7 @@ class NCCLWeightTransferEngine(
def shutdown(self) -> None:
if self.model_update_group is not None:
# Clean up the communicator by removing the reference
self.model_update_group.destroy()
self.model_update_group = None
@@ -456,4 +456,6 @@ class NCCLTrainerWeightTransferEngine(TrainerWeightTransferEngine[NCCLTrainerIni
torch.cuda.current_stream().synchronize()
def shutdown(self) -> None:
self.model_update_group = None
if self.model_update_group is not None:
self.model_update_group.destroy()
self.model_update_group = None
@@ -186,6 +186,7 @@ class SparseNCCLWeightTransferEngine(
def shutdown(self) -> None:
if self.model_update_group is not None:
self.model_update_group.destroy()
self.model_update_group = None
@@ -371,4 +372,6 @@ class SparseNCCLTrainerWeightTransferEngine(
torch.cuda.current_stream().synchronize()
def shutdown(self) -> None:
self.model_update_group = None
if self.model_update_group is not None:
self.model_update_group.destroy()
self.model_update_group = None
+4
View File
@@ -296,6 +296,10 @@ class EngineClient(ABC):
"""Initialize weight transfer for RL training."""
raise NotImplementedError
async def shutdown_weight_transfer_engine(self) -> None:
"""Release the trainer connection without shutting down inference."""
raise NotImplementedError
async def start_weight_update(self) -> None:
"""Start a new weight update."""
raise NotImplementedError
+4
View File
@@ -26,6 +26,10 @@ class RLOfflineMixin(OfflineInferenceMixin):
"init_weight_transfer_engine", kwargs={"init_info": init_info_dict}
)
def shutdown_weight_transfer_engine(self) -> None:
"""Release the trainer connection without shutting down inference."""
self.llm_engine.collective_rpc("shutdown_weight_transfer_engine")
def start_weight_update(self) -> None:
"""Start a new weight update."""
self.llm_engine.collective_rpc("start_weight_update")
+7
View File
@@ -168,6 +168,13 @@ async def init_weight_transfer_engine(
return JSONResponse(content={"message": "Weight transfer initialized"})
@router.post("/shutdown_weight_transfer_engine")
async def shutdown_weight_transfer_engine(raw_request: Request):
with weight_operation_metrics().record("shutdown"):
await engine_client(raw_request).shutdown_weight_transfer_engine()
return JSONResponse(content={"message": "Weight transfer shut down"})
@router.post("/start_weight_update")
async def start_weight_update(raw_request: Request):
with weight_operation_metrics().record("start"):
+1 -1
View File
@@ -10,7 +10,7 @@ from typing import Literal
from prometheus_client import REGISTRY, CollectorRegistry, Gauge, Histogram
Operation = Literal["init", "start", "start_draft", "update", "finish"]
Operation = Literal["init", "shutdown", "start", "start_draft", "update", "finish"]
class WeightOperationMetrics:
+4
View File
@@ -1318,6 +1318,10 @@ class AsyncLLM(EngineClient):
"init_weight_transfer_engine", kwargs={"init_info": request.init_info}
)
async def shutdown_weight_transfer_engine(self) -> None:
"""Release the trainer connection without shutting down inference."""
await self.collective_rpc("shutdown_weight_transfer_engine")
async def start_weight_update(self) -> None:
"""Start a new weight update."""
await self.collective_rpc("start_weight_update")
+9
View File
@@ -1482,6 +1482,15 @@ class Worker(WorkerBase):
typed_init_info = self.weight_transfer_engine.parse_init_info(init_info)
self.weight_transfer_engine.init_transfer_engine(typed_init_info)
def shutdown_weight_transfer_engine(self) -> None:
"""Release a trainer connection without shutting down inference."""
if self._weight_update_active:
raise RuntimeError(
"Cannot release a trainer connection during a weight update"
)
if self.weight_transfer_engine is not None:
self.weight_transfer_engine.shutdown()
def start_weight_update(self) -> None:
"""Start a new weight update session.