Skip to content

support disaggregated weight update#4638

Open
irexyc wants to merge 3 commits into
InternLM:mainfrom
irexyc:xtuner-disaggregated
Open

support disaggregated weight update#4638
irexyc wants to merge 3 commits into
InternLM:mainfrom
irexyc:xtuner-disaggregated

Conversation

@irexyc

@irexyc irexyc commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a disaggregated weight-update path to the PyTorch backend, allowing an external RL trainer to broadcast updated model weights into a running rollout engine via a dedicated NCCL process group (init / update / destroy lifecycle), and threads it through the engine, executors, model agent, and OpenAI HTTP API.

Changes:

  • New OpenAI-compatible HTTP endpoints /init_weights_update_group, /update_weights_from_distributed, /destroy_weights_update_group (PyTorch backend only) and matching pydantic request models.
  • New init_weights_update_group / update_weights_from_distributed / destroy_weights_update_group methods plumbed from Engine → executor (base worker, ray executor) → BaseModelAgent, plus equivalents in the MP engine path.
  • Adds init_custom_process_group helper in lmdeploy/utils.py (copied from XTuner) that creates a non-default-world NCCL group, including PyTorch ≥ 2.6 backend_options compatibility.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lmdeploy/utils.py Adds init_custom_process_group helper to create a custom NCCL PG outside the default world.
lmdeploy/serve/openai/protocol.py New request schemas for init/update/destroy disaggregated weight-update endpoints.
lmdeploy/serve/openai/api_server.py Registers the three new endpoints with a PyTorch-backend-only guard.
lmdeploy/pytorch/engine/engine.py Forwards the three new operations to the executor.
lmdeploy/pytorch/engine/executor/base_worker.py Forwards calls to the model agent.
lmdeploy/pytorch/engine/executor/ray_executor.py Implements collective_rpc dispatch and a shared _reduce_worker_status reducer.
lmdeploy/pytorch/engine/model_agent/agent.py Core implementation: per-name PG dict, NCCL broadcast receive, main/draft split, finalization & graph reset.
lmdeploy/pytorch/engine/mp_engine/base.py MPEngine wrappers for the three new methods.
lmdeploy/pytorch/engine/mp_engine/base_worker.py MP engine worker delegates to underlying engine.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +501 to 503



Comment on lines +1217 to +1221
if request.names:
named_tensors = []
for name, dtype_str, shape in zip(request.names, request.dtypes, request.shapes):
target_dtype = getattr(torch, dtype_str) if isinstance(dtype_str, str) else dtype_str
named_tensors.append((name, torch.empty(shape, dtype=target_dtype, device=device)))
Comment on lines +1277 to +1287
group_name = request.group_name
pg = self._model_update_group.pop(group_name, None)
if pg is None:
return False, f'group {group_name!r} not initialized'
try:
dist.destroy_process_group(pg)
return True, f'Succeeded to destroy group {group_name!r}.'
except Exception as e:
msg = f'Failed to destroy weights update group {group_name!r}: {e}'
logger.exception(msg)
return False, msg
@lvhan028 lvhan028 added enhancement New feature or request planned feature and removed enhancement New feature or request labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants