-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-507] Set dtype=int32 for ret_indices in ordering ops #11134
Conversation
After discussing offline with Eric, I'll add an additional |
Feel free to remove "breaking" label when you're ready. |
I think that it would be helpful if a check for the ranges of the floating point types is added. The recent addtion of |
Thanks a lot! I was just looking for such a check.
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Deokjae Lee <notifications@github.com>
Sent: Monday, June 11, 2018 9:31:02 PM
To: apache/incubator-mxnet
Cc: Xingjian SHI; Author
Subject: Re: [apache/incubator-mxnet] [MXNET-507] Set dtype=int32 for ret_indices in ordering ops (#11134)
I think that it would be helpful if a check for the ranges of the floating point types is added. The recent addtion of dtype to multinomial implemented the check. https://github.com/apache/incubator-mxnet/blob/3eada3b32aeab5c8cdf7d507bcc3a986c9e5b91f/src/operator/random/sample_multinomial_op.h#L73-L76
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#11134 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AE8D7u7vceZYr3aWQORkAyQyQqv645Ntks5t7nEWgaJpZM4UYsvh>.
|
Is it okay to merge this in? |
DMLC_DECLARE_FIELD(dtype) | ||
.add_enum("uint8", mshadow::kUint8) | ||
.add_enum("int32", mshadow::kInt32) | ||
.add_enum("float16", mshadow::kFloat16) |
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.
should we remove this option given that it won't be supported?
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, I'll remove it.
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.
@szha Actually, the dtype of indices can be float16. There is no need to remove the option.
This reverts commit 30a4457.
@sxjscience any chance you could add a small update to the documentation saying that the output is sorted. thanks! |
Description
There are two problems in the ordering operators, i.e, topk, sort, argsort:
Only real_t is supported.
The indices are stored as real_t. This will cause error in the backward pass where the gradient are passed to the wrong locations.
For example, we can not run the following code in the previous version:
I propose to fix this bug by changing the dtype of indices to int32. This will make the code backward incompatible. However, it only breaks some rare usages. Normally we will directly output the indices or use them to slice a tensor. The current change do not break these common usages.(I have used the other solution mentioned below.)Another solution is to support an additional flag
dtype
for these operators (as suggested in #11031). The problem of this solution is that we cannot avoid a nested macro, which is extremely slow to compile. So I haven't solved it this way.This PR also fixes the issue reported in #10085 that ordering ops do not support kNullOp.
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments
This change is backward incompatible. However, I think it's reasonable to set the dtype of indices to int32 because it does not break the common usage where we use these indices to slice a tensor.The change is backward compatible now.