Created
January 3, 2025 03:05
-
-
Save youkaichao/ee42782c91e444851965509236beea62 to your computer and use it in GitHub Desktop.
cmp shm broadcast and pytorch broadcast object list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.distributed as dist | |
import torch | |
import time | |
dist.init_process_group(backend="nccl") | |
rank = dist.get_rank() | |
torch.cuda.set_device(rank) | |
N_warmup = 10 | |
N_measure = 100 | |
if rank == 0: | |
rpc_method = "a" | |
for i in range(N_warmup): | |
dist.broadcast_object_list([rpc_method], src=0) | |
send_latencies = [] | |
for i in range(N_measure): | |
t0 = time.perf_counter_ns() | |
dist.broadcast_object_list([rpc_method], src=0) | |
t1 = time.perf_counter_ns() | |
send_latencies.append(t1 - t0) | |
median = sorted(send_latencies)[len(send_latencies) // 2] | |
print(f"Median latency: {median / 1e3:.3f} us") | |
else: | |
for i in range(N_warmup + N_measure): | |
recv_data = [None] | |
dist.broadcast_object_list(recv_data, src=0) | |
rpc_method = recv_data[0] | |
assert rpc_method == "a" | |
# torchrun --nproc-per-node=8 test_pytorch.py | |
# Median latency: 121.143 us |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
measure both shm broadcast send and recv latency: