This is an automated email from the ASF dual-hosted git repository.

marcoabreu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 1bd9356  [MXNET-771] Fix Flaky Test test_executor.py:test_dot (#11978)
1bd9356 is described below

commit 1bd9356b30ecde412663d0020ed769042cf456d6
Author: Lai Wei <[email protected]>
AuthorDate: Thu Aug 2 10:11:17 2018 -0700

    [MXNET-771] Fix Flaky Test test_executor.py:test_dot (#11978)
    
    * use assert_almost_equal, increase rtol, reduce matrix size
    
    * remove seed in test_bind
    
    * add seed 0 to test_bind, it is still flaky
    
    * add comments for tracking
---
 tests/python/unittest/test_executor.py | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/tests/python/unittest/test_executor.py 
b/tests/python/unittest/test_executor.py
index 630cad8..3117f66 100644
--- a/tests/python/unittest/test_executor.py
+++ b/tests/python/unittest/test_executor.py
@@ -18,13 +18,7 @@
 import numpy as np
 import mxnet as mx
 from common import setup_module, with_seed, teardown
-
-
-def reldiff(a, b):
-    diff = np.sum(np.abs(a - b))
-    norm = np.sum(np.abs(a))
-    reldiff = diff  / norm
-    return reldiff
+from mxnet.test_utils import assert_almost_equal
 
 
 def check_bind_with_uniform(uf, gf, dim, sf=None, lshape=None, rshape=None):
@@ -64,9 +58,9 @@ def check_bind_with_uniform(uf, gf, dim, sf=None, 
lshape=None, rshape=None):
     out1 = uf(lhs_arr.asnumpy(), rhs_arr.asnumpy())
     out3 = exec3.outputs[0].asnumpy()
     out4 = exec4.outputs[0].asnumpy()
-    assert reldiff(out1, out2) < 1e-6
-    assert reldiff(out1, out3) < 1e-6
-    assert reldiff(out1, out4) < 1e-6
+    assert_almost_equal(out1, out2, rtol=1e-5, atol=1e-5)
+    assert_almost_equal(out1, out3, rtol=1e-5, atol=1e-5)
+    assert_almost_equal(out1, out4, rtol=1e-5, atol=1e-5)
     # test gradient
     out_grad = mx.nd.array(np.ones(out2.shape))
     lhs_grad2, rhs_grad2 = gf(out_grad.asnumpy(),
@@ -74,8 +68,8 @@ def check_bind_with_uniform(uf, gf, dim, sf=None, 
lshape=None, rshape=None):
                               rhs_arr.asnumpy())
     executor.backward([out_grad])
 
-    assert reldiff(lhs_grad.asnumpy(), lhs_grad2) < 1e-6
-    assert reldiff(rhs_grad.asnumpy(), rhs_grad2) < 1e-6
+    assert_almost_equal(lhs_grad.asnumpy(), lhs_grad2, rtol=1e-5, atol=1e-5)
+    assert_almost_equal(rhs_grad.asnumpy(), rhs_grad2, rtol=1e-5, atol=1e-5)
 
 
 @with_seed(0)
@@ -118,12 +112,14 @@ def test_bind():
     check_bind(False)
 
 
-@with_seed(0)
+# @roywei: Removing fixed seed as flakiness in this test is fixed
+# tracked at https://github.com/apache/incubator-mxnet/issues/11686
+@with_seed()
 def test_dot():
     nrepeat = 10
     maxdim = 4
     for repeat in range(nrepeat):
-        s =tuple(np.random.randint(1, 500, size=3))
+        s =tuple(np.random.randint(1, 200, size=3))
         check_bind_with_uniform(lambda x, y: np.dot(x, y),
                                 lambda g, x, y: (np.dot(g, y.T), np.dot(x.T, 
g)),
                                 2,
@@ -131,7 +127,7 @@ def test_dot():
                                 rshape=(s[1], s[2]),
                                 sf = mx.symbol.dot)
     for repeat in range(nrepeat):
-        s =tuple(np.random.randint(1, 500, size=1))
+        s =tuple(np.random.randint(1, 200, size=1))
         check_bind_with_uniform(lambda x, y: np.dot(x, y),
                                 lambda g, x, y: (g * y, g * x),
                                 2,

Reply via email to