anirudh2290 closed pull request #11366: Fix flaky test:test_sample_multinomial
URL: https://github.com/apache/incubator-mxnet/pull/11366
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/python/unittest/test_random.py 
b/tests/python/unittest/test_random.py
index 3e648a5cbbd..d90dfcf856f 100644
--- a/tests/python/unittest/test_random.py
+++ b/tests/python/unittest/test_random.py
@@ -19,7 +19,7 @@
 import math
 import itertools
 import mxnet as mx
-from mxnet.test_utils import verify_generator, gen_buckets_probs_with_ppf
+from mxnet.test_utils import verify_generator, gen_buckets_probs_with_ppf, 
retry
 import numpy as np
 import random as rnd
 from common import setup_module, with_seed, random_seed, teardown
@@ -358,15 +358,15 @@ def test_parallel_random_seed_setting_for_context():
         for i in range(1, len(samples_sym)):
             assert same(samples_sym[i - 1], samples_sym[i])
 
+@retry(5)
 @with_seed()
[email protected]("Flaky test: 
https://github.com/apache/incubator-mxnet/issues/11487";)
 def test_sample_multinomial():
     for dtype in ['uint8', 'int32', 'float16', 'float32', 'float64']: # output 
array types
         for x in [mx.nd.array([[0,1,2,3,4],[4,3,2,1,0]])/10.0, 
mx.nd.array([0,1,2,3,4])/10.0]:
             dx = mx.nd.ones_like(x)
             mx.contrib.autograd.mark_variables([x], [dx])
             # Adding rtol and increasing samples needed to pass with seed 
2951820647
-            samples = 5000
+            samples = 10000
             with mx.autograd.record():
                 y, prob = mx.nd.random.multinomial(x, shape=samples, 
get_prob=True, dtype=dtype)
                 r = prob * 5
@@ -383,7 +383,7 @@ def test_sample_multinomial():
                 prob = prob.reshape((1, prob.shape[0]))
             for i in range(x.shape[0]):
                 freq = np.bincount(y[i,:].astype('int32'), 
minlength=5)/np.float32(samples)*x[i,:].sum()
-                mx.test_utils.assert_almost_equal(freq, x[i], rtol=0.20)
+                mx.test_utils.assert_almost_equal(freq, x[i], rtol=0.20, 
atol=1e-1)
                 rprob = x[i][y[i].astype('int32')]/x[i].sum()
                 mx.test_utils.assert_almost_equal(np.log(rprob), 
prob.asnumpy()[i], atol=1e-5)
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to