(self, func, local_rank, args, kwargs, results)
| 532 | self.verbose = verbose |
| 533 | |
| 534 | def run_process(self, func, local_rank, args, kwargs, results): |
| 535 | _env = os.environ.copy() # keep the original system env |
| 536 | try: |
| 537 | os.environ["MASTER_ADDR"] = self.master_addr |
| 538 | os.environ["MASTER_PORT"] = str(self.master_port) |
| 539 | os.environ["LOCAL_RANK"] = str(local_rank) |
| 540 | if self.verbose: |
| 541 | os.environ["NCCL_DEBUG"] = "INFO" |
| 542 | os.environ["NCCL_DEBUG_SUBSYS"] = "ALL" |
| 543 | os.environ["TORCH_NCCL_BLOCKING_WAIT"] = str(1) |
| 544 | os.environ["OMP_NUM_THREADS"] = str(1) |
| 545 | os.environ["WORLD_SIZE"] = str(self.nproc_per_node * self.nnodes) |
| 546 | os.environ["RANK"] = str(self.nproc_per_node * self.node_rank + local_rank) |
| 547 | |
| 548 | if torch.cuda.is_available(): |
| 549 | torch.cuda.set_device(int(local_rank)) # using device ids from CUDA_VISIBILE_DEVICES |
| 550 | |
| 551 | if self.init_method != "no_init": |
| 552 | dist.init_process_group( |
| 553 | backend=self.backend, |
| 554 | init_method=self.init_method, |
| 555 | timeout=self.timeout, |
| 556 | world_size=int(os.environ["WORLD_SIZE"]), |
| 557 | rank=int(os.environ["RANK"]), |
| 558 | ) |
| 559 | func(*args, **kwargs) |
| 560 | # the primary node lives longer to |
| 561 | # avoid _store_based_barrier, RuntimeError: Broken pipe |
| 562 | # as the TCP store daemon is on the rank 0 |
| 563 | if int(os.environ["RANK"]) == 0: |
| 564 | time.sleep(0.1) |
| 565 | results.put(True) |
| 566 | except Exception as e: |
| 567 | results.put(str(e)) |
| 568 | raise e |
| 569 | finally: |
| 570 | os.environ.clear() |
| 571 | os.environ.update(_env) |
| 572 | try: |
| 573 | dist.destroy_process_group() |
| 574 | except RuntimeError as e: |
| 575 | warnings.warn(f"While closing process group: {e}.") |
| 576 | |
| 577 | def __call__(self, obj): |
| 578 | if not torch.distributed.is_available(): |
nothing calls this directly
no test coverage detected