MCPcopy Create free account
hub / github.com/pytorch/tutorials / init_pg

Function init_pg

advanced_source/cuda_graph_annotations_tutorial.py:739–748  ·  view source on GitHub ↗

Initialize a NCCL group for one rank of the spawned demo.

(rank, world_size)

Source from the content-addressed store, hash-verified

737WORLD_SIZE = 2
738
739def init_pg(rank, world_size):
740 """Initialize a NCCL group for one rank of the spawned demo."""
741 os.environ["MASTER_ADDR"] = "127.0.0.1"
742 os.environ["MASTER_PORT"] = "29500"
743 os.environ["RANK"] = str(rank)
744 os.environ["WORLD_SIZE"] = str(world_size)
745 # Use loopback interface for single-node setup
746 os.environ["NCCL_SOCKET_IFNAME"] = "lo"
747 dist.init_process_group("nccl", rank=rank, world_size=world_size)
748 torch.cuda.set_device(rank)
749
750def _comm_worker(rank, world_size):
751 """Per-rank worker: build, capture, profile, and (on rank 0) post-process."""

Callers 1

_comm_workerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected