Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions tests/ignite/contrib/metrics/test_average_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ def get_test_cases():
def _test_distrib_integration_binary_input(device):

rank = idist.get_rank()
torch.manual_seed(12)
n_iters = 80
s = 16
batch_size = 16
n_classes = 2
offset = n_iters * s

def _test(y_preds, y_true, n_epochs, metric_device, update_fn):
metric_device = torch.device(metric_device)
Expand All @@ -232,6 +230,9 @@ def _test(y_preds, y_true, n_epochs, metric_device, update_fn):
data = list(range(n_iters))
engine.run(data=data, max_epochs=n_epochs)

y_true = idist.all_gather(y_true)
y_preds = idist.all_gather(y_preds)

assert "ap" in engine.state.metrics

res = engine.state.metrics["ap"]
Expand All @@ -240,24 +241,25 @@ def _test(y_preds, y_true, n_epochs, metric_device, update_fn):
assert pytest.approx(res) == true_res

def get_tests(is_N):
torch.manual_seed(12 + rank)
if is_N:
y_true = torch.randint(0, n_classes, size=(offset * idist.get_world_size(),)).to(device)
y_preds = torch.rand(offset * idist.get_world_size()).to(device)
y_true = torch.randint(0, n_classes, size=(n_iters * batch_size,)).to(device)
y_preds = torch.rand(n_iters * batch_size).to(device)

def update_fn(engine, i):
return (
y_preds[i * s + rank * offset : (i + 1) * s + rank * offset],
y_true[i * s + rank * offset : (i + 1) * s + rank * offset],
y_preds[i * batch_size : (i + 1) * batch_size],
y_true[i * batch_size : (i + 1) * batch_size],
)

else:
y_true = torch.randint(0, n_classes, size=(offset * idist.get_world_size(), 10)).to(device)
y_preds = torch.randint(0, n_classes, size=(offset * idist.get_world_size(), 10)).to(device)
y_true = torch.randint(0, n_classes, size=(n_iters * batch_size, 10)).to(device)
y_preds = torch.randint(0, n_classes, size=(n_iters * batch_size, 10)).to(device)

def update_fn(engine, i):
return (
y_preds[i * s + rank * offset : (i + 1) * s + rank * offset, :],
y_true[i * s + rank * offset : (i + 1) * s + rank * offset, :],
y_preds[i * batch_size : (i + 1) * batch_size, :],
y_true[i * batch_size : (i + 1) * batch_size, :],
)

return y_preds, y_true, update_fn
Expand Down