Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix flaky test test_custom_op_exc #14878

Merged
merged 1 commit into from
May 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5467,33 +5467,6 @@ def infer_shape(self, in_shape):
def create_operator(self, ctx, shapes, dtypes):
return Dot()

def _custom_exc3(seed):
def custom_exc3():
def f(in_data, out_data):
out_data[0][:] = mx.nd.dot(in_data[0], in_data[1])
out_data[0].wait_to_read()
_build_dot_custom(f, 'Dot3')
n = int(1e8)
a = mx.nd.zeros((n, 1))
b = mx.nd.zeros((1, n))
# trigger OOM
c = mx.nd.Custom(a, b, op_type='Dot3')
c.wait_to_read()
assert_raises(MXNetError, custom_exc3)

def _custom_exc4(seed):
def custom_exc4():
def f(in_data, out_data):
out_data[0][:] = mx.nd.dot(in_data[0], in_data[1])
_build_dot_custom(f, 'Dot4')
n = int(1e8)
a = mx.nd.zeros((n, 1))
b = mx.nd.zeros((1, n))
# trigger OOM
c = mx.nd.Custom(a, b, op_type='Dot4')
c.wait_to_read()
assert_raises(MXNetError, custom_exc4)

@with_seed()
def test_custom_op_exc():
# test except handling
Expand Down Expand Up @@ -5523,8 +5496,35 @@ def f(in_data, out_data):
assert_raises(MXNetError, custom_exc2)

# 3. error in real execution
run_in_spawned_process(_custom_exc3, {})
run_in_spawned_process(_custom_exc4, {})
if default_context().device_type == 'cpu':
def custom_exc3():
def f(in_data, out_data):
dot = mx.nd.dot(in_data[0], in_data[1])
# input to Cholesky factorization should be
# symmetric positive-definite, error will be
# triggered in op execution on cpu
out_data[0][:] = mx.nd.linalg.potrf(dot)
out_data[0].wait_to_read()
_build_dot_custom(f, 'Dot3')
a = mx.nd.zeros((2, 1))
b = mx.nd.zeros((1, 2))
c = mx.nd.Custom(a, b, op_type='Dot3')
c.wait_to_read()
assert_raises(MXNetError, custom_exc3)

def custom_exc4():
def f(in_data, out_data):
dot = mx.nd.dot(in_data[0], in_data[1])
# input to Cholesky factorization should be
# symmetric positive-definite, error will be
# triggered in op execution on cpu
out_data[0][:] = mx.nd.linalg.potrf(dot)
_build_dot_custom(f, 'Dot4')
a = mx.nd.zeros((2, 1))
b = mx.nd.zeros((1, 2))
c = mx.nd.Custom(a, b, op_type='Dot4')
c.wait_to_read()
assert_raises(MXNetError, custom_exc4)


@with_seed()
Expand Down