(self, obj)
| 575 | warnings.warn(f"While closing process group: {e}.") |
| 576 | |
| 577 | def __call__(self, obj): |
| 578 | if not torch.distributed.is_available(): |
| 579 | return unittest.skipIf(True, "Skipping distributed tests because not torch.distributed.is_available()")(obj) |
| 580 | if torch.cuda.is_available() and torch.cuda.device_count() < self.nproc_per_node: |
| 581 | return unittest.skipIf( |
| 582 | True, |
| 583 | f"Skipping distributed tests because it requires {self.nnodes} devices " |
| 584 | f"but got {torch.cuda.device_count()}", |
| 585 | )(obj) |
| 586 | |
| 587 | _cache_original_func(obj) |
| 588 | |
| 589 | @functools.wraps(obj) |
| 590 | def _wrapper(*args, **kwargs): |
| 591 | tmp = torch.multiprocessing.get_context(self.method) |
| 592 | processes = [] |
| 593 | results = tmp.Queue() |
| 594 | func = _call_original_func |
| 595 | args = [obj.__name__, obj.__module__] + list(args) |
| 596 | |
| 597 | for proc_rank in range(self.nproc_per_node): |
| 598 | run_args = (func, proc_rank, args, kwargs, results) |
| 599 | p = tmp.Process(target=self.run_process, args=run_args, daemon=self.daemon) |
| 600 | p.start() |
| 601 | processes.append(p) |
| 602 | |
| 603 | for p in processes: |
| 604 | p.join() |
| 605 | pr = results.get(block=False) |
| 606 | assert pr is True, f"Distributed call failed: {pr}" |
| 607 | _del_original_func(obj) |
| 608 | |
| 609 | return _wrapper |
| 610 | |
| 611 | |
| 612 | class TimedCall: |
nothing calls this directly
no test coverage detected