-
Notifications
You must be signed in to change notification settings - Fork 225
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
Replace WeightOnlyInt8Linear with TorchAO int8_weight_only quantization #1328
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchchat/1328
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 1a42fb6 with merge base e30aaa0 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
d43d52e
to
92e0a9d
Compare
thanks! can you add a generate.py speed benchmark result for before and after as well |
# Use tensor subclass API for int4 weight only. | ||
if device == "cuda" and quantizer == "linear:int4": | ||
quantize_(model, int4_weight_only(q_kwargs["groupsize"])) | ||
elif quantizer == "linear:int8": | ||
print("quantizer is linear int8") |
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.
print("quantizer is linear int8") |
"precision": PrecisionHandler, | ||
"executor": ExecutorHandler, | ||
"linear:int4": Int4WeightOnlyQuantizer, | ||
"linear:int8": int8_weight_only, |
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.
Do we need this?
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.
we can probably use None for now, and remove this later
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.
We check for int8_weight_only and finished check before it looks at the table I think
@vmpuri can you check?
Can you ack that the numerics look good for MPS and CPU as well? |
# Use tensor subclass API for int4 weight only. | ||
if device == "cuda" and quantizer == "linear:int4": | ||
quantize_(model, int4_weight_only(q_kwargs["groupsize"])) | ||
elif quantizer == "linear:int8": | ||
print("quantizer is linear int8") | ||
quantize_(model, int8_weight_only()) |
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.
Why not integrate it into a QuantHandler class dispatched thru the handler dict at a single call site rather than build a chain of if statements?
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.
Hi @mikekgfb, we will refactor this part in the future after all quant APIs are moved to torchao I think
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.
torchAO already has a class-based API that is used for other quantizers? Why do these differently, and then later refactor them? Or why not do them all a consistent way now, and if you refactor later, do that?
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.
yeah, quantizer API is deprecated in favor of quantize_
, that's why we are gradually refactoring the quantizer APIs to use quantize_
, the reason we do it one by one is because there might be missing support/alignment on numerics etc. that we need to do during the migration
return linear_int8_aoti(input, self.weight, self.scales) | ||
|
||
def et_forward(self, input: torch.Tensor) -> torch.Tensor: | ||
return linear_int8_et(input, self.weight, self.scales) |
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.
Int 8 seems like it special cased for ET, reminder to check that as well
Replace the WeightOnlyInt8Linear quantization code with TorchAO's int8_weight_only quantization.
Note - this commit also contains lintrunner changes.
Testing:
From current master:
Lint