Skip to content
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

[Core][Distributed] add shm broadcast #5399

Merged
merged 43 commits into from
Jun 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c82dc08
add shm broadcast
youkaichao Jun 10, 2024
aa15dc2
fix name
youkaichao Jun 10, 2024
7d4f81e
Merge branch 'main' into shm_broadcast
youkaichao Jun 14, 2024
b4e5d47
enable shm broadcast
youkaichao Jun 14, 2024
aa606d1
use HIGHEST_PROTOCOL
youkaichao Jun 14, 2024
943147c
add modulus
youkaichao Jun 14, 2024
2f2e7b8
error on large object
youkaichao Jun 14, 2024
399f8c1
name written flag
youkaichao Jun 14, 2024
a7db4d5
rename to data and metadata
youkaichao Jun 14, 2024
a105688
add sleep if all blocks are empty
youkaichao Jun 14, 2024
d09c8b6
bump up slots
youkaichao Jun 14, 2024
ba6839d
only memset for metadata section
youkaichao Jun 14, 2024
a298ae9
add comments
youkaichao Jun 14, 2024
2c775d0
remove initialization in world size 1
youkaichao Jun 15, 2024
b8105bb
add comments
youkaichao Jun 15, 2024
681919a
add warning if waiting for too long
youkaichao Jun 15, 2024
468bf93
add shm broadcast tests
youkaichao Jun 15, 2024
c5e47b3
lint
youkaichao Jun 15, 2024
98188ce
add tests
youkaichao Jun 15, 2024
8e755f2
Update vllm/distributed/device_communicators/shm_broadcast.py
youkaichao Jun 16, 2024
5197920
Merge branch 'main' into shm_broadcast
youkaichao Jun 16, 2024
398c6e2
Merge branch 'main' into shm_broadcast
youkaichao Jun 16, 2024
57a1839
Merge branch 'main' into shm_broadcast
youkaichao Jun 18, 2024
95b8a87
use underscore for private attributes
youkaichao Jun 18, 2024
c0cc37f
rename
youkaichao Jun 18, 2024
fc49f86
add mem layout docstring
youkaichao Jun 18, 2024
34475a0
stash
youkaichao Jun 18, 2024
82792f1
Merge branch 'main' into shm_broadcast
youkaichao Jun 20, 2024
4b70d6f
refactor
youkaichao Jun 20, 2024
bb851d4
use queue
youkaichao Jun 20, 2024
f7680f4
fix lint
youkaichao Jun 20, 2024
9af386c
add single process test
youkaichao Jun 20, 2024
729a592
fix warning
youkaichao Jun 20, 2024
0a61a69
add barrier
youkaichao Jun 20, 2024
d8d9a0f
add test for complicated cases
youkaichao Jun 20, 2024
608d57f
fix tests
youkaichao Jun 20, 2024
e5137cb
fix tests
youkaichao Jun 20, 2024
d0aa190
add comments
youkaichao Jun 21, 2024
d0522b0
fix race condition
youkaichao Jun 21, 2024
cd39b81
add random delay in test
youkaichao Jun 21, 2024
d0f77e9
add comments
youkaichao Jun 21, 2024
5fd104e
use env var
youkaichao Jun 21, 2024
0e3a810
fix env
youkaichao Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add warning if waiting for too long
  • Loading branch information
youkaichao committed Jun 15, 2024
commit 681919a3a6a44904c5f3cac8edf23e832ee7a162
17 changes: 17 additions & 0 deletions vllm/distributed/device_communicators/shm_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
import torch.distributed as dist
from torch.distributed import ProcessGroup

from vllm.logger import init_logger

logger = init_logger(__name__)


class ShmRingBuffer:

# seconds to wait before warning about a potential blocking call
WARNING_INTERVAL = 60

def __init__(self, pg: ProcessGroup, max_chunk_bytes, max_chunks):
self.rank = dist.get_rank(pg)
self.world_size = dist.get_world_size(pg)
Expand Down Expand Up @@ -64,6 +71,7 @@ def metadata(self):
def acquire_write(self):
assert self.is_writer, "Only writers can acquire write"
start_index = self.current_idx
start_time = time.time()
while True:
youkaichao marked this conversation as resolved.
Show resolved Hide resolved
with self.metadata as metadata_buffer:
read_count = sum(metadata_buffer[1:])
youkaichao marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -74,6 +82,10 @@ def acquire_write(self):
self.current_idx = (self.current_idx + 1) % self.max_chunks
if self.current_idx == start_index:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means we iterate all the data chunks right? Can you comment here?

# no empty block found
if time.time() - start_time > self.WARNING_INTERVAL:
logger.warning(
"No available block found in %s second. ",
self.WARNING_INTERVAL)
youkaichao marked this conversation as resolved.
Show resolved Hide resolved
# wait for a while (0.1 us)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this too small? (we call sleep 1e7 times per second). Have you measured the CPU overhead in this scenario by chance?

time.sleep(1e-7)
youkaichao marked this conversation as resolved.
Show resolved Hide resolved
continue
Expand All @@ -95,6 +107,7 @@ def acquire_write(self):
def acquire_read(self):
assert self.is_reader, "Only readers can acquire read"
start_index = self.current_idx
start_time = time.time()
while True:
with self.metadata as metadata_buffer:
read_flag = metadata_buffer[self.rank]
Expand All @@ -107,6 +120,10 @@ def acquire_read(self):
self.current_idx = (self.current_idx + 1) % self.max_chunks
if self.current_idx == start_index:
# no block found
if time.time() - start_time > self.WARNING_INTERVAL:
logger.warning(
"No available block found in %s second. ",
self.WARNING_INTERVAL)
# wait for a while (0.1 us)
time.sleep(1e-7)
continue
Expand Down
Loading