Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
388596c9
Unverified
Commit
388596c9
authored
Jun 06, 2024
by
youkaichao
Committed by
GitHub
Jun 06, 2024
Browse files
[Misc][Utils] allow get_open_port to be called for multiple times (#5333)
parent
baa15a9e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
2 deletions
+27
-2
tests/test_utils.py
tests/test_utils.py
+15
-1
vllm/envs.py
vllm/envs.py
+3
-0
vllm/utils.py
vllm/utils.py
+9
-1
No files found.
tests/test_utils.py
View file @
388596c9
import
asyncio
import
os
import
socket
import
sys
from
typing
import
(
TYPE_CHECKING
,
Any
,
AsyncIterator
,
Awaitable
,
Protocol
,
Tuple
,
TypeVar
)
import
pytest
from
vllm.utils
import
deprecate_kwargs
,
merge_async_iterators
from
vllm.utils
import
deprecate_kwargs
,
get_open_port
,
merge_async_iterators
from
.utils
import
error_on_warning
...
...
@@ -116,3 +118,15 @@ def test_deprecate_kwargs_additional_message():
with
pytest
.
warns
(
DeprecationWarning
,
match
=
"abcd"
):
dummy
(
old_arg
=
1
)
def
test_get_open_port
():
os
.
environ
[
"VLLM_PORT"
]
=
"5678"
# make sure we can get multiple ports, even if the env var is set
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s1
:
s1
.
bind
((
"localhost"
,
get_open_port
()))
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s2
:
s2
.
bind
((
"localhost"
,
get_open_port
()))
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s3
:
s3
.
bind
((
"localhost"
,
get_open_port
()))
os
.
environ
.
pop
(
"VLLM_PORT"
)
vllm/envs.py
View file @
388596c9
...
...
@@ -99,6 +99,9 @@ environment_variables: Dict[str, Callable[[], Any]] = {
lambda
:
os
.
getenv
(
'VLLM_HOST_IP'
,
""
)
or
os
.
getenv
(
"HOST_IP"
,
""
),
# used in distributed environment to manually set the communication port
# Note: if VLLM_PORT is set, and some code asks for multiple ports, the
# VLLM_PORT will be used as the first port, and the rest will be generated
# by incrementing the VLLM_PORT value.
# '0' is used to make mypy happy
'VLLM_PORT'
:
lambda
:
int
(
os
.
getenv
(
'VLLM_PORT'
,
'0'
))
...
...
vllm/utils.py
View file @
388596c9
...
...
@@ -289,7 +289,15 @@ def get_distributed_init_method(ip: str, port: int) -> str:
def
get_open_port
()
->
int
:
port
=
envs
.
VLLM_PORT
if
port
is
not
None
:
while
True
:
try
:
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s
:
s
.
bind
((
""
,
port
))
return
port
except
OSError
:
port
+=
1
# Increment port number if already in use
logger
.
info
(
"Port %d is already in use, trying port %d"
,
port
-
1
,
port
)
# try ipv4
try
:
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment