Skip to content

Add int1 to int7 dtypes#136301

Closed
jerryzh168 wants to merge 5 commits into
gh/jerryzh168/853/basefrom
gh/jerryzh168/853/head
Closed

Add int1 to int7 dtypes#136301
jerryzh168 wants to merge 5 commits into
gh/jerryzh168/853/basefrom
gh/jerryzh168/853/head

Conversation

@jerryzh168

@jerryzh168 jerryzh168 commented Sep 19, 2024

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization (https://www.internalfb.com/diff/D62464487)

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the release notes: quantization release notes category label Sep 19, 2024
@pytorch-bot

pytorch-bot Bot commented Sep 19, 2024

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/136301

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit c42b2de with merge base 86631ec (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@jerryzh168 jerryzh168 requested review from albanD and ezyang September 19, 2024 03:03
@jerryzh168 jerryzh168 changed the title Add int1 to int7 dtypes #117208 Add int1 to int7 dtypes Sep 19, 2024
Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Sep 19, 2024
Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: e2c23c7
Pull Request resolved: #136301
@ezyang

ezyang commented Sep 19, 2024

Copy link
Copy Markdown
Contributor

Can you explain in more detail why the signed types are desirable?

@jerryzh168

Copy link
Copy Markdown
Contributor Author

@ezyang it's used in edge low bit kernels to represent weight: https://www.internalfb.com/diff/D62464487

TBH, I think it we can extend torch.dtype out of core, it's probably better, but my impression is that we can't do that right now

Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization (https://www.internalfb.com/diff/D62464487)

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Sep 19, 2024
Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: c71df2e
Pull Request resolved: #136301
@jerryzh168

jerryzh168 commented Sep 19, 2024

Copy link
Copy Markdown
Contributor Author

actually we can delay this PR I think, since we have been uint8 right now for uintx as well: https://github.com/pytorch/ao/blob/53b6b787bb035f1abc3c4804dd22c09ee41e7a0d/torchao/dtypes/uintx/uintx.py#L66, we just need to add some placeholder dtypes in torchao in this case, although it is more convenient to be able to do torch.intx without importing anything.

@ezyang

ezyang commented Sep 20, 2024

Copy link
Copy Markdown
Contributor

It's coherent to support this type but it's pretty unlikely for, e.g., signed int1 to be a useful concept, you would only have the elements -1 and 0. So I would like at least like a little more concrete evidence you can't use the uint types instead

@jerryzh168

Copy link
Copy Markdown
Contributor Author

@ezyang you mean just for int1 or other intx dtypes as well? I agree int1 is probably not very useful. but cc @metascroy and also @kimishpatel to see if there are more context here for the need intx dtypes (especially int1).

@ezyang

ezyang commented Sep 21, 2024

Copy link
Copy Markdown
Contributor

For the larger int types, it seems to me that the biggest benefit you get over unsigned is access to signed operations. But this also isn't obviously that helpful; for example, in two's complement, you can implemented signed addition... as regular unsigned addition.

Obviously, exposing signed integers as a user facing abstraction is a legitimate thing to do, but my understanding of AO's use case is they would wrapped up in a tensor subclass anyway...

@kimishpatel kimishpatel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

left some comments

Comment thread c10/core/ScalarType.h
case ScalarType::UInt5:
case ScalarType::UInt6:
case ScalarType::UInt7:
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a bug before this pr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah I think so

assert quantized_tensor.int_repr().min().item() == q8_min

def test_uint1_7_dtype(self):
def test_uint4_int4_dtype(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what happened to the original test case?

@jerryzh168 jerryzh168 Sep 23, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

naming was a bit off, original test is testing uint4, and I added int4 in the PR

@kimishpatel

Copy link
Copy Markdown
Contributor

@ezyang so in general it is not clear why unsigned is treated different than signed? We have had this issue with uint16. So just from UX perspective it seems like an aberration that we have uintx types but not intx.

but my understanding of AO's use case is they would wrapped up in a tensor subclass anyway

I think this is fair and I am not sure for the kernels we actually need intx/uintx types at all if kernels are tied with quantization API. Meaning if we did not use AO API, and relied purely on exported IR to derive if some tensors are uintx/intx, then I think having this natively available in PyTorch makes sense.

But in general @ezyang what would be the objection given uintx are already present.

@jerryzh168

jerryzh168 commented Sep 23, 2024

Copy link
Copy Markdown
Contributor Author

I think this is fair and I am not sure for the kernels we actually need intx/uintx types at all if kernels are tied with quantization API. Meaning if we did not use AO API, and relied purely on exported IR to derive if some tensors are uintx/intx, then I think having this natively available in PyTorch makes sense.

yes all the operations are implemented with tensor subclass (currently just pack/unpack to/from uint8),

the biggest benefit you get over unsigned is access to signed operations.

main benefit right now is that we are using torch.uintx/torch.intx as user facing API so people don't need to maybe use (nbits: int, signed: bool) to express them

we are thinking of implementing tensor subclasses a bit later, since we need a "standard"/"default" packing format, and we want to have an efficient kernel for these before we decide on that

Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization (https://www.internalfb.com/diff/D62464487)

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
jerryzh168 added a commit that referenced this pull request Sep 25, 2024
Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: cd0264c
Pull Request resolved: #136301
@jerryzh168

Copy link
Copy Markdown
Contributor Author

@ezyang any ideas on the CI failure (https://github.com/pytorch/pytorch/actions/runs/11026420870/job/30727936288?pr=136301)? I can't repro locally

@ezyang

ezyang commented Sep 27, 2024

Copy link
Copy Markdown
Contributor

looks like master problem

@jerryzh168

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased gh/jerryzh168/853/orig onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/136301)

pytorchmergebot pushed a commit that referenced this pull request Sep 27, 2024
Summary:
Similar to #117208, we want to add int1 to int7 for edge use cases
for weight quantization

Test Plan:
python test/test_quantization.py -k test_uint4_int4_dtype

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 9979fb5
Pull Request resolved: #136301
@jerryzh168

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 27, 2024
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@PaliC

PaliC commented Sep 30, 2024

Copy link
Copy Markdown
Contributor

@pytorchbot revert -m "causing internal failures" -c "ghfirst"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@jerryzh168 your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request Sep 30, 2024
This reverts commit bfa16a1.

Reverted #136301 on behalf of https://github.com/PaliC due to causing internal failures ([comment](#136301 (comment)))
AnantGulati pushed a commit to AnantGulati/pytorch that referenced this pull request Oct 2, 2024
This reverts commit bfa16a1.

Reverted pytorch#136301 on behalf of https://github.com/PaliC due to causing internal failures ([comment](pytorch#136301 (comment)))
@jerryzh168

Copy link
Copy Markdown
Contributor Author

landed in #137928

@jerryzh168 jerryzh168 closed this Oct 18, 2024
@github-actions github-actions Bot deleted the gh/jerryzh168/853/head branch November 29, 2024 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: quantization release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants