此量化方式对激活值不做量化,仅将权重量化为8 bit。使用per Channel量化。
仅
量化后权重目录结构:
├─ config.json ├─ quant_model_weight_w8a16.safetensors ├─ quant_model_description_w8a16.json ├─ tokenizer_config.json ├─ tokenizer.json └─ tokenizer.model
以下展示了量化后权重描述文件quant_model_description_w8a16.json中的部分内容:
{ "model_quant_type": "W8A16", "model.embed_tokens.weight": "FLOAT", "model.layers.0.self_attn.q_proj.weight": "W8A16", "model.layers.0.self_attn.q_proj.weight_scale": "W8A16", "model.layers.0.self_attn.q_proj.weight_offset": "W8A16", }
量化后的MatMul权重新增weight_scale和weight_offset,用于对MatMul的计算结果进行反量化。
此量化方式支持量化float16或bfloat16类型的原始权重。
Tensor信息 |
weight |
weight_scale |
weight_offset |
bias |
---|---|---|---|---|
dtype |
int8 |
float32 |
float32 |
float16 |
shape |
[n, k] |
[n, 1] |
[n, 1] |
[n] |
Tensor信息 |
weight |
weight_scale |
weight_offset |
bias |
---|---|---|---|---|
dtype |
int8 |
float32 |
float32 |
float32 |
shape |
[n, k] |
[n, 1] |
[n, 1] |
[n] |
仅当浮点权重存在bias场景时,量化权重才会有bias。
以LLaMa2-70B为例,您可以使用以下指令生成W8A16量化权重。
cd ${ATB_SPEED_HOME_PATH} python -m examples.convert.model_slim.quantifier --model_path {浮点权重路径} --save_directory {W8A16量化权重路径} --calib_file= --w_bit 8 --a_bit 16 --act_method 3 --tokenizer_args '{"padding_side":"left","pad_token":"<unk>"}'
LLaMa1_65b和LLaMa2_70b用的是一个type。
以LLaMa2-70B为例,您可以使用以下指令执行对话测试,推理内容为"What's deep learning?"。
cd ${ATB_SPEED_HOME_PATH} bash examples/models/llama/run_pa.sh {W8A16量化权重路径}