-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add gptq and awq int4 support in intel platform Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> * fix ci failure Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> * set kv cache dtype Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> * refine the code according to the review command Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> * Simplifying conditionals + reverting integration tests values. * Unused import * Fix redundant import. * Revert change after rebase. * Upgrading the tests (TP>1 fix changes to use different kernels.) * Update server/text_generation_server/layers/gptq/__init__.py --------- Signed-off-by: Wang, Yi A <yi.a.wang@intel.com> Co-authored-by: Wang, Yi A <yi.a.wang@intel.com>
- Loading branch information
Showing
11 changed files
with
226 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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 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
8 changes: 8 additions & 0 deletions
8
server/text_generation_server/layers/awq/quantize/__init__.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from text_generation_server.utils.import_utils import SYSTEM | ||
|
||
if SYSTEM == "ipex": | ||
from .ipex import WQLinear | ||
elif SYSTEM == "cuda": | ||
from .cuda import WQLinear | ||
|
||
__all__ = ["WQLinear"] |
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Optional | ||
import torch | ||
import torch.nn as nn | ||
import intel_extension_for_pytorch as ipex | ||
|
||
|
||
class WQLinear(nn.Module): | ||
def __init__( | ||
self, w_bit, group_size, qweight, qzeros, scales, bias: Optional[torch.Tensor] | ||
): | ||
super().__init__() | ||
|
||
if w_bit not in [4]: | ||
raise NotImplementedError("Only 4-bit are supported for now.") | ||
|
||
self.in_features = qweight.shape[0] | ||
self.out_features = qweight.shape[1] * 32 // w_bit | ||
|
||
self.w_bit = w_bit | ||
self.group_size = group_size if group_size != -1 else self.in_features | ||
# quick sanity check (make sure aligment) | ||
assert self.in_features % self.group_size == 0 | ||
assert self.out_features % (32 // self.w_bit) == 0 | ||
|
||
self.qweight = qweight | ||
self.qzeros = qzeros | ||
self.scales = scales | ||
self.bias = bias | ||
self.woq_linear = ( | ||
ipex.llm.quantization.IPEXWeightOnlyQuantizedLinear.from_weight( | ||
self.qweight, | ||
self.scales, | ||
self.qzeros, | ||
self.in_features, | ||
self.out_features, | ||
bias=self.bias, | ||
group_size=self.group_size, | ||
quant_method=ipex.llm.quantization.QuantMethod.AWQ_GEMM, | ||
dtype=ipex.llm.quantization.QuantDtype.INT4, | ||
) | ||
) | ||
|
||
@torch.no_grad() | ||
def forward(self, x): | ||
out_shape = x.shape[:-1] + (self.out_features,) | ||
out = self.woq_linear(x.reshape(-1, x.shape[-1])) | ||
out = out + self.bias if self.bias is not None else out | ||
return out.reshape(out_shape) |
This file contains 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
File renamed without changes.
Oops, something went wrong.