-
Notifications
You must be signed in to change notification settings - Fork 212
Feat (brevitas_examples/sdxl): better GPTQ #1250
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
Open
Giuseppe5
wants to merge
6
commits into
Xilinx:dev
Choose a base branch
from
Giuseppe5:faster_sdxl
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,13 +242,26 @@ def single_layer_update(self): | |
pass | ||
|
||
def get_quant_weights(self, i, i1, permutation_list, with_quant_history=False): | ||
from brevitas.quant_tensor import _unpack_quant_tensor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required - already imported. |
||
|
||
# We need to recompute quant weights at runtime since our float weights are being updated | ||
# Add offset in case of blockwise computation | ||
i = i1 + i | ||
|
||
# For QuantLinear and for some QuantConvolutional layers, we exploit the possibility | ||
# of quantizing only a subset of the entire matrix speeding up the computation of GPxQ | ||
no_slice = False | ||
# Groupwise Quantization does not support slicing | ||
no_slice = no_slice or self.layer.weight_quant.is_groupwise | ||
# If we need quantization of past channels, we do not use slicing | ||
no_slice = no_slice or with_quant_history | ||
# If we are in export mode (i.e., inference mode), we do not slice for torch.compile | ||
# compatibility | ||
no_slice = no_slice or self.layer.weight_quant.export_mode | ||
|
||
if isinstance(self.layer, qnn.QuantLinear): | ||
if self.layer.weight_quant.is_groupwise or with_quant_history: | ||
if no_slice: | ||
|
||
# No slicing, not optimized | ||
q = self.layer.quant_weight(quant_input=self.quant_metadata) | ||
q = _unpack_quant_tensor(q).unsqueeze(0) # [1, OC, IC] | ||
|
@@ -264,11 +277,11 @@ def get_quant_weights(self, i, i1, permutation_list, with_quant_history=False): | |
subtensor_slice_list=subtensor_slice_list, | ||
quant_input=self.quant_metadata)).unsqueeze(0) # [1, OC, 1] | ||
elif isinstance(self.layer, SUPPORTED_CONV_OP): | ||
# For depthwise and ConvTranspose we fall back to quantizing the entire martix. | ||
# For all other cases, we create a mask that represent the slicing we will perform on the weight matrix | ||
# and we quantize only the selected dimensions. | ||
if self.layer.weight_quant.is_groupwise or with_quant_history or self.groups > 1 or ( | ||
self.groups == 1 and is_conv_transposed(self.layer)): | ||
# Depthwise and ConvTranspose does not support slicing | ||
no_slice_conv = no_slice or (self.groups > 1 or is_conv_transposed(self.layer)) | ||
|
||
if no_slice_conv: | ||
|
||
quant_weight = self.layer.quant_weight(quant_input=self.quant_metadata) | ||
quant_weight = _unpack_quant_tensor(quant_weight) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
Maybe I should re-introduce this but I was getting weird CUDA errors. Also, since we are storing in CPU, not sure why we need to use pin_memory.
@i-colbert maybe you can comment before we merge
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.
From what I can remember, it was used to improve data transfer speeds from GPU to CPU, which is why it is only enabled if a GPU is available.