Skip to content

Commit d2a56c2

Browse files
zhuzilinping1jing2
authored andcommitted
[RL] Add --nccl-port to prevent port conflict (sgl-project#7418)
1 parent 910075e commit d2a56c2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

python/sglang/srt/server_args.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ServerArgs:
6868
# Port for the HTTP server
6969
host: str = "127.0.0.1"
7070
port: int = 30000
71+
nccl_port: Optional[int] = None
7172

7273
# Memory and scheduling
7374
mem_fraction_static: Optional[float] = None
@@ -599,6 +600,12 @@ def add_cli_args(parser: argparse.ArgumentParser):
599600
default=ServerArgs.port,
600601
help="The port of the HTTP server.",
601602
)
603+
parser.add_argument(
604+
"--nccl-port",
605+
type=int,
606+
default=ServerArgs.nccl_port,
607+
help="The port for NCCL distributed environment setup. Defaults to a random port.",
608+
)
602609
parser.add_argument(
603610
"--tokenizer-mode",
604611
type=str,
@@ -1747,14 +1754,17 @@ class PortArgs:
17471754

17481755
@staticmethod
17491756
def init_new(server_args, dp_rank: Optional[int] = None) -> "PortArgs":
1750-
port = server_args.port + random.randint(100, 1000)
1751-
while True:
1752-
if is_port_available(port):
1753-
break
1754-
if port < 60000:
1755-
port += 42
1756-
else:
1757-
port -= 43
1757+
if server_args.nccl_port is None:
1758+
port = server_args.port + random.randint(100, 1000)
1759+
while True:
1760+
if is_port_available(port):
1761+
break
1762+
if port < 60000:
1763+
port += 42
1764+
else:
1765+
port -= 43
1766+
else:
1767+
port = server_args.nccl_port
17581768

17591769
if not server_args.enable_dp_attention:
17601770
# Normal case, use IPC within a single node

0 commit comments

Comments
 (0)