MCPcopy Create free account
hub / github.com/FlashSampling/FlashSampling / _distributed_worker

Function _distributed_worker

src/fused_mm_sampling/tp_info.py:83–107  ·  view source on GitHub ↗
(rank: int, world_size: int, port: int, fn: Callable, args: tuple)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

_print_gpu_topologyFunction · 0.85
_numa_bindFunction · 0.70
fnFunction · 0.50

Tested by

no test coverage detected