昇腾社区首页
中文
注册

get_linear_quant_type接口

接口功能

根据packed_modules_mapping,将实际堆积模块映射为权重中原始模块,并获取对应量化类型。

参数说明

参数名称

是否必选

类型

默认值

描述

安全声明

quant_description

Dict[str, Any]

-

模型的模块名称和量化方法构成的字典,用于在MindIE Turbo中选择对应量化实现。该字典当前由msModelSlim在权重量化过程中生成,即模型权重路径下config.json中新增的“quantization_config”字段。

推理强依赖数据的合法性,需由用户保证。

prefix

str

-

模块名称前缀。例如:

"model.layers.0.self_attn.o_proj"

packed_modules_mapping

Dict[str, Any]

-

推理时实际堆积模块到权重中原始模块的映射关系,该部分通常与linear相关。

例如:

{

"qkv_proj": ["q_proj", "k_proj", "v_proj"],

"gate_up_proj": ["gate_proj", "up_proj"]

}

返回值说明

类型

描述

安全声明

str

代表量化类型的字符串。

推理强依赖数据的合法性,需由用户保证。

使用样例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
quant_description = {
    "model_quant_type": "W8A8",
    "model.embed_tokens.weight": "FLOAT",
    "model.layers.0.self_attn.q_proj.weight": "W8A8",
    "model.layers.0.self_attn.q_proj.input_scale": "W8A8",
    "model.layers.0.self_attn.q_proj.input_offset": "W8A8",
    "model.layers.0.self_attn.q_proj.quant_bias": "W8A8",
    "model.layers.0.self_attn.q_proj.deq_scale": "W8A8",
    "model.layers.0.self_attn.k_proj.weight": "W8A8",
    "model.layers.0.self_attn.k_proj.input_scale": "W8A8",
    "model.layers.0.self_attn.k_proj.input_offset": "W8A8",
    "model.layers.0.self_attn.k_proj.quant_bias": "W8A8",
    "model.layers.0.self_attn.k_proj.deq_scale": "W8A8",
    "model.layers.0.self_attn.v_proj.weight": "W8A8",
    "model.layers.0.self_attn.v_proj.input_scale": "W8A8",
    "model.layers.0.self_attn.v_proj.input_offset": "W8A8",
    "model.layers.0.self_attn.v_proj.quant_bias": "W8A8",
    "model.layers.0.self_attn.v_proj.deq_scale": "W8A8",
}
prefix = "model.layers.0.self_attn.qkv_proj"
packed_modules_mapping = {
    "qkv_proj": ["q_proj", "k_proj", "v_proj"],
    "gate_up_proj": ["gate_proj", "up_proj"]
}
quant_type = MindIETurboQuantizer.get_linear_quant_type(
    quant_description, prefix, packed_modules_mapping
)