# distributed

Python API: `luxonis_train.attached_modules.metrics.distributed`

Distributed gathering helpers for per-image metric states.

## Functions

| Name | Description |
| --- | --- |
|
[`sync_per_image_states`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/attached_modules/metrics/distributed.md)
| Gather per-image vector or matrix lists with two gathers per state. |

### function `sync_per_image_states`

```python
def sync_per_image_states(
    metric: Metric,
    dist_sync_fn: Callable = gather_all_tensors,
    process_group: Any = None,
)
```

Gather per-image vector or matrix lists with two gathers per state.

Opt in only for metrics whose states are all lists of per-image tensors that must retain image boundaries. This does not implement
reductions for scalar states or concatenated sample lists.

The header records dtype, channel width (-1 for vectors), and per- image row counts. The second gather exchanges concatenated
rows. Empty ranks still participate in both gathers. TorchMetrics caches and restores the original local lists around
synchronization.
