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

Enabled masked for a bool tensor #19140

Closed
wants to merge 5 commits into from
Closed

Conversation

izdeby
Copy link
Contributor

@izdeby izdeby commented Apr 11, 2019

Enabled masked methods them for a bool tensor.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@izdeby izdeby requested review from gchanan and ezyang April 11, 2019 14:22
@ezyang
Copy link
Contributor

ezyang commented Apr 11, 2019

So, how exactly is the deprecation cycle going to work? Are we going to change the behavior of these functions to do uint8 indexing eventually?

@izdeby
Copy link
Contributor Author

izdeby commented Apr 11, 2019

@ezyang, did you mean bool indexing? it works with uint8 now.

So the current plan looks like this:

  1. add deprecation warnings for existing methods
  2. [after release] replace byte masks (uint8) with bool.

@gchanan, correct me if im wrong, please.

@gchanan
Copy link
Contributor

gchanan commented Apr 11, 2019

it's not standard practice to deprecate things before the replacement is ready to use. I don't see a replacement ready to use here?

@izdeby
Copy link
Contributor Author

izdeby commented Apr 11, 2019

There are 2 options here:

  1. enable bool masks right now which will work alongside with byte masks, add deprecation warning that byte masks will be gone
  2. add deprecation warning that byte will be replaced with bool and do that after the release.

This PR implements the 2nd option as discussed offline. Should i go with the 1st option instead?

@gchanan
Copy link
Contributor

gchanan commented Apr 11, 2019

I must have misunderstood the options, then. It's not useful to provide deprecation warnings without replacements. As a user, there's nothing I can do with that information.

@izdeby
Copy link
Contributor Author

izdeby commented Apr 11, 2019

Sure, no problems, will switch to option #1.

@izdeby izdeby changed the title Enabled masked for a bool tensor [WIP] Enabled masked for a bool tensor Apr 11, 2019
aten/src/ATen/Declarations.cwrap Outdated Show resolved Hide resolved
aten/src/TH/generic/THTensorEvenMoreMath.cpp Outdated Show resolved Hide resolved
@izdeby izdeby force-pushed the maskedForBool branch 2 times, most recently from 957da21 to 9869e12 Compare April 15, 2019 19:37
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@izdeby izdeby changed the title [WIP] Enabled masked for a bool tensor Enabled masked for a bool tensor Apr 15, 2019
@izdeby izdeby requested a review from gchanan April 15, 2019 19:39
@izdeby
Copy link
Contributor Author

izdeby commented Apr 15, 2019

@ezyang @gchanan, added option to pass bool masks to masked methods. Initially i wanted to add just overloaded versions but that turned out to be very hard to do and would require adding a new dispatcher which seems too much to me as byte masks will be killed after the release.

aten/src/ATen/Utils.h Outdated Show resolved Hide resolved
aten/src/ATen/Declarations.cwrap Outdated Show resolved Hide resolved
aten/src/TH/generic/THTensorEvenMoreMath.cpp Outdated Show resolved Hide resolved
aten/src/THC/generic/THCTensorMasked.cu Outdated Show resolved Hide resolved
aten/src/THC/generic/THCTensorMasked.cu Outdated Show resolved Hide resolved
aten/src/THC/generic/THCTensorMasked.cu Outdated Show resolved Hide resolved
test/test_torch.py Outdated Show resolved Hide resolved
@izdeby izdeby changed the title Enabled masked for a bool tensor [WIP] Enabled masked for a bool tensor Apr 16, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@izdeby izdeby changed the title [WIP] Enabled masked for a bool tensor Enabled masked for a bool tensor Apr 16, 2019
@izdeby izdeby requested a review from gchanan April 16, 2019 19:07
@ezyang
Copy link
Contributor

ezyang commented Apr 17, 2019

@gchanan I'll let you review this, but let me know if you want me to look (I helped Iurii debug some issues while he was working on this patch.)

@ezyang ezyang removed their request for review April 17, 2019 20:09
Copy link
Contributor

@gchanan gchanan left a comment

Choose a reason for hiding this comment

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

why do you need sum ?

options:
- arguments:
- arg: THTensor* self
broadcast: mask inplace fallback types:Byte
Copy link
Contributor

Choose a reason for hiding this comment

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

this "types:Byte" thing looks questionable?

aten/src/ATen/Declarations.cwrap Outdated Show resolved Hide resolved
aten/src/TH/generic/THTensorEvenMoreMath.cpp Show resolved Hide resolved
aten/src/ATen/function_wrapper.py Show resolved Hide resolved
test/test_torch.py Outdated Show resolved Hide resolved
@izdeby izdeby requested a review from gchanan April 23, 2019 20:03
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

torch/_tensor_str.py Outdated Show resolved Hide resolved
test/test_torch.py Outdated Show resolved Hide resolved
@izdeby izdeby requested a review from gchanan April 25, 2019 16:35
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

aten/src/ATen/native/LegacyDefinitions.cpp Outdated Show resolved Hide resolved
// As we dispatch on self and TH is type-chcked, we need different definitions.
// This can be fixed by moving to ATen.
if (mask.dtype() == at::ScalarType::Byte) {
return at::legacy::th::_th_masked_fill_(self, mask, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

in a future PR, it might make sense to call the bool one masked_fill_ and the other one masked_fill_byte, since that is the end state, but not necessary for now.

aten/src/ATen/native/LegacyDefinitions.cpp Outdated Show resolved Hide resolved
@@ -165,6 +247,67 @@ void THCTensor_(maskedSelect)(THCState* state,
THCudaCheck(cudaGetLastError());
}

void THCTensor_(maskedSelectBool)(THCState* state,
Copy link
Contributor

Choose a reason for hiding this comment

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

also for the future: I think you could move these definitions into a non-generic function so you don't have to copy the code.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@izdeby has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Apr 29, 2019
Summary:
Added deprecation warnings for the masked methods and enabled them for a bool tensor.
Pull Request resolved: pytorch/pytorch#19140

Differential Revision: D14888021

Pulled By: izdeby

fbshipit-source-id: 0e42daf8f3732ca29f36d10485402bfc502716ad
@facebook-github-bot
Copy link
Contributor

@izdeby merged this pull request in de19eee.

zhangguanheng66 pushed a commit to zhangguanheng66/pytorch that referenced this pull request May 6, 2019
Summary:
Added deprecation warnings for the masked methods and enabled them for a bool tensor.
Pull Request resolved: pytorch#19140

Differential Revision: D14888021

Pulled By: izdeby

fbshipit-source-id: 0e42daf8f3732ca29f36d10485402bfc502716ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants