Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ def process_loaded_weights(self, layer: nn.Layer, state_dict):
quant_weight, scale = weight_quantize(
weight_tensor[i], algo=self.moe_quant_type, arch=self.weight_only_linear_arch
)
quant_weight = paddle.transpose(quant_weight, [1, 0])
if self.quant_config.algo != "weight_only_int4":
quant_weight = paddle.transpose(quant_weight, [1, 0])
weight_list.append(quant_weight)
weight_scale_list.append(scale)
quanted_weight = paddle.stack(weight_list, axis=0)
Expand Down
9 changes: 9 additions & 0 deletions fastdeploy/model_executor/layers/quantization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
"""
quantization module
"""
import os
from typing import Dict, List, Type

from fastdeploy.platforms import current_platform
from fastdeploy.utils import parse_quantization

from .quant_base import QuantConfigBase
Expand Down Expand Up @@ -78,6 +80,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"

if current_platform.is_maca():
metax_dense_quant_type = os.getenv("FD_METAX_DENSE_QUANT_TYPE")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加环境变量需要统一在envs.py里注册,禁止私自添加env。尽管如此,针对这里的case,也不建议通过这种环境变量的方式来控制 dense_quant_type

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模型的config.json里是可以配置moe_quant_type和dense_quant_type的

quantization_config["dense_quant_type"] = (
metax_dense_quant_type if metax_dense_quant_type is not None else "wint8"
)

else:
quant_config_name = None
if quant_config_name is None:
Expand Down
4 changes: 3 additions & 1 deletion fastdeploy/model_executor/layers/quantization/weight_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ def process_loaded_weights(self, layer, weight) -> None:
arch=self.quant_config.weight_only_linear_arch,
)
if current_platform.is_maca():
quanted_weight_tensor = paddle.transpose(quanted_weight_tensor, [1, 0])
if self.quant_config.algo != "weight_only_int4":
quanted_weight_tensor = paddle.transpose(quanted_weight_tensor, [1, 0])

layer.weight.set_value(quanted_weight_tensor)
layer.weight_scale.set_value(weight_scale_tensor.astype(paddle.get_default_dtype()))

Expand Down
Loading