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

[known issue] kthvalue not available on CUDA #2134

Closed
vadimkantorov opened this issue Jul 17, 2017 · 6 comments
Closed

[known issue] kthvalue not available on CUDA #2134

vadimkantorov opened this issue Jul 17, 2017 · 6 comments

Comments

@vadimkantorov
Copy link
Contributor

vadimkantorov commented Jul 17, 2017

torch.arange(1, 10).cuda().kthvalue(5) will throw

A known issue (https://discuss.pytorch.org/t/missing-kthvalue-on-gpu/1798/2)

@vadimkantorov vadimkantorov changed the title kthvalue not available on CUDA [known issue] kthvalue not available on CUDA Jul 17, 2017
@apaszke
Copy link
Contributor

apaszke commented Jul 17, 2017

A workaround for now would be to use topk. It should be very fast.

def kthvalue(tensor, k, dim=None):
    val, idx = tensor.topk(k, dim)
    return val[:1], idx[:1]

@vadimkantorov
Copy link
Contributor Author

vadimkantorov commented Jul 17, 2017

kthvalue returns k'th smallest element, while topk returns by default largest elements. So a workaround should be:

 # dim = None wouldn't work because topk requires a dim argument if largest = False is used
def kthvalue(tensor, k, dim=-1):
    val, idx = tensor.topk(k, largest = False, dim = dim)
    return val[-1:], idx[-1:]

@AnishShah
Copy link

Hi, can I work on this?

@soumith
Copy link
Member

soumith commented Jul 25, 2017

sure thing @AnishShah !

@soumith soumith added this to Uncategorized in Issue Status Aug 23, 2017
@soumith soumith moved this from Uncategorized to Medium Priority in Issue Status Aug 23, 2017
@soumith soumith added this to nn / autograd / torch in Issue Categories Aug 31, 2017
@vadimkantorov
Copy link
Contributor Author

fix worked on in #8406

@vadimkantorov
Copy link
Contributor Author

Fixed in #17544

xwang233 pushed a commit to xwang233/pytorch that referenced this issue Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Issue Categories
neural-nets
Issue Status
Medium Priority
Development

No branches or pull requests

4 participants