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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

topk() cannot be used with complex or bool type of a 0D(only cuda) or more D tensor but topk() can be used with complex or bool type of a 0D(only cpu) tensor #126659

Open
hyperkai opened this issue May 20, 2024 · 1 comment
Labels
actionable module: edge cases Adversarial inputs unlikely to occur in practice triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@hyperkai
Copy link

hyperkai commented May 20, 2024

馃悰 Describe the bug

It seems like topk() cannot be used with complex or bool type of a 0D(only cuda) or more D tensor according to the errors as shown below:

complex type of a 0D(only cuda) tensor:

import torch

my_tensor = torch.tensor(0.+0.j, device='cuda:0')

torch.topk(input=my_tensor, k=1) # RuntimeError: "topk_out_cuda" not implemented for 'ComplexFloat'

bool type of a 0D(only cuda) tensor:

import torch

my_tensor = torch.tensor(True, device='cuda:0')

torch.topk(input=my_tensor, k=1) # RuntimeError: "topk_out_cuda" not implemented for 'Bool'

complex type of a 1D tensor:

import torch

my_tensor = torch.tensor([0.+0.j, 1.+0.j, 2.+0.j], device='cpu')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_cpu" not implemented for 'ComplexFloat'

my_tensor = torch.tensor([0.+0.j, 1.+0.j, 2.+0.j], device='cuda:0')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_out_cuda" not implemented for 'ComplexFloat'

bool type of a 1D tensor:

import torch

my_tensor = torch.tensor([True, False, True], device='cpu')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_cpu" not implemented for 'Bool'

my_tensor = torch.tensor([True, False, True], device='cuda:0')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_out_cuda" not implemented for 'Bool'

complex type of a 2D tensor:

import torch

my_tensor = torch.tensor([[0.+0.j, 1.+0.j], [2.+0.j, 3.+0.j]], device='cpu')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_cpu" not implemented for 'ComplexFloat'

my_tensor = torch.tensor([[0.+0.j, 1.+0.j], [2.+0.j, 3.+0.j]], device='cuda:0')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_out_cuda" not implemented for 'ComplexFloat'

bool type of a 2D tensor:

import torch

my_tensor = torch.tensor([[True, False], [False, True]],  device='cpu')

torch.topk(input=my_tensor, k=2)  # RuntimeError: "topk_cpu" not implemented for 'Bool'

my_tensor = torch.tensor([[True, False], [False, True]],  device='cuda:0')

torch.topk(input=my_tensor, k=2) # RuntimeError: "topk_out_cuda" not implemented for 'Bool'

But topk() can be used with complex or bool type of a 0D(only cpu) tensor as shown below:

complex type of a 0D(only cpu) tensor:

import torch

my_tensor = torch.tensor(0.+0.j, device='cpu')

torch.topk(input=my_tensor, k=1)
# torch.return_types.topk(
# values=tensor(0.+0.j),
# indices=tensor(0))

my_tensor = torch.tensor(0.+0.j, device='cuda:0')

torch.topk(input=my_tensor, k=1) # RuntimeError: "topk_out_cuda" not implemented for 'ComplexFloat'

bool type of a 0D tensor:

import torch

my_tensor = torch.tensor(True, device='cpu')

torch.topk(input=my_tensor, k=1)
# torch.return_types.topk(
# values=tensor(True),
# indices=tensor(0))

Versions

import torch

torch.__version__ # 2.2.1+cu121
@drisspg drisspg added triage review actionable module: edge cases Adversarial inputs unlikely to occur in practice and removed triage review labels May 20, 2024
@malfet malfet added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 20, 2024
@malfet
Copy link
Contributor

malfet commented May 20, 2024

We would accept a PR that errors out even on empty, single element tensors if dtype are complex or boolean types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable module: edge cases Adversarial inputs unlikely to occur in practice triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants