[diffusion] chore: use batched P2P ops in VAE parallel decoding (#18728)
This commit is contained in:
@@ -134,24 +134,27 @@ def halo_exchange(
|
|||||||
recv_top_buf = _ensure_recv_buf(recv_top_buf, top_row)
|
recv_top_buf = _ensure_recv_buf(recv_top_buf, top_row)
|
||||||
recv_bottom_buf = _ensure_recv_buf(recv_bottom_buf, bottom_row)
|
recv_bottom_buf = _ensure_recv_buf(recv_bottom_buf, bottom_row)
|
||||||
|
|
||||||
reqs = []
|
# use batched P2P operations
|
||||||
|
p2p_ops = []
|
||||||
|
|
||||||
if rank > 0:
|
if rank > 0:
|
||||||
# has previous neighbor, recv previous rank's data to recv_top_buf and send top_row to it.
|
# has previous neighbor, recv previous rank's data to recv_top_buf and send top_row to it.
|
||||||
prev_rank = group_ranks[rank - 1]
|
prev_rank = group_ranks[rank - 1]
|
||||||
reqs.append(dist.irecv(recv_top_buf, src=prev_rank, group=group))
|
p2p_ops.append(dist.P2POp(dist.irecv, recv_top_buf, prev_rank, group))
|
||||||
reqs.append(dist.isend(top_row, dst=prev_rank, group=group))
|
p2p_ops.append(dist.P2POp(dist.isend, top_row, prev_rank, group))
|
||||||
if rank < world_size - 1:
|
if rank < world_size - 1:
|
||||||
# has next neighbor, send bottom_row to next rank and recv next rank's data to recv_bottom_buf.
|
# has next neighbor, send bottom_row to next rank and recv next rank's data to recv_bottom_buf.
|
||||||
next_rank = group_ranks[rank + 1]
|
next_rank = group_ranks[rank + 1]
|
||||||
reqs.append(dist.isend(bottom_row, dst=next_rank, group=group))
|
p2p_ops.append(dist.P2POp(dist.isend, bottom_row, next_rank, group))
|
||||||
reqs.append(dist.irecv(recv_bottom_buf, src=next_rank, group=group))
|
p2p_ops.append(dist.P2POp(dist.irecv, recv_bottom_buf, next_rank, group))
|
||||||
|
|
||||||
if rank == 0:
|
if rank == 0:
|
||||||
recv_top_buf.zero_()
|
recv_top_buf.zero_()
|
||||||
if rank == world_size - 1:
|
if rank == world_size - 1:
|
||||||
recv_bottom_buf.zero_()
|
recv_bottom_buf.zero_()
|
||||||
|
|
||||||
|
if p2p_ops:
|
||||||
|
reqs = dist.batch_isend_irecv(p2p_ops)
|
||||||
for req in reqs:
|
for req in reqs:
|
||||||
req.wait()
|
req.wait()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user