Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ def _test(metric_device):


def _test_distrib_integration(device):

rank = idist.get_rank()
torch.manual_seed(12)

def _test(n_epochs, metric_device):
metric_device = torch.device(metric_device)
rank = idist.get_rank()
torch.manual_seed(rank)
n_iters = 80
size = 105
y_true = torch.rand(size=(size,)).to(device)
y_preds = torch.rand(size=(size,)).to(device)

offset = n_iters * size
y_true = torch.rand(size=(offset * idist.get_world_size(),)).to(device)
y_preds = torch.rand(size=(offset * idist.get_world_size(),)).to(device)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayantan1410 either revert these modifications or make them coherent to others and rename the PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, making them coherent with others, also some tests are failing, fixing them as well

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you updated others ? Do not forget to rename the PR title to reflect that you change not only test_precision_recall_curve.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in the other tests this has been changed and I have changed the PR title as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you add

        rank = idist.get_rank()
        torch.manual_seed(rank)

here and other regression files ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to precision_recall_curve and was waiting for all the tests to pass for it. Now I will add it to the other files as well.


def update(engine, i):
return (
y_preds[i * size : (i + 1) * size],
y_true[i * size : (i + 1) * size],
y_preds[i * size + rank * offset : (i + 1) * size + rank * offset],
y_true[i * size + rank * offset : (i + 1) * size + rank * offset],
)

engine = Engine(update)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ def _test(metric_device):


def _test_distrib_integration(device):

rank = idist.get_rank()
torch.manual_seed(12)

def _test(n_epochs, metric_device):
metric_device = torch.device(metric_device)
rank = idist.get_rank()
torch.manual_seed(rank)
n_iters = 80
size = 105
y_true = torch.rand(size=(size,)).to(device)
y_preds = torch.rand(size=(size,)).to(device)

offset = n_iters * size
y_true = torch.rand(size=(offset * idist.get_world_size(),)).to(device)
y_preds = torch.rand(size=(offset * idist.get_world_size(),)).to(device)

def update(engine, i):
return (
y_preds[i * size : (i + 1) * size],
y_true[i * size : (i + 1) * size],
y_preds[i * size + rank * offset : (i + 1) * size + rank * offset],
y_true[i * size + rank * offset : (i + 1) * size + rank * offset],
)

engine = Engine(update)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ def _test(metric_device):


def _test_distrib_integration(device):

rank = idist.get_rank()
torch.manual_seed(12)

def _test(n_epochs, metric_device):
metric_device = torch.device(metric_device)
rank = idist.get_rank()
torch.manual_seed(rank)
n_iters = 80
size = 151
y_true = torch.rand(size=(size,)).to(device)
y_preds = torch.rand(size=(size,)).to(device)

offset = n_iters * size
y_true = torch.rand(size=(offset * idist.get_world_size(),)).to(device)
y_preds = torch.rand(size=(offset * idist.get_world_size(),)).to(device)

def update(engine, i):
return (
y_preds[i * size : (i + 1) * size],
y_true[i * size : (i + 1) * size],
y_preds[i * size + rank * offset : (i + 1) * size + rank * offset],
y_true[i * size + rank * offset : (i + 1) * size + rank * offset],
)

engine = Engine(update)
Expand Down
22 changes: 11 additions & 11 deletions tests/ignite/contrib/metrics/test_precision_recall_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ def get_test_cases():


def _test_distrib_integration(device):

rank = idist.get_rank()
torch.manual_seed(12)

def _test(n_epochs, metric_device):
metric_device = torch.device(metric_device)
rank = idist.get_rank()
torch.manual_seed(rank)
n_iters = 80
size = 151
y_true = torch.randint(0, 2, (size,)).to(device)
y_preds = torch.randint(0, 2, (size,)).to(device)

offset = n_iters * size
y_true = torch.randint(0, 2, size=(offset * idist.get_world_size(),)).to(device)
y_preds = torch.randint(0, 2, size=(offset * idist.get_world_size(),)).to(device)

def update(engine, i):
return (
y_preds[i * size : (i + 1) * size],
y_true[i * size : (i + 1) * size],
y_preds[i * size + rank * offset : (i + 1) * size + rank * offset],
y_true[i * size + rank * offset : (i + 1) * size + rank * offset],
)

engine = Engine(update)
Expand All @@ -231,9 +231,9 @@ def update(engine, i):
assert precision.shape == sk_precision.shape
assert recall.shape == sk_recall.shape
assert thresholds.shape == sk_thresholds.shape
assert pytest.approx(precision.cpu().numpy()) == sk_precision
assert pytest.approx(recall.cpu().numpy()) == sk_recall
assert pytest.approx(thresholds.cpu().numpy()) == sk_thresholds
assert pytest.approx(precision.cpu().numpy(), rel=1e-3) == sk_precision
assert pytest.approx(recall.cpu().numpy(), rel=1e-3) == sk_recall
assert pytest.approx(thresholds.cpu().numpy(), rel=1e-3) == sk_thresholds

metric_devices = ["cpu"]
if device.type != "xla":
Expand Down