mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
[Quantization] Support w4afp8 MoE dynamic quantization (#5282)
* support dynamic activation quant for w4afp8 * support dynamic w4afp8 * add test * fix * fix --------- Co-authored-by: zhoutianzi666 <17801055074@163.com>
This commit is contained in:
@@ -84,6 +84,13 @@ def parse_quant_config(args, model_config, is_ernie, is_v1_loader):
|
||||
quantization_config["moe_quant_type"] = "wint4"
|
||||
quantization_config["quantization"] = "mix_quant"
|
||||
quant_config_name = "mix_quant"
|
||||
# Special handling for moe w4afp8 dynamic quant
|
||||
elif quant_config_name == "w4afp8":
|
||||
quantization_config["dense_quant_type"] = "block_wise_fp8"
|
||||
quantization_config["moe_quant_type"] = "w4afp8"
|
||||
quantization_config["hadamard_block_size"] = 512
|
||||
quantization_config["quantization"] = "mix_quant"
|
||||
quant_config_name = "mix_quant"
|
||||
else:
|
||||
quant_config_name = None
|
||||
if quant_config_name is None:
|
||||
|
||||
@@ -31,7 +31,7 @@ class W4AFP8Config(QuantConfigBase):
|
||||
quantization config for weight 4bits and activation fp8
|
||||
"""
|
||||
|
||||
def __init__(self, weight_scale_dict, act_scale_dict, is_permuted, hadamard_block_size) -> None:
|
||||
def __init__(self, weight_scale_dict, act_scale_dict, is_permuted, hadamard_block_size, is_quantized) -> None:
|
||||
super().__init__()
|
||||
self.weight_scale_dict = weight_scale_dict
|
||||
self.act_scale_dict = act_scale_dict
|
||||
@@ -40,6 +40,7 @@ class W4AFP8Config(QuantConfigBase):
|
||||
self.quant_round_type = 1
|
||||
self.is_permuted = is_permuted
|
||||
self.hadamard_block_size = hadamard_block_size
|
||||
self.is_quantized = is_quantized
|
||||
|
||||
def name(self) -> str:
|
||||
return "w4afp8"
|
||||
@@ -50,7 +51,8 @@ class W4AFP8Config(QuantConfigBase):
|
||||
act_scale_dict = config.get("act_scale_dict", None)
|
||||
is_permuted = config.get("is_permuted", True)
|
||||
hadamard_block_size = config.get("hadamard_block_size", 128)
|
||||
return cls(weight_scale_dict, act_scale_dict, is_permuted, hadamard_block_size)
|
||||
is_quantized = config.get("is_quantized", False)
|
||||
return cls(weight_scale_dict, act_scale_dict, is_permuted, hadamard_block_size, is_quantized)
|
||||
|
||||
def get_quant_method(self, layer) -> Optional[QuantMethodBase]:
|
||||
if isinstance(layer, FusedMoE):
|
||||
|
||||
Reference in New Issue
Block a user