Skip to content

add tolerance for tpu in r2 and canberra tests #1414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 30, 2020
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
8 changes: 4 additions & 4 deletions tests/ignite/contrib/metrics/regression/test_r2_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def update_fn(engine, batch):
assert r2_score(np_y, np_y_pred) == pytest.approx(r_squared)


def _test_distrib_compute(device):
def _test_distrib_compute(device, tol=1e-6):
rank = idist.get_rank()

def _test(metric_device):
Expand All @@ -111,7 +111,7 @@ def _test(metric_device):
np_y_pred = y_pred.cpu().numpy()
np_y = y.cpu().numpy()
res = m.compute()
assert r2_score(np_y, np_y_pred) == pytest.approx(res)
assert r2_score(np_y, np_y_pred) == pytest.approx(res, abs=tol)

for _ in range(3):
_test("cpu")
Expand Down Expand Up @@ -167,12 +167,12 @@ def test_multinode_distrib_gpu(distributed_context_multi_node_nccl):
@pytest.mark.skipif(not idist.has_xla_support, reason="Skip if no PyTorch XLA package")
def test_distrib_single_device_xla():
device = idist.device()
_test_distrib_compute(device)
_test_distrib_compute(device, tol=1e-3)


def _test_distrib_xla_nprocs(index):
device = idist.device()
_test_distrib_compute(device)
_test_distrib_compute(device, tol=1e-3)


@pytest.mark.tpu
Expand Down