Weight sync refactor + move sparse nccl engine (#44353)

Signed-off-by: hao-aaron <ahao@anyscale.com>
Signed-off-by: haoaaron <ahao@anyscale.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aaron Hao
2026-07-01 01:25:19 -07:00
committed by GitHub
co-authored by Claude Sonnet 4.6
parent f651a8a9a4
commit 77a9c5ae28
32 changed files with 951 additions and 1044 deletions
+14 -81
View File
@@ -155,7 +155,6 @@ class Worker(WorkerBase):
# is available, since the engine needs a reference to the model.
self.weight_transfer_engine: WeightTransferEngine | None = None
self._weight_update_active = False
self._is_checkpoint_format = True
# Torch/CUDA profiler. Enabled and configured through profiler_config.
# Profiler wrapper is created lazily in profile() when start is called,
@@ -416,7 +415,8 @@ class Worker(WorkerBase):
if self.vllm_config.weight_transfer_config is not None:
self.weight_transfer_engine = WeightTransferEngineFactory.create_engine(
self.vllm_config.weight_transfer_config,
self.vllm_config.parallel_config,
self.vllm_config,
self.device,
self.model_runner.get_model(),
)
@@ -1161,16 +1161,16 @@ 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 start_weight_update(self, is_checkpoint_format: bool = True) -> None:
def start_weight_update(self) -> None:
"""
Start a new weight update session.
Args:
is_checkpoint_format: Whether incoming weights are in checkpoint
format (need layerwise processing) or kernel format (direct
copy / sparse patch application).
Delegates engine-specific preparation (e.g. layerwise reload setup) to
the configured weight transfer engine. The worker only tracks that a
session is active.
"""
self._check_weight_transfer_engine()
assert self.weight_transfer_engine is not None
if self._weight_update_active:
raise RuntimeError(
@@ -1178,16 +1178,7 @@ class Worker(WorkerBase):
"active. Call finish_weight_update first."
)
if is_checkpoint_format:
from vllm.model_executor.model_loader.reload import (
initialize_layerwise_reload,
)
model = self.model_runner.model
with torch.device(self.device):
initialize_layerwise_reload(model)
self._is_checkpoint_format = is_checkpoint_format
self.weight_transfer_engine.start_weight_update()
self._weight_update_active = True
def update_weights(self, update_info: dict) -> None:
@@ -1208,82 +1199,24 @@ class Worker(WorkerBase):
"start_weight_update must be called before update_weights."
)
update_succeeded = False
try:
# Parse dict into backend-specific typed dataclass
typed_update_info = self.weight_transfer_engine.parse_update_info(
update_info
)
with torch.device(self.device):
if self._is_checkpoint_format:
if typed_update_info.update_kind != "dense":
raise ValueError(
"Sparse weight updates require "
"`start_weight_update(is_checkpoint_format=False)`."
)
model = self.model_runner.model
# Use layerwise reload pattern for checkpoint format weights
self.weight_transfer_engine.receive_weights(
typed_update_info,
load_weights=model.load_weights,
)
elif typed_update_info.update_kind == "sparse_flat":
if self.parallel_config.world_size != 1:
raise NotImplementedError(
"Sparse weight updates currently require TP=1 and PP=1"
)
self.weight_transfer_engine.receive_sparse_weights(
typed_update_info,
apply_patches=self.model_runner.apply_sparse_weight_patches,
)
else:
model = self.model_runner.model
# Weights are already in kernel format, copy directly.
def load_weights_direct(
weights: list[tuple[str, torch.Tensor]],
) -> None:
for name, weight in weights:
param = model.get_parameter(name)
param.copy_(weight)
self.weight_transfer_engine.receive_weights(
typed_update_info,
load_weights=load_weights_direct,
)
# NCCL broadcast/packed path are asynchronous.
# Sync here so the next step uses the new weights.
torch.accelerator.synchronize()
update_succeeded = True
finally:
if not update_succeeded:
self._weight_update_active = False
self._is_checkpoint_format = True
self.weight_transfer_engine.update_weights(update_info)
except BaseException:
self._weight_update_active = False
raise
def finish_weight_update(self) -> None:
"""Finish the current weight update session."""
self._check_weight_transfer_engine()
assert self.weight_transfer_engine is not None
if not self._weight_update_active:
raise RuntimeError(
"finish_weight_update called without a matching start_weight_update."
)
if self._is_checkpoint_format:
from vllm.model_executor.model_loader.reload import (
finalize_layerwise_reload,
)
model = self.model_runner.model
with torch.device(self.device):
finalize_layerwise_reload(model, self.model_config)
self.weight_transfer_engine.finish_weight_update()
self._weight_update_active = False
self._is_checkpoint_format = True
def shutdown(self) -> None:
gc.unfreeze()