leideng/QCFuse / srt /utils /poll_based_barrier.py
leideng's picture
download
raw
937 Bytes
import torch
from sglang.srt.distributed import get_world_group
class PollBasedBarrier:
def __init__(self, noop: bool = False):
self._noop = noop
self._local_arrived = False
def local_arrive(self):
assert not self._local_arrived
self._local_arrived = True
def poll_global_arrived(self) -> bool:
global_arrived = self._compute_global_arrived()
output = self._local_arrived and global_arrived
if output:
self._local_arrived = False
return output
def _compute_global_arrived(self) -> bool:
local_arrived = self._noop or self._local_arrived
global_arrived = torch.tensor(local_arrived)
# Can optimize if bottleneck
torch.distributed.all_reduce(
global_arrived,
torch.distributed.ReduceOp.MIN,
group=get_world_group().cpu_group,
)
return global_arrived.item()

Xet Storage Details

Size:
937 Bytes
·
Xet hash:
579dc9709d2ef40631647396d109df0c8a60341ac1a2504443b167a1098cb212

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.