-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(sglang): disagg DP rank routing + backwards-compatible network imports #6736
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e3f9ee1
feat: pass data_parallel_rank to prefill handler for disagg DP routing
ishandhanani 7416afd
Merge branch 'main' into idhanani/disagg-dp-rank-routing
ishandhanani e0131ac
fix(sglang): import get_local_ip_auto from network
ishandhanani eed64bf
fix(sglang): use current network utilities
ishandhanani 0e24a98
Merge branch 'main' into idhanani/disagg-dp-rank-routing
ishandhanani f572cda
fix(sglang): backwards-compatible network imports via _compat shim
ishandhanani 222ba83
docs(sglang): add N-1 deprecation policy to compat pattern
ishandhanani 016c28e
docs(sglang): generalize _compat.py docstring
ishandhanani 818b411
lint
ishandhanani b729ba1
fix: avoid always routing to dp_rank 0 in non-KV router mode
ishandhanani bb1a919
refactor: extract dp_rank sentinel to module-level constant
ishandhanani 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """ | ||
| Compatibility shim for SGLang internal APIs. | ||
|
|
||
| SGLang is pre-1.0 and routinely moves, renames, or introduces APIs between | ||
| releases. This module is the single place where we handle those differences | ||
| so the rest of the component can import from here without version-specific | ||
| try/except blocks. | ||
|
|
||
| Policy: support current SGLang release + 1 version back (N and N-1). Each | ||
| fallback branch must document which version it covers and when it can be | ||
| removed. When the old version falls outside the support window, delete the | ||
| fallback and any associated polyfills. | ||
| """ | ||
|
|
||
| import ipaddress | ||
| import logging | ||
| import socket | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| try: | ||
| from sglang.srt.utils.network import ( # noqa: F401 | ||
| NetworkAddress, | ||
| get_local_ip_auto, | ||
| get_zmq_socket, | ||
| ) | ||
|
|
||
| _SGLANG_HAS_NETWORK_MODULE = True | ||
| except ImportError: | ||
| # Fallback for sglang <= 0.5.9. Remove when min supported version is 0.6.0+ | ||
| from sglang.srt.utils import ( # type: ignore[no-redef] # noqa: F401 | ||
| get_local_ip_auto, | ||
| get_zmq_socket, | ||
| ) | ||
|
|
||
| _SGLANG_HAS_NETWORK_MODULE = False | ||
| logger.info( | ||
| "sglang.srt.utils.network not found (sglang <= 0.5.9); " | ||
| "using compatibility shim for NetworkAddress" | ||
| ) | ||
|
|
||
| class NetworkAddress: # type: ignore[no-redef] | ||
| """Minimal polyfill for sglang.srt.utils.network.NetworkAddress.""" | ||
|
|
||
| def __init__(self, host: str, port: int) -> None: | ||
| self.host = host | ||
| self.port = port | ||
|
|
||
| @property | ||
| def is_ipv6(self) -> bool: | ||
| try: | ||
| ipaddress.IPv6Address(self.host) | ||
| return True | ||
| except ValueError: | ||
| return False | ||
|
|
||
| @classmethod | ||
| def parse(cls, addr: str) -> "NetworkAddress": | ||
| """Parse 'host:port', '[IPv6]:port', or bare host.""" | ||
| addr = addr.strip() | ||
| if addr.startswith("["): | ||
| end = addr.find("]") | ||
| host = addr[1:end] if end != -1 else addr.strip("[]") | ||
| rest = addr[end + 1 :] if end != -1 else "" | ||
| if rest.startswith(":") and rest[1:].isdigit(): | ||
| return cls(host, int(rest[1:])) | ||
| return cls(host, 0) | ||
| if addr.count(":") == 1: | ||
| host_part, port_part = addr.rsplit(":", 1) | ||
| if port_part.isdigit(): | ||
| return cls(host_part, int(port_part)) | ||
| return cls(addr, 0) | ||
|
|
||
| def resolved(self) -> "NetworkAddress": | ||
| """DNS-resolve the host, preserving port.""" | ||
| try: | ||
| infos = socket.getaddrinfo( | ||
| self.host, None, family=socket.AF_UNSPEC, type=socket.SOCK_STREAM | ||
| ) | ||
| resolved_ip = infos[0][4][0] | ||
| return NetworkAddress(resolved_ip, self.port) | ||
| except socket.gaierror: | ||
| return self | ||
|
|
||
| def to_host_port_str(self) -> str: | ||
| """Return '[IPv6]:port' or 'host:port'.""" | ||
| if self.is_ipv6: | ||
| return f"[{self.host}]:{self.port}" | ||
| return f"{self.host}:{self.port}" | ||
|
|
||
| def to_tcp(self) -> str: | ||
| """Return 'tcp://[IPv6]:port' or 'tcp://host:port'.""" | ||
| if self.is_ipv6: | ||
| return f"tcp://[{self.host}]:{self.port}" | ||
| return f"tcp://{self.host}:{self.port}" | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "NetworkAddress", | ||
| "get_local_ip_auto", | ||
| "get_zmq_socket", | ||
| "_SGLANG_HAS_NETWORK_MODULE", | ||
| ] |
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
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.