-
Notifications
You must be signed in to change notification settings - Fork 262
Nixl weight transfer #2326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
S1ro1
wants to merge
14
commits into
main
Choose a base branch
from
nixl-weight-transfer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Nixl weight transfer #2326
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4a7a6dd
Initial
S1ro1 f270cac
Feat: Cleanup
S1ro1 cd3a565
Clean up GLM MoE DSA converter + NIXL broadcast
S1ro1 612429f
Feat: some cleanup
S1ro1 bec06a0
Feat: cleanup more
S1ro1 459f19f
wtf did claude cook
S1ro1 690dc4a
Feat: NIXL broadcast working end-to-end on GLM-5.1 (12-node disagg)
S1ro1 0d49320
Feat: hard-override UCX_NET_DEVICES in pin_ucx_rail
S1ro1 18b39fe
Feat: NIXL weight transfer now works with expandable_segments=True
S1ro1 5ea1051
Feat: ConversionSpec + QuantizationSpec, doc, fix tilelang preload
S1ro1 ea791f8
Feat: TransportPlan + Slot refactor, drop FP8 NCCL quantize path
S1ro1 90c4dc4
Docs: NIXL architecture contract + drop stale fixtures
S1ro1 e78fa10
Docs: rewrite nixl-weight-broadcast.md as a system contract
S1ro1 ed71964
Docs: drop nixl-architecture.md, superseded by contract rewrite
S1ro1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """vLLM worker extension that receives weight updates over NIXL. | ||
|
|
||
| Registers every vLLM parameter + weight-scale buffer with NIXL and publishes | ||
| ``(ptr, nbytes, device)`` per tensor. The trainer builds its own remote | ||
| descriptors at the right byte offsets — this side doesn't need to know the | ||
| per-source layout, so one ``all_gather_obj`` round is enough. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| import torch | ||
| from torch.nn import Module | ||
| from vllm.distributed.utils import StatelessProcessGroup | ||
| from vllm.logger import init_logger | ||
|
|
||
| from prime_rl.inference.vllm.worker.weight_transfer import build_expert_map, update_mla_absorbed_weights | ||
| from prime_rl.utils.nixl_transfer import NixlAgentWrapper, make_agent_name | ||
|
|
||
| if TYPE_CHECKING: | ||
| from vllm.v1.worker.gpu_worker import Worker # noqa: F401 | ||
|
|
||
| Worker = Worker # type: ignore | ||
| else: | ||
| Worker = object # type: ignore | ||
|
|
||
| logger = init_logger("vllm.inference.vllm.worker_nixl") | ||
|
|
||
|
|
||
| class NIXLWeightUpdateWorker(Worker): | ||
| """vLLM worker extension for in-place weight updates over NIXL.""" | ||
|
|
||
| def init_nixl_transfer( | ||
| self, | ||
| host: str, | ||
| port: int, | ||
| rank_offset: int, | ||
| trainer_world_size: int, | ||
| inference_world_size: int, | ||
| timeout: int, | ||
| backends: list[str], | ||
| ) -> None: | ||
| local_rank = self.device.index | ||
| global_rank = trainer_world_size + rank_offset + local_rank | ||
| full_world_size = trainer_world_size + inference_world_size | ||
|
|
||
| logger.info( | ||
| f"Initializing NIXL transfer: local_rank={local_rank} rank_offset={rank_offset} " | ||
| f"global_rank={global_rank} trainer_ws={trainer_world_size} inference_ws={inference_world_size}" | ||
| ) | ||
|
|
||
| model_runner = self.model_runner | ||
| model = model_runner.model.runnable if hasattr(model_runner.model, "runnable") else model_runner.model | ||
| assert isinstance(model, Module) | ||
| self._model = model | ||
|
|
||
| self._agent = NixlAgentWrapper( | ||
| name=make_agent_name("inference", global_rank), | ||
| local_rank=local_rank, | ||
| backends=backends, | ||
| ) | ||
|
|
||
| tensor_ptrs: dict[str, tuple[int, int, int]] = {} | ||
|
|
||
| def _register(name: str, tensor: torch.Tensor) -> None: | ||
| contig = tensor.contiguous() | ||
| self._agent.register_tensor(contig) | ||
| tensor_ptrs[name] = (contig.data_ptr(), contig.numel() * contig.element_size(), contig.get_device()) | ||
|
|
||
| for name, param in model.named_parameters(): | ||
| _register(name, param.data) | ||
| for name, buf in model.named_buffers(): | ||
| if name in tensor_ptrs or not name.endswith("_weight_scale_inv"): | ||
| continue | ||
| _register(name, buf) | ||
|
|
||
| expert_map = {k: v.cpu().tolist() for k, v in build_expert_map(model).items()} | ||
|
|
||
| self._spg = StatelessProcessGroup.create( | ||
| host=host, | ||
| port=port, | ||
| rank=global_rank, | ||
| world_size=full_world_size, | ||
| store_timeout=timeout, | ||
| ) | ||
| gathered = self._spg.all_gather_obj( | ||
| { | ||
| "role": "inference", | ||
| "global_rank": global_rank, | ||
| "agent_name": self._agent.name, | ||
| "agent_metadata": self._agent.get_metadata(), | ||
| "tensor_ptrs": tensor_ptrs, | ||
| "expert_map": expert_map, | ||
| } | ||
| ) | ||
| for peer in gathered[:trainer_world_size]: | ||
| self._agent.add_remote(peer["agent_metadata"]) | ||
|
|
||
| logger.info( | ||
| f"NIXL transfer ready: registered {len(tensor_ptrs)} tensors, " | ||
| f"added {trainer_world_size} trainer peers" | ||
| ) | ||
|
|
||
| @torch.no_grad() | ||
| def update_weights_from_path(self, weight_dir: str | None = None) -> None: | ||
| if not hasattr(self, "_spg"): | ||
| raise RuntimeError("NIXL transfer not initialized — call /init_nixl_transfer first") | ||
| self._spg.barrier() | ||
| update_mla_absorbed_weights(self._model) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.