def METHOD_NAME(device):
    import numpy as np
    from ignite.engine import Engine
    rank = idist.get_rank()
    def _test(metric_device):
        n_iters = 80
        batch_size = 50
        torch.manual_seed(12 + rank)
        y_true = torch.arange(0, n_iters * batch_size, dtype=torch.float).to(device)
        y_preds = torch.ones(n_iters * batch_size, dtype=torch.float).to(device)
        def update(engine, i):
            return (
                y_preds[i * batch_size : (i + 1) * batch_size],
                y_true[i * batch_size : (i + 1) * batch_size],
            )
        engine = Engine(update)
        m = MeanAbsoluteError(device=metric_device)
        m.attach(engine, "mae")
        data = list(range(n_iters))
        engine.run(data=data, max_epochs=1)
        y_preds = idist.all_gather(y_preds)
        y_true = idist.all_gather(y_true)
        assert "mae" in engine.state.metrics
        res = engine.state.metrics["mae"]
        true_res = np.mean(np.abs((y_true - y_preds).cpu().numpy()))
        assert pytest.approx(res) == true_res
    _test("cpu")
    if device.type != "xla":
        _test(idist.device())