Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST][FLAKY] topi/tests/python/test_topi_sort.py::test_argsort #4891

Merged
merged 4 commits into from
Feb 21, 2020

Conversation

cchung100m
Copy link
Contributor

Hi @tqchen ,

Following issue #4860 , I sort the array and then shuffle it, I would appreciate if you can give some suggestions/review for this PR, thank you.

@tqchen
Copy link
Member

tqchen commented Feb 15, 2020

in order to avoid ties, we might need to take an array whose element is sufficient apart, e.g. range(n)

@cchung100m
Copy link
Contributor Author

Hi @tqchen

I just update the PR. I am not sure if I understand the suggestion correctly, I would appreciate that you can describe it further.

Sorry for any inconvenience.

many thanks,

@tqchen
Copy link
Member

tqchen commented Feb 16, 2020

OK, sorry for not being clear, the root problem is potential ties in the value generated by np.random(two values too close to each other). So one way to avoid that is only generate random value that we know won't have ties. For example

np.shuffle(range(n))

Then we can use this as input data to test argsort

@cchung100m
Copy link
Contributor Author

Hi @tqchen

Thanks for the prompt reply and explanation.

I shuffle index and get data from the shuffled index.

@@ -27,6 +27,12 @@ def verify_argsort(axis, is_ascend):
data_dtype = "float32"
data = tvm.placeholder(dshape, name="data", dtype=data_dtype)
np_data = np.random.uniform(size=dshape).astype(data_dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove np_data here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the output nd.array of numpy.random.uniform?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np data is provided in the next few lines, this line is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think np_data is needed by the following lines, like L32 and L37, but please correct me if I’m wrong on that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry I was a bit confused here. The shuffling here still does not address the problem of ties(two values too close to each other in random.uniform).

We should instead change this line to directly create arange then broadcast to the shape, then we shuffle each of the broadcasted place.

Then the problem will be solved because arange won't have ties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apology for the misunderstanding. I update that part you mentioned and the test results as shown below:

>>> perm = np.arange(dshape[0] * dshape[1], dtype=data_dtype)
>>> np.random.shuffle(perm)
>>> np_data = perm.reshape(dshape)
>>> np_data
array([[22., 23., 10., 18., 12.],
       [16., 20.,  6., 21.,  1.],
       [24.,  7.,  4., 15., 13.],
       [14.,  5.,  8., 19., 11.],
       [ 9.,  3.,  0.,  2., 17.]], dtype=float32)

@tqchen tqchen added the status: need update need update based on feedbacks label Feb 18, 2020
@@ -27,6 +27,12 @@ def verify_argsort(axis, is_ascend):
data_dtype = "float32"
data = tvm.placeholder(dshape, name="data", dtype=data_dtype)
np_data = np.random.uniform(size=dshape).astype(data_dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry I was a bit confused here. The shuffling here still does not address the problem of ties(two values too close to each other in random.uniform).

We should instead change this line to directly create arange then broadcast to the shape, then we shuffle each of the broadcasted place.

Then the problem will be solved because arange won't have ties

@tqchen tqchen merged commit 8290eab into apache:master Feb 21, 2020
@tqchen tqchen added status: accepted and removed status: need update need update based on feedbacks labels Feb 21, 2020
@cchung100m cchung100m deleted the fix_ci_test_argsort branch February 22, 2020 02:39
@cchung100m
Copy link
Contributor Author

Hi @tqchen

Thanks for your patience and I did learn a lot from this task. :)

alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 26, 2020
…he#4891)

* [TEST][FLAKY] topi/tests/python/test_topi_sort.py::test_argsort

* upadate test function of argsort like topk

* Shuffle index and get data from shuffled index

* Replace the random.uniform with np.arange
alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 28, 2020
…he#4891)

* [TEST][FLAKY] topi/tests/python/test_topi_sort.py::test_argsort

* upadate test function of argsort like topk

* Shuffle index and get data from shuffled index

* Replace the random.uniform with np.arange
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2020
…he#4891)

* [TEST][FLAKY] topi/tests/python/test_topi_sort.py::test_argsort

* upadate test function of argsort like topk

* Shuffle index and get data from shuffled index

* Replace the random.uniform with np.arange
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants