Skip to content

Commit c894c5d

Browse files
authored
[Bug Fix] Fix address/port already in use error for deep_ep test (#20094)
Signed-off-by: yewentao256 <zhyanwentao@126.com>
1 parent 1f5d178 commit c894c5d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tests/kernels/moe/deepep_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import dataclasses
66
import importlib
7+
import os
78
import traceback
89
from typing import Callable, Optional
910

@@ -13,6 +14,8 @@
1314
spawn) # pyright: ignore[reportPrivateImportUsage]
1415
from typing_extensions import Concatenate, ParamSpec
1516

17+
from vllm.model_executor.layers.fused_moe.utils import find_free_port
18+
1619
has_deep_ep = importlib.util.find_spec("deep_ep") is not None
1720
if has_deep_ep:
1821
from vllm.model_executor.layers.fused_moe.deepep_ht_prepare_finalize import ( # noqa: E501
@@ -92,7 +95,7 @@ def parallel_launch(
9295
world_size,
9396
world_size,
9497
0,
95-
"tcp://localhost:29500",
98+
f"tcp://{os.getenv('LOCALHOST', 'localhost')}:{find_free_port()}",
9699
worker,
97100
) + args,
98101
nprocs=world_size,

vllm/model_executor/layers/fused_moe/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
import socket
4+
from contextlib import closing
35
from math import prod
46
from typing import Optional
57

@@ -96,3 +98,10 @@ def _fp8_perm(m: torch.Tensor, idx: torch.Tensor) -> torch.Tensor:
9698
return m.view(dtype=torch.uint8)[idx, ...].view(dtype=m.dtype)
9799
else:
98100
return m[idx, ...]
101+
102+
103+
def find_free_port():
104+
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
105+
s.bind(('', 0))
106+
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
107+
return s.getsockname()[1]

0 commit comments

Comments
 (0)