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
82
83def _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
110def _print_gpu_topology() -> None:

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