-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Expose is_signed for dtype #29511
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
Expose is_signed for dtype #29511
Conversation
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
albanD
left a comment
There was a problem hiding this 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!
facebook-github-bot
left a comment
There was a problem hiding this 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.
nairbv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
@albanD is this good to be merged? |
|
@vishwakftw Sorry I was checking with the people working on BFloat16 to make sure this special case was useful. |
|
Sure, thanks @albanD. Just a side note, I think you might have tagged the wrong person. |
|
Yes, my bad, fixed that. |
|
@albanD I've fixed it. Thanks for the pointer about BFloat16. |
facebook-github-bot
left a comment
There was a problem hiding this 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.
|
@albanD is this good to merge? I see some failing internal tests. |
|
Yes, I was waiting for all the tests to run, failures are unrelated. |
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
|
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. |
|
We need to know how |
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: |
|
@nairbv yeah looks like |
|
@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. |
Actually it seems if you throw an error during a property access it dumps core. |
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]
|
Nevermind, got it working: Still seems a bit weird to me though to raise an error on an attribute, without a function call. |
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]
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]
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)
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
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
Changelog:
Test Plan:
Closes #29475