Skip to content

Conversation

@vishwakftw
Copy link
Contributor

@vishwakftw vishwakftw commented Nov 9, 2019

Changelog:

  • Expose is_signed for torch.dtype by modifying torch/csrc/Dtype.cpp
  • Allow half, bfloat16 and bool to also been "known" by the isSignedType function

Test Plan:

  • Add tests in test/test_torch.py

Closes #29475

Changelog:
- Expose is_signed for torch.dtype by modifying torch/csrc/Dtype.cpp
- Allow bfloat16 and bool to also been "known" by the isSignedType function

Test Plan:
- Add tests in test/test_torch.py
@vishwakftw vishwakftw requested review from albanD and nairbv November 9, 2019 22:54
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Thanks making the changes!

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.

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

Copy link
Collaborator

@nairbv nairbv left a comment

Choose a reason for hiding this comment

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

Thanks!

@vishwakftw
Copy link
Contributor Author

@albanD is this good to be merged?

@albanD
Copy link
Collaborator

albanD commented Nov 13, 2019

@vishwakftw Sorry I was checking with the people working on BFloat16 to make sure this special case was useful.
Given this I think you don't need this special case, and you can add it back to the main macro :)

@vishwakftw
Copy link
Contributor Author

Sure, thanks @albanD.

Just a side note, I think you might have tagged the wrong person.

@albanD
Copy link
Collaborator

albanD commented Nov 13, 2019

Yes, my bad, fixed that.
This will be good to merge once you do the change.

@vishwakftw
Copy link
Contributor Author

@albanD I've fixed it. Thanks for the pointer about BFloat16.

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.

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

@vishwakftw
Copy link
Contributor Author

vishwakftw commented Nov 14, 2019

@albanD is this good to merge? I see some failing internal tests.

@albanD
Copy link
Collaborator

albanD commented Nov 14, 2019

Yes, I was waiting for all the tests to run, failures are unrelated.

@facebook-github-bot
Copy link
Contributor

@albanD merged this pull request in 69e343f.

csarofeen pushed a commit to mruberry/pytorch that referenced this pull request Nov 18, 2019
Summary:
Changelog:
- Expose is_signed for torch.dtype by modifying torch/csrc/Dtype.cpp
- Allow half, bfloat16 and bool to also been "known" by the isSignedType function
Pull Request resolved: pytorch#29511

Test Plan:
- Add tests in test/test_torch.py

Closes pytorch#29475

Differential Revision: D18439030

Pulled By: albanD

fbshipit-source-id: 4b1f9da70c1c8dfd0a5bc028b6936acd1c64af47
@gchanan
Copy link
Contributor

gchanan commented Nov 26, 2019

Umm...are quantized dtypes signed? It's not clear to me that the underlying dtype is relevant here, that's just a representation, i.e. I believe you can have negative values with a quint8 dtype. Is that correct @jerryzh168 ?

@jerryzh168
Copy link
Contributor

Umm...are quantized dtypes signed? It's not clear to me that the underlying dtype is relevant here, that's just a representation, i.e. I believe you can have negative values with a quint8 dtype. Is that correct @jerryzh168 ?

yeah, quint8 dtype can represent negative floating point values, since we have scale and zero_point as well.

@jerryzh168
Copy link
Contributor

We need to know how is_signed is used first, then we can decide what should be is_signed for quantized dtypes

@nairbv
Copy link
Collaborator

nairbv commented Nov 26, 2019

We need to know how is_signed is used first, then we can decide what should be is_signed for quantized dtypes

Should we change this to throw an error for quantized types until we figure it out? The idea is for this to be usable from python, so could be used for anything. Within PyTorch I think so-far it's only used in this unit test:
https://github.com/pytorch/pytorch/pull/29231/files#diff-9996665f82f52030836eb8657057cfadR2645

@jerryzh168
Copy link
Contributor

@nairbv yeah looks like is_signed doesn't make sense for quantized dtype in this case, we should throw an error if people call is_signed for quantized dtypes.

@nairbv
Copy link
Collaborator

nairbv commented Nov 27, 2019

@gchanan how do we feel about having access to a property raise an error? The behavior of torch.qint8.is_signed raising an error seems a bit odd to me where there's no function call, though should be an easy change to make.

@nairbv
Copy link
Collaborator

nairbv commented Nov 27, 2019

though should be an easy change to make.

Actually it seems if you throw an error during a property access it dumps core.

nairbv added a commit that referenced this pull request Nov 27, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

[ghstack-poisoned]
nairbv added a commit that referenced this pull request Nov 27, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

ghstack-source-id: fffc818
Pull Request resolved: #30527
@nairbv
Copy link
Collaborator

nairbv commented Nov 27, 2019

Nevermind, got it working:

#30527

Still seems a bit weird to me though to raise an error on an attribute, without a function call.

nairbv added a commit that referenced this pull request Dec 2, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

[ghstack-poisoned]
nairbv added a commit that referenced this pull request Dec 2, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

[ghstack-poisoned]
nairbv added a commit that referenced this pull request Dec 2, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

ghstack-source-id: 4ccb037
Pull Request resolved: #30527
nairbv added a commit that referenced this pull request Dec 2, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

Differential Revision: [D18765410](https://our.internmc.facebook.com/intern/diff/D18765410)
nairbv added a commit that referenced this pull request Dec 2, 2019
Summary:

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

ghstack-source-id: 3b2d4db
Pull Request resolved: #30527
facebook-github-bot pushed a commit that referenced this pull request Dec 3, 2019
Summary:
Pull Request resolved: #30527

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at #29511

Test Plan: Imported from OSS

Differential Revision: D18765410

Pulled By: nairbv

fbshipit-source-id: c87cfe999b604cfcbbafa561e04d0d5cdbf41e6d
@vishwakftw vishwakftw deleted the expose-is_signed branch December 20, 2019 19:25
wuhuikx pushed a commit to wuhuikx/pytorch that referenced this pull request Jan 30, 2020
Summary:
Pull Request resolved: pytorch#30527

When we introduced dtype.is_signed we allowed for support of
quantized types, but we're not sure what the correct result should be.

See discussion at pytorch#29511

Test Plan: Imported from OSS

Differential Revision: D18765410

Pulled By: nairbv

fbshipit-source-id: c87cfe999b604cfcbbafa561e04d0d5cdbf41e6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose a dtype.is_signed

7 participants