-
Notifications
You must be signed in to change notification settings - Fork 490
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
Modify qlinear_cuda for tracing the GPTQ model #367
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,7 +229,7 @@ def forward(self, x): | |
|
||
if self.bits in [2,4,8]: | ||
zeros = torch.bitwise_right_shift(torch.unsqueeze(self.qzeros, 2).expand(-1, -1, 32 // self.bits), self.wf.unsqueeze(0)).to(torch.int16 if self.bits == 8 else torch.int8) | ||
torch.bitwise_and(zeros, (2 ** self.bits) - 1, out=zeros) | ||
zeros = torch.bitwise_and(zeros, (2 ** self.bits) - 1) | ||
|
||
zeros = zeros + 1 | ||
zeros = zeros.reshape(-1, 1, zeros.shape[1] * zeros.shape[2]) | ||
|
@@ -238,7 +238,7 @@ def forward(self, x): | |
scales = scales.reshape(-1, 1, scales.shape[-1]) | ||
|
||
weight = torch.bitwise_right_shift(torch.unsqueeze(self.qweight, 1).expand(-1, 32 // self.bits, -1), self.wf.unsqueeze(-1)).to(torch.int16 if self.bits == 8 else torch.int8) | ||
torch.bitwise_and(weight,(2 ** self.bits) - 1, out=weight) | ||
weight = torch.bitwise_and(weight,(2 ** self.bits) - 1) | ||
weight = weight.reshape(-1, self.group_size, weight.shape[2]) | ||
elif self.bits == 3: | ||
zeros = self.qzeros.reshape(self.qzeros.shape[0], self.qzeros.shape[1]//3, 3, 1).expand(-1, -1, -1, 12) | ||
|
@@ -266,10 +266,10 @@ def forward(self, x): | |
weight = (scales * (weight - zeros)) | ||
weight = weight.reshape(weight.shape[0] * weight.shape[1], weight.shape[2]) | ||
|
||
out = torch.matmul(x.half(), weight) | ||
out = torch.matmul(x.to(weight.dtype), weight) | ||
out = out.half().reshape(out_shape) | ||
out = out + self.bias if self.bias is not None else out | ||
return out | ||
return out.to(x.dtype) | ||
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. This introduces a bug when using the CUDA kernel in fp32. 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. What kind of bug? Can you please explain? 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. When 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. Thanks @fxmarty! |
||
|
||
|
||
__all__ = ["QuantLinear"] |
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 is there still a
.half()
here?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.
I'm not sure about this. I think this was left by mistake. Should I remove 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.
I don't mind leaving it you if this
half()
is not a blocker for you. But was wondering given that you replaced some of the.half()
to remove the assumption on fp16.