mmengine.dist.collect_results¶
- mmengine.dist.collect_results(results, size, device='cpu', tmpdir=None)[源代码]¶
Collected results in distributed environments.
- 参数:
results (list[object]) – Result list containing result parts to be collected. Each item of
result_part
should be a picklable object.size (int) – Size of the results, commonly equal to length of the results.
device (str) – Device name. Optional values are ‘cpu’, ‘gpu’ or ‘npu’.
tmpdir (str | None) – Temporal directory for collected results to store. If set to None, it will create a temporal directory for it.
tmpdir
should be None when device is ‘gpu’ or ‘npu’. Defaults to None.
- 返回:
The collected results.
- 返回类型:
list or None
示例
>>> # distributed environment >>> # We have 2 process groups, 2 ranks. >>> import mmengine.dist as dist >>> if dist.get_rank() == 0: data = ['foo', {1: 2}] else: data = [24, {'a': 'b'}] >>> size = 4 >>> output = dist.collect_results(data, size, device='cpu') >>> output ['foo', 24, {1: 2}, {'a': 'b'}] # rank 0 None # rank 1