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

Enable dispatch to tinygemm int4 and int8 kernels for quantized tensor #230

Merged
merged 1 commit into from
May 14, 2024

Conversation

jerryzh168
Copy link
Contributor

@jerryzh168 jerryzh168 commented May 8, 2024

Summary:
This adds some dispatch to the tinygemm kernels for cuda, although need to resolve implementation mismatch problem for tinygemm first

Test Plan:
TODO

Reviewers:

Subscribers:

Tasks:

Tags:

Copy link

pytorch-bot bot commented May 8, 2024

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 2a8dc5d with merge base e7bbbd2 (image):

NEW FAILURE - The following job has failed:

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 8, 2024
@jerryzh168 jerryzh168 changed the title Enable dispatch to tinygemm int4 and int8 kernels for unified quantiz… Enable dispatch to tinygemm int4 and int8 kernels for quantized tensor May 8, 2024
@jerryzh168
Copy link
Contributor Author

waiting for #227 to be landed to actually test it

@@ -832,7 +836,54 @@ def __torch_dispatch__(cls, func, types, args, kwargs):
args[1],
None if len(args) == 2 else args[2],
)
if weight_qtensor.input_quant_func is not None:
if weight_qtensor.input_quant_func is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's please remove input_quant_func and discuss using AffineQuantizedTensor as an organizing principle :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is used for testing 8da4w right now, can this be done later until there is a better alternative?

Copy link
Contributor

@cpuhrsch cpuhrsch left a comment

Choose a reason for hiding this comment

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

Setting request changes just so we don't forget to remove input_quant_func

@jerryzh168
Copy link
Contributor Author

Setting request changes just so we don't forget to remove input_quant_func

will do in next PR



# TODO: add padding support
class TinygemmAffineQuantizedTensor(AffineQuantizedTensor):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this?

Copy link
Contributor

@cpuhrsch cpuhrsch left a comment

Choose a reason for hiding this comment

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

CI is red and let's please not add a TinygemmAffineQuantizedTensor

@jerryzh168
Copy link
Contributor Author

sorry, CI should be fixed now.

For tinygemm, it's because it is quantizing things differently, we need to think of how to unify this

@jerryzh168 jerryzh168 force-pushed the int4mm branch 3 times, most recently from b5950a3 to 449a5d8 Compare May 11, 2024 01:24
@jerryzh168 jerryzh168 requested a review from cpuhrsch May 11, 2024 01:26
@jerryzh168 jerryzh168 force-pushed the int4mm branch 5 times, most recently from 61befaa to 943bf13 Compare May 13, 2024 22:44
…ed tensor

Summary:
This adds some dispatch to the tinygemm kernels for cuda, although need to resolve implementation
mismatch problem for tinygemm first

Test Plan:
python test/quantization/test_quant_api.py -k test_quantized_tensor_subclass_int4
python test/quantization/test_quant_api.py -k test_quantized_tensor_subclass_int8

Reviewers:

Subscribers:

Tasks:

Tags:
@@ -50,14 +49,14 @@ def _apply_dynamic_quant(model):
"""
_replace_with_custom_fn_if_matches_filter(
model,
lambda linear_mod: dynamic_quant(linear_mod, (torch.randn(1, linear_mod.in_features))),
lambda linear_mod: dynamic_quant(linear_mod, (torch.randn(1, linear_mod.in_features),)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Why is that extra comma needed now?

Copy link
Contributor

Choose a reason for hiding this comment

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

By all means don't be blocked on this comment haha

self.assertTrue(torch.equal(scale, scale_ref))
torch.testing.assert_close(zero_point_float, zero_point_ref, rtol=0.00001, atol=torch.max(scale)*0.03)
self.assertTrue(torch.equal(zero_point, zero_point_ref))
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat

@jerryzh168 jerryzh168 merged commit 10da375 into pytorch:main May 14, 2024
13 checks passed
lancerts pushed a commit to lancerts/ao that referenced this pull request May 17, 2024
pytorch#230)

Summary:
This adds some dispatch to the tinygemm kernels for cuda, although need to resolve implementation
mismatch problem for tinygemm first

Test Plan:
python test/quantization/test_quant_api.py -k test_quantized_tensor_subclass_int4
python test/quantization/test_quant_api.py -k test_quantized_tensor_subclass_int8

Reviewers:

Subscribers:

Tasks:

Tags:
dbyoung18 pushed a commit to dbyoung18/ao that referenced this pull request Jul 31, 2024
pytorch#230)

Summary:
This adds some dispatch to the tinygemm kernels for cuda, although need to resolve implementation
mismatch problem for tinygemm first

Test Plan:
python test/quantization/test_quant_api.py -k test_quantized_tensor_subclass_int4
python test/quantization/test_quant_api.py -k test_quantized_tensor_subclass_int8

Reviewers:

Subscribers:

Tasks:

Tags:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants