(rank: int, world_size: int, port: int, fn: Callable, args: tuple)
| 81 | |
| 82 | |
| 83 | def _distributed_worker(rank: int, world_size: int, port: int, fn: Callable, args: tuple) -> None: |
| 84 | if rank == 0: |
| 85 | _print_gpu_topology() |
| 86 | print( |
| 87 | f"Rank {rank}: available CPUs (before NUMA bind): {sorted(os.sched_getaffinity(0))}", |
| 88 | flush=True, |
| 89 | ) |
| 90 | _numa_bind(rank) |
| 91 | device_id = rank % torch.cuda.device_count() |
| 92 | torch.cuda.set_device(device_id) |
| 93 | backend = "nccl" if torch.cuda.device_count() >= world_size else "gloo" |
| 94 | if rank == 0: |
| 95 | print(f"Using distributed backend: '{backend}'") |
| 96 | |
| 97 | dist.init_process_group( |
| 98 | backend=backend, |
| 99 | init_method=f"tcp://localhost:{port}", |
| 100 | rank=rank, |
| 101 | world_size=world_size, |
| 102 | device_id=device_id, |
| 103 | ) |
| 104 | try: |
| 105 | fn(*args) |
| 106 | finally: |
| 107 | dist.destroy_process_group() |
| 108 | |
| 109 | |
| 110 | def _print_gpu_topology() -> None: |
nothing calls this directly
no test coverage detected