-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1401] adding more operators to test support for Large Tensor #14944
Conversation
@mxnet-label-bot add [pr-work-in-progress] |
@mxnet-label-bot add [pr-awaiting-review] |
@apeforest please review |
tests/nightly/test_large_array.py
Outdated
@@ -28,7 +28,6 @@ | |||
SMALL_Y = 50 | |||
LARGE_SIZE = LARGE_X * SMALL_Y | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep it. It's Pep8 style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Are you referring to this: https://www.python.org/dev/peps/pep-0008/#blank-lines
Please verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
tests/nightly/test_large_array.py
Outdated
@@ -37,26 +36,31 @@ def test_gluon_embedding(): | |||
assert b.shape == (MEDIUM_X, SMALL_Y, MEDIUM_X) | |||
assert b.asnumpy().size == LARGE_SIZE | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep it. It's Pep8 style
tests/nightly/test_large_array.py
Outdated
def test_ndarray_zeros(): | ||
a = nd.zeros(shape=(LARGE_X, SMALL_Y)) | ||
assert a[-1][0] == 0 | ||
assert a.shape == (LARGE_X, SMALL_Y) | ||
assert a.size == LARGE_SIZE | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep it. It's Pep8 style
tests/nightly/test_large_array.py
Outdated
|
||
|
||
def test_argmin(): | ||
a = nd.arange(0, LARGE_X).reshape(LARGE_X, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to broadcast? Can we just create a super long array and perform argmin?
tests/nightly/test_large_array.py
Outdated
|
||
def test_take(): | ||
a = nd.ones(shape=(LARGE_X, SMALL_Y)) | ||
idx = nd.arange(LARGE_X-1000, LARGE_X) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add space between LARGE_X and -
@@ -217,6 +260,33 @@ def numpy_space_to_depth(x, blocksize): | |||
output = mx.nd.space_to_depth(data, 2) | |||
assert_almost_equal(output.asnumpy(), expected, atol=1e-3, rtol=1e-3) | |||
|
|||
|
|||
def test_diag(): | |||
h = np.random.randint(2,9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use randint? Can we just use deterministic values to test diag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apeforest : using random values is better since we are checking diagonal. Having different values actually ensures that the operation is performed correctly. Checking just the shape is fine but this ensures total correctness. I think if we can perform this check then it ensures total correctness
26f85d3
to
41df5d6
Compare
tests/nightly/test_large_array.py
Outdated
a = nd.arange(0, LARGE_X * SMALL_Y).reshape(LARGE_X, SMALL_Y) | ||
outs = nd.split(a, num_outputs=SMALL_Y, axis=1) | ||
sum = 0 | ||
for i, out in enumerate(outs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may make this more pythonic:
for i, out in enumerate(outs): | |
result = sum(1 for i, v in enumerate(outs) if i == v) |
You also need to convert outs into outs.asnumpy() first in the line above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
def test_diag(): | ||
h = np.random.randint(2,9) | ||
w = np.random.randint(2,9) | ||
a_np = np.random.random((LARGE_X, 64)).astype(np.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to convert to np.float32 explicitly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apeforest by default np.random.random((LARGE_X, 64))
makes it float64 by default.
x = np.random.random((50000000, 64))
x
array([[0.77259927, 0.17861939, 0.73446367, ..., 0.61712618, 0.00411382,
0.80232583],
[0.99131563, 0.29269588, 0.34078989, ..., 0.14693316, 0.68376766,
0.13507782],
[0.26176515, 0.54208053, 0.42594753, ..., 0.76032471, 0.30179728,
0.83745653],
...,
[0.45731445, 0.84679834, 0.02738181, ..., 0.27567623, 0.94721731,
0.77850831],
[0.65551258, 0.92503922, 0.43253718, ..., 0.23874736, 0.55155928,
0.33177961],
[0.95565209, 0.86454407, 0.75257631, ..., 0.31738383, 0.90281116,
0.93569039]])
x.dtype
dtype('float64')
I am trying to keep it consistent with: https://github.com/apache/incubator-mxnet/blob/f680255fbff25818ed3eee0d4541d80b3c7b9d9d/tests/python/unittest/test_operator.py#L8029
So, I think float32 is required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. mx.nd.array(a_np) is float32 by default.
y = mx.nd.array(x)
y.dtype
<class 'numpy.float32'>
I will remove astype('float32')
from next line
tests/nightly/test_large_array.py
Outdated
assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k)) | ||
|
||
# random k | ||
k = np.random.randint(-min(LARGE_X,64) + 1, min(h,w)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add space after comma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
tests/nightly/test_large_array.py
Outdated
assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k)) | ||
|
||
# random k | ||
k = np.random.randint(-min(LARGE_X, 64) + 1, min(h,w)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same between h and w
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Test to check support for operators: tostype, split, argmin, tile, take and diag
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.