`test_torch_tanh_approx` is flaky
Describe the bug
test_torch_tanh_approx often fails during automated PR-checking test runs.
To Reproduce Run the test or the test suite a few times until it fails.
Expected behavior Should pass reliably.
Screenshots
____________________ test_torch_tanh_approx[sigmoid-3-0.1] _____________________
method = 'sigmoid', prec_frac = 3, tolerance = 0.1
workers = {'alice': <VirtualWorker id:alice #objects:7>, 'bob': <VirtualWorker id:bob #objects:7>, 'charlie': <VirtualWorker id:charlie #objects:6>, 'james': <VirtualWorker id:james #objects:6>, ...}
@pytest.mark.parametrize(
"method, prec_frac, tolerance",
[
("chebyshev", 3, 3 / 100),
("chebyshev", 4, 2 / 100),
("sigmoid", 3, 10 / 100),
("sigmoid", 4, 5 / 100),
],
)
def test_torch_tanh_approx(method, prec_frac, tolerance, workers):
"""
Test the approximate tanh with different tolerance depending on
the precision_fractional considered
"""
alice, bob, james = workers["alice"], workers["bob"], workers["james"]
t = torch.tensor(range(-10, 10)) * 0.5
t_sh = t.fix_precision(precision_fractional=prec_frac).share(alice, bob, crypto_provider=james)
r_sh = t_sh.tanh(method)
r = r_sh.get().float_prec()
t = t.tanh()
diff = (r - t).abs().max()
norm = (r + t).abs().max() / 2
> assert (diff / (tolerance * norm)) < 1
E assert (tensor(0.1001) / (0.1 * tensor(1.0000))) < 1
test/torch/tensors/test_precision.py:512: AssertionError
Additional context Possible that several of the parameterized cases are flaky.
I will look on this.
Seen this again, here:
2020-05-15T10:08:51.0720029Z =================================== FAILURES ===================================
2020-05-15T10:08:51.0721859Z ____________________ test_torch_tanh_approx[sigmoid-3-0.1] _____________________
2020-05-15T10:08:51.0722192Z
2020-05-15T10:08:51.0722841Z method = 'sigmoid', prec_frac = 3, tolerance = 0.1
2020-05-15T10:08:51.0723543Z workers = {'alice': <VirtualWorker id:alice #objects:1>, 'bob': <VirtualWorker id:bob #objects:1>, 'charlie': <VirtualWorker id:charlie #objects:0>, 'james': <VirtualWorker id:james #objects:0>, ...}
2020-05-15T10:08:51.0723844Z
2020-05-15T10:08:51.0724137Z @pytest.mark.parametrize(
2020-05-15T10:08:51.0724423Z "method, prec_frac, tolerance",
2020-05-15T10:08:51.0724702Z [
2020-05-15T10:08:51.0724982Z ("chebyshev", 3, 3 / 100),
2020-05-15T10:08:51.0725298Z ("chebyshev", 4, 2 / 100),
2020-05-15T10:08:51.0725575Z ("sigmoid", 3, 10 / 100),
2020-05-15T10:08:51.0725839Z ("sigmoid", 4, 5 / 100),
2020-05-15T10:08:51.0726117Z ],
2020-05-15T10:08:51.0726385Z )
2020-05-15T10:08:51.0726666Z def test_torch_tanh_approx(method, prec_frac, tolerance, workers):
2020-05-15T10:08:51.0726956Z """
2020-05-15T10:08:51.0727241Z Test the approximate tanh with different tolerance depending on
2020-05-15T10:08:51.0727539Z the precision_fractional considered
2020-05-15T10:08:51.0727820Z """
2020-05-15T10:08:51.0728136Z alice, bob, james = workers["alice"], workers["bob"], workers["james"]
2020-05-15T10:08:51.0728430Z
2020-05-15T10:08:51.0728923Z t = torch.tensor(range(-10, 10)) * 0.5
2020-05-15T10:08:51.0729246Z t_sh = t.fix_precision(precision_fractional=prec_frac).share(alice, bob, crypto_provider=james)
2020-05-15T10:08:51.0729547Z r_sh = t_sh.tanh(method)
2020-05-15T10:08:51.0729828Z r = r_sh.get().float_prec()
2020-05-15T10:08:51.0730108Z t = t.tanh()
2020-05-15T10:08:51.0730596Z diff = (r - t).abs().max()
2020-05-15T10:08:51.0730890Z norm = (r + t).abs().max() / 2
2020-05-15T10:08:51.0731163Z
2020-05-15T10:08:51.0731433Z > assert (diff / (tolerance * norm)) < 1
2020-05-15T10:08:51.0731714Z E assert (tensor(0.1021) / (0.1 * tensor(1.0000))) < 1
2020-05-15T10:08:51.0731925Z
@gmuraru Is this a case where we should increase the tolerance on this test? I've hesitated to fix it that way, because I don't know how much that weakens the test assertion, but think I remember seeing similar tests adjusted that way in the past.
This issue has been marked stale because it has been open 30 days with no activity. Leave a comment or remove the stale label to unmark it. Otherwise, this will be closed in 7 days.