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

Please implement where_cpu and where_cuda for BoolTensors #26247

Closed
sshish opened this issue Sep 15, 2019 · 11 comments
Closed

Please implement where_cpu and where_cuda for BoolTensors #26247

sshish opened this issue Sep 15, 2019 · 11 comments
Assignees
Labels
function request A request for a new function or the addition of new arguments/modes to an existing function. module: boolean tensor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@sshish
Copy link

sshish commented Sep 15, 2019

🚀 Feature

mycudabooltensor.where(...)
returns:
RuntimeError: "where_cuda" not implemented for 'Bool'

Motivation

In order to do masked operations on bool tensors, I have to cast those to byte tensors first, which looks unelegant.

cc @izdeby

@cpuhrsch cpuhrsch added enhancement Not as big of a feature, but technically not a bug. Should be easy to fix feature A request for a proper, new feature. triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Sep 17, 2019
@izdeby izdeby self-assigned this Sep 18, 2019
facebook-github-bot pushed a commit that referenced this issue Sep 19, 2019
Summary:
Enabled "where_cuda" for bool tensors on CUDA
Fixing #26247
Tested via unit tests
Pull Request resolved: #26430

Differential Revision: D17464181

Pulled By: izdeby

fbshipit-source-id: cbb09925753b2e6f35e7400da3243d4d3fc86b69
zdevito pushed a commit to zdevito/ATen that referenced this issue Sep 19, 2019
Summary:
Enabled "where_cuda" for bool tensors on CUDA
Fixing pytorch/pytorch#26247
Tested via unit tests
Pull Request resolved: pytorch/pytorch#26430

Differential Revision: D17464181

Pulled By: izdeby

fbshipit-source-id: cbb09925753b2e6f35e7400da3243d4d3fc86b69
@izdeby
Copy link
Contributor

izdeby commented Sep 19, 2019

Done

@izdeby izdeby closed this as completed Sep 19, 2019
@TheodoreZhao
Copy link

There is also the same kind of problem on CPU.
RuntimeError: "where_cpu" not implemented for 'Bool'

@izdeby izdeby changed the title Please implement where_cuda for BoolTensors Please implement where_cpu and where_cuda for BoolTensors Oct 21, 2019
@izdeby
Copy link
Contributor

izdeby commented Oct 21, 2019

Reopening in order to fix the CPU path

@izdeby izdeby reopened this Oct 21, 2019
@izdeby
Copy link
Contributor

izdeby commented Oct 21, 2019

@TheodoreZhao, can you provide repro code? This should work.
Tested via

import torch
a = torch.tensor([True, False], device='cuda')
res = torch.where(a > 0)
print(res)


a = torch.tensor([True, False], device='cpu')
res = torch.where(a > 0)
print(res)

Output:
(tensor([0], device='cuda:0'),)
(tensor([0]),)

@izdeby izdeby closed this as completed Oct 21, 2019
@TheodoreZhao
Copy link

TheodoreZhao commented Oct 25, 2019

@izdeby It looks the types of x and y in torch.where(condition, x, y) cannot be BoolTensor.
https://pytorch.org/docs/stable/torch.html#torch.where

import torch
a = torch.tensor([True, False], device='cuda')
x = torch.tensor([True, True], device='cuda')
y = torch.tensor([False, False], device='cuda')
res = torch.where(a, x, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module> 
RuntimeError: "where_cuda" not implemented for 'Bool'
import torch
a = torch.tensor([True, False], device='cpu')
x = torch.tensor([True, True], device='cpu')
y = torch.tensor([False, False], device='cpu')
res = torch.where(a, x, y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module> 
RuntimeError: "where_cpu" not implemented for 'Bool'

@izdeby
Copy link
Contributor

izdeby commented Oct 28, 2019

Reopening while investigating

@izdeby izdeby reopened this Oct 28, 2019
@spacegoing
Copy link

Any update on this?

@izdeby
Copy link
Contributor

izdeby commented Sep 24, 2020

I have to fix this. Will do in next few days. sorry for the delay.

@genbei
Copy link

genbei commented Sep 28, 2020

我必须解决这个问题。将在未来几天内完成。抱歉耽搁了。

Have you solved it now? I have also encountered this problem

@mruberry mruberry added function request A request for a new function or the addition of new arguments/modes to an existing function. and removed enhancement Not as big of a feature, but technically not a bug. Should be easy to fix feature A request for a proper, new feature. module: operators (deprecated) labels Oct 8, 2020
@H-Huang
Copy link
Member

H-Huang commented Nov 7, 2020

Fixed in #47454

@H-Huang H-Huang closed this as completed Nov 7, 2020
@Hananel-Hazan
Copy link

Hananel-Hazan commented Dec 8, 2020

This issue still exist on PyTorch == 1.7 using cpu but seems to work find on cuda

On cpu:

import torch
a = torch.tensor([True, False], device='cpu')
x = torch.tensor([True, True], device='cpu')
y = torch.tensor([False, False], device='cpu')
res = torch.where(a, x, y)
File "<ipython-input-15-0d63a62ea507>", line 4, in <module>
res = torch.where(a, x, y)
RuntimeError: "where_cpu" not implemented for 'Bool'

On cuda:

import torch
a = torch.tensor([True, False], device='cuda')
x = torch.tensor([True, True], device='cuda')
y = torch.tensor([False, False], device='cuda')
res = torch.where(a, x, y)

Working as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function request A request for a new function or the addition of new arguments/modes to an existing function. module: boolean tensor triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants