-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ci] fix: occasional CI failures caused by sglang server port conflicts #5310
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
pengwu22
wants to merge
8
commits into
verl-project:main
Choose a base branch
from
pengwu22:pw/fix-ci-0212
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8cf7bc1
fix
pengwu22 3bba691
fix2
pengwu22 0178383
backward compat
pengwu22 99ecff5
closing it
pengwu22 dcd3e12
no replica rank only pid
pengwu22 e213554
remove unnecessary comments
pengwu22 a0f2fe7
resolve comments
pengwu22 5163338
let sglang handle nnodes=1
pengwu22 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 |
|---|---|---|
|
|
@@ -123,17 +123,19 @@ def __init__( | |
| profiler_config = None | ||
| self.profiler_controller = DistProfiler(self.replica_rank, config=profiler_config, tool_config=tool_config) | ||
|
|
||
| # used for NCCL process group | ||
| if self.node_rank == 0: | ||
| # For multi-node, we need dist_init_addr so nodes can coordinate NCCL init. | ||
| # For single-node, let SGLang handle port selection internally via nccl_port, | ||
| # which also avoids port conflicts. | ||
| self._master_address = None | ||
| self._master_port = None | ||
| self._master_sock = None | ||
| if self.nnodes > 1 and self.node_rank == 0: | ||
| self._master_address = self._server_address | ||
| self._master_port, self._master_sock = get_free_port(self._server_address) | ||
| self._master_port, self._master_sock = get_free_port(self._server_address, with_alive_sock=True) | ||
| logger.info( | ||
| f"SGLangHttpServer, replica_rank: {self.replica_rank}, " | ||
| f"master address: {self._master_address}, port: {self._master_port}" | ||
| ) | ||
| else: | ||
| self._master_address = None | ||
| self._master_port = None | ||
|
|
||
| def get_master_address(self): | ||
| """Get master address and port for init NCCL process group.""" | ||
|
|
@@ -145,10 +147,13 @@ def get_server_address(self): | |
| return self._server_address, self._server_port | ||
|
|
||
| async def launch_server(self, master_address: str = None, master_port: int = None): | ||
| if self.node_rank != 0: | ||
| assert master_address and master_port, "non-master node should provide master address and port" | ||
| self._master_address = master_address | ||
| self._master_port = master_port | ||
| if self.nnodes > 1: | ||
| if self.node_rank != 0: | ||
| assert master_address and master_port, "non-master node should provide master address and port" | ||
| self._master_address = master_address | ||
| self._master_port = master_port | ||
| else: | ||
| self._master_sock.close() | ||
|
|
||
| engine_kwargs = self.config.get("engine_kwargs", {}).get("sglang", {}) or {} | ||
| attention_backend = engine_kwargs.pop("attention_backend", None) | ||
|
|
@@ -167,11 +172,6 @@ async def launch_server(self, master_address: str = None, master_port: int = Non | |
| fp8_block_quant_kwargs = dict(FP8_BLOCK_QUANT_KWARGS) | ||
| else: | ||
| raise ValueError(f"Currently only support fp8 quantization, got: {quantization}") | ||
| dist_init_addr = ( | ||
| f"[{self._master_address}]:{self._master_port}" | ||
| if is_valid_ipv6_address(self._master_address) | ||
| else f"{self._master_address}:{self._master_port}" | ||
| ) | ||
| infer_tp = self.config.tensor_model_parallel_size * self.config.data_parallel_size | ||
| args = { | ||
| "model_path": self.model_config.local_path, | ||
|
|
@@ -186,7 +186,6 @@ async def launch_server(self, master_address: str = None, master_port: int = Non | |
| "ep_size": self.config.expert_parallel_size, | ||
| "node_rank": self.node_rank, | ||
| "load_format": self.config.load_format, | ||
| "dist_init_addr": dist_init_addr, | ||
| "nnodes": self.nnodes, | ||
| "trust_remote_code": self.model_config.trust_remote_code, | ||
| "max_running_requests": self.config.get("max_num_seqs", None), | ||
|
|
@@ -202,6 +201,16 @@ async def launch_server(self, master_address: str = None, master_port: int = Non | |
| **engine_kwargs, | ||
| } | ||
|
|
||
| # Only set dist_init_addr for multi-node; for single-node, let SGLang | ||
| # handle port selection internally via nccl_port to avoid conflicts. | ||
| if self.nnodes > 1: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we unify single/multi node, always choose free port for it? |
||
| dist_init_addr = ( | ||
| f"[{self._master_address}]:{self._master_port}" | ||
| if is_valid_ipv6_address(self._master_address) | ||
| else f"{self._master_address}:{self._master_port}" | ||
| ) | ||
| args["dist_init_addr"] = dist_init_addr | ||
|
|
||
| if self.config.prometheus.enable: | ||
| if self.config.prometheus.served_model_name: | ||
| # Extract model name from path if it's a full path | ||
|
|
@@ -510,7 +519,9 @@ async def launch_servers(self): | |
| self.servers.append(server) | ||
|
|
||
| # launch http server in each node | ||
| master_address, master_port = await self.servers[0].get_master_address.remote() | ||
| master_address, master_port = None, None | ||
| if self.nnodes > 1: | ||
| master_address, master_port = await self.servers[0].get_master_address.remote() | ||
| await asyncio.gather( | ||
| *[ | ||
| server.launch_server.remote(master_address=master_address, master_port=master_port) | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ async def run_unvicorn(app: FastAPI, server_args, server_address, max_retries=5) | |
|
|
||
| for i in range(max_retries): | ||
| try: | ||
| server_port, sock = get_free_port(server_address) | ||
| server_port, _ = get_free_port(server_address) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should keep sock alive here |
||
| app.server_args = server_args | ||
| config = uvicorn.Config(app, host=server_address, port=server_port, log_level="warning") | ||
| server = uvicorn.Server(config) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should keep sock alive here