mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-04-20 06:12:07 +00:00
fix modules_to_not_convert
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
This commit is contained in:
parent
06dfe9abfe
commit
0bad926fb8
@ -6,7 +6,7 @@ import torch
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from text_generation_server.utils.import_utils import SYSTEM
|
from text_generation_server.utils.import_utils import SYSTEM
|
||||||
from text_generation_server.utils.log import log_once
|
from text_generation_server.utils.log import log_once
|
||||||
from text_generation_server.utils.weights import Weight, Weights, WeightsLoader
|
from text_generation_server.utils.weights import Weight, Weights, WeightsLoader, UnquantizedWeight
|
||||||
|
|
||||||
if SYSTEM == "ipex":
|
if SYSTEM == "ipex":
|
||||||
from .ipex import QuantLinear
|
from .ipex import QuantLinear
|
||||||
@ -90,6 +90,7 @@ class GPTQWeightsLoader(WeightsLoader):
|
|||||||
quant_method: str,
|
quant_method: str,
|
||||||
quantize: str,
|
quantize: str,
|
||||||
sym: bool,
|
sym: bool,
|
||||||
|
modules_to_not_convert: Optional[List[str]],
|
||||||
):
|
):
|
||||||
self.bits = bits
|
self.bits = bits
|
||||||
self.desc_act = desc_act
|
self.desc_act = desc_act
|
||||||
@ -97,6 +98,7 @@ class GPTQWeightsLoader(WeightsLoader):
|
|||||||
self.quant_method = quant_method
|
self.quant_method = quant_method
|
||||||
self.quantize = quantize
|
self.quantize = quantize
|
||||||
self.sym = sym
|
self.sym = sym
|
||||||
|
self.modules_to_not_convert = modules_to_not_convert
|
||||||
|
|
||||||
def get_weights(self, weights: Weights, prefix: str):
|
def get_weights(self, weights: Weights, prefix: str):
|
||||||
self._get_gptq_params(weights)
|
self._get_gptq_params(weights)
|
||||||
@ -109,6 +111,10 @@ class GPTQWeightsLoader(WeightsLoader):
|
|||||||
log_once(logger.warning, "Disabling exllama because desc_act=True")
|
log_once(logger.warning, "Disabling exllama because desc_act=True")
|
||||||
use_exllama = False
|
use_exllama = False
|
||||||
|
|
||||||
|
if self.is_layer_skipped_quantization(prefix, self.modules_to_not_convert):
|
||||||
|
w = weights.get_tensor(f"{prefix}.weight")
|
||||||
|
return UnquantizedWeight(w)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
qweight = weights.get_tensor(f"{prefix}.qweight")
|
qweight = weights.get_tensor(f"{prefix}.qweight")
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
@ -171,9 +177,15 @@ class GPTQWeightsLoader(WeightsLoader):
|
|||||||
g_idx=g_idx,
|
g_idx=g_idx,
|
||||||
bits=self.bits,
|
bits=self.bits,
|
||||||
groupsize=self.groupsize,
|
groupsize=self.groupsize,
|
||||||
|
use_awq_kernel=self.quantize == "awq",
|
||||||
use_exllama=use_exllama,
|
use_exllama=use_exllama,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def is_layer_skipped_quantization(self, prefix: str, modules_to_not_convert: List[str]):
|
||||||
|
if modules_to_not_convert is None:
|
||||||
|
return False
|
||||||
|
return any(module_name in prefix for module_name in modules_to_not_convert)
|
||||||
|
|
||||||
def get_weights_col_packed(
|
def get_weights_col_packed(
|
||||||
self,
|
self,
|
||||||
weights: Weights,
|
weights: Weights,
|
||||||
|
@ -85,6 +85,8 @@ class UnquantizedSparseMoELayer(nn.Module):
|
|||||||
use_grouped_topk=self.n_expert_group is not None,
|
use_grouped_topk=self.n_expert_group is not None,
|
||||||
num_expert_group=self.n_expert_group,
|
num_expert_group=self.n_expert_group,
|
||||||
topk_group=self.topk_group,
|
topk_group=self.topk_group,
|
||||||
|
scoring_func=self.scoring_func,
|
||||||
|
e_score_correction_bias=self.e_score_correction_bias,
|
||||||
)
|
)
|
||||||
return fused_moe(
|
return fused_moe(
|
||||||
x,
|
x,
|
||||||
|
@ -21,6 +21,7 @@ class _QuantizerConfig:
|
|||||||
quant_method: str
|
quant_method: str
|
||||||
sym: bool
|
sym: bool
|
||||||
weight_block_size: Optional[List[int]]
|
weight_block_size: Optional[List[int]]
|
||||||
|
modules_to_not_convert: Optional[List[str]]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -51,6 +52,7 @@ def _get_quantizer_config(model_id, revision):
|
|||||||
sym = False
|
sym = False
|
||||||
desc_act = False
|
desc_act = False
|
||||||
weight_block_size = None
|
weight_block_size = None
|
||||||
|
modules_to_not_convert = None
|
||||||
|
|
||||||
filename = "config.json"
|
filename = "config.json"
|
||||||
try:
|
try:
|
||||||
@ -73,7 +75,8 @@ def _get_quantizer_config(model_id, revision):
|
|||||||
# Order is important here, desc_act is missing on some real models
|
# Order is important here, desc_act is missing on some real models
|
||||||
quant_method = data["quantization_config"]["quant_method"]
|
quant_method = data["quantization_config"]["quant_method"]
|
||||||
checkpoint_format = data["quantization_config"].get("checkpoint_format")
|
checkpoint_format = data["quantization_config"].get("checkpoint_format")
|
||||||
desc_act = data["quantization_config"]["desc_act"]
|
desc_act = data["quantization_config"].get("desc_act", False)
|
||||||
|
modules_to_not_convert = data["quantization_config"].get("modules_to_not_convert", None)
|
||||||
except Exception:
|
except Exception:
|
||||||
filename = "quantize_config.json"
|
filename = "quantize_config.json"
|
||||||
try:
|
try:
|
||||||
@ -110,6 +113,7 @@ def _get_quantizer_config(model_id, revision):
|
|||||||
sym=sym,
|
sym=sym,
|
||||||
desc_act=desc_act,
|
desc_act=desc_act,
|
||||||
weight_block_size=weight_block_size,
|
weight_block_size=weight_block_size,
|
||||||
|
modules_to_not_convert=modules_to_not_convert,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -159,6 +163,7 @@ def get_loader(
|
|||||||
quant_method=quantizer_config.quant_method,
|
quant_method=quantizer_config.quant_method,
|
||||||
quantize=quantize,
|
quantize=quantize,
|
||||||
sym=quantizer_config.sym,
|
sym=quantizer_config.sym,
|
||||||
|
modules_to_not_convert=quantizer_config.modules_to_not_convert,
|
||||||
)
|
)
|
||||||
elif quantize == "bitsandbytes":
|
elif quantize == "bitsandbytes":
|
||||||
from text_generation_server.layers.bnb import BNBWeight
|
from text_generation_server.layers.bnb import BNBWeight
|
||||||
|
Loading…
Reference in New Issue
Block a user