This is an automated email from the ASF dual-hosted git repository.
anirudh2290 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 c792638 Fix flaky test:test_sample_multinomial (#11366)
c792638 is described below
commit c7926383972b8988d2f6505443d3672f9ade70fa
Author: Anirudh Subramanian <[email protected]>
AuthorDate: Tue Jul 10 16:39:31 2018 -0700
Fix flaky test:test_sample_multinomial (#11366)
* Fix atol and tests
* Remove commented code
* Remove skip
---
tests/python/unittest/test_random.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/python/unittest/test_random.py
b/tests/python/unittest/test_random.py
index 3e648a5..d90dfcf 100644
--- a/tests/python/unittest/test_random.py
+++ b/tests/python/unittest/test_random.py
@@ -19,7 +19,7 @@ import os
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)