Skip to content

Commit

Permalink
fix flaky test: test_broadcast_binary_op (apache#11875)
Browse files Browse the repository at this point in the history
* cast inputs to f32

* retrigger

* retrigger

* remove extra cast

* remove commented out function

* retrigger
  • Loading branch information
azai91 authored and anirudh2290 committed Sep 19, 2018
1 parent 8546ea1 commit bd409d8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,6 @@ def test_bmod(a, b):
#c = a % b
c = mx.sym.cast(a, dtype='float64') % mx.sym.cast(b, dtype='float64')
# '%' is sensitive to the precision of the calculation. Force numpy to match mxnet's float32.
#check_binary_op_forward(c, lambda a, b: np.float32(a) % np.float32(b), gen_binary_data)
check_binary_op_forward(c, lambda a, b: np.float32(a) % np.float32(b), gen_binary_data, rtol=0, atol=0)
check_binary_op_backward(c,
lambda g_out, a, b: (g_out, - g_out * (np.float32(a) // np.float32(b))), gen_binary_data)
Expand Down Expand Up @@ -1913,10 +1912,16 @@ def test_bdiv(a, b):
check_binary_op_forward(c, lambda a, b: a / b, gen_broadcast_data, mx_nd_func=mx.nd.divide)
check_binary_op_backward(c, lambda g_out, a, b: (g_out / b, - g_out * a / (b * b)), gen_broadcast_data)

def test_bmod(a, b):
def test_bmod(a_, b_):
# Python and numpy operate only in double so to avoid numerical errors we have to use
# doubles as well. This was a flaky test before when using float32. seed 1688524483, 1768433044
a = mx.sym.cast(a_, dtype='float64')
b = mx.sym.cast(b_, dtype='float64')
# '%' is sensitive to the precision of the calculation. Force numpy to match mxnet's float32.
c = mx.sym.broadcast_mod(a, b)
check_binary_op_forward(c, lambda a, b: a % b, gen_broadcast_data, atol=1, mx_nd_func=mx.nd.modulo)
check_binary_op_backward(c, lambda g_out, a, b: (g_out, - g_out * (a // b)), gen_broadcast_data, atol=1)
check_binary_op_backward(c,
lambda g_out, a, b: (g_out, - g_out * (np.float32(a) // np.float32(b))), gen_binary_data)

def test_bmod_int(a, b):
c = mx.sym.broadcast_mod(mx.sym.cast(a, dtype='int32'), mx.sym.cast(b, dtype='int32'))
Expand Down Expand Up @@ -1974,13 +1979,7 @@ def test_bxor(a, b):
test_bminus(a, b)
test_bmul(a, b)
test_bdiv(a, b)
'''
Flaky Test Disabled due to master build failure:
http://jenkins.mxnet-ci.amazon-ml.com/blue/organizations/jenkins/incubator-mxnet/detail/master/1248/pipeline
Github Issue: https://github.com/apache/incubator-mxnet/issues/11838
test_bmod(a, b)
'''
test_bmod_int(a, b)
test_bpow(a, b)
test_bequal(a, b)
Expand Down

0 comments on commit bd409d8

Please sign in to comment.