Use Python 3.9 syntax in examples (#37279)

Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
cyyever
2025-04-07 19:52:21 +08:00
committed by GitHub
parent 08f36771b3
commit 0fb8d49e88
123 changed files with 358 additions and 451 deletions

View File

@@ -19,16 +19,16 @@ def run(backend):
tensor = torch.zeros(1)
# Need to put tensor on a GPU device for nccl backend
if backend == "nccl":
device = torch.device("cuda:{}".format(LOCAL_RANK))
device = torch.device(f"cuda:{LOCAL_RANK}")
tensor = tensor.to(device)
if WORLD_RANK == 0:
for rank_recv in range(1, WORLD_SIZE):
dist.send(tensor=tensor, dst=rank_recv)
print("worker_{} sent data to Rank {}\n".format(0, rank_recv))
print(f"worker_{0} sent data to Rank {rank_recv}\n")
else:
dist.recv(tensor=tensor, src=0)
print("worker_{} has received data from rank {}\n".format(WORLD_RANK, 0))
print(f"worker_{WORLD_RANK} has received data from rank {0}\n")
def init_processes(backend):