mirror of
https://github.com/RYDE-WORK/MiniCPM.git
synced 2026-01-19 12:53:36 +08:00
增加了bnb量化模型的readme
This commit is contained in:
parent
08514cd9ec
commit
4a7761df1f
@ -45,15 +45,45 @@
|
||||
|
||||
```
|
||||
5. 运行quantize/awq_quantize.py文件,在设置的quan_path目录下可得awq量化后的模型。
|
||||
|
||||
<p id="bnb"></p>
|
||||
|
||||
**bnb量化**
|
||||
1. 在quantize/bnb_quantize.py 文件中修改根据注释修改配置参数:
|
||||
```python
|
||||
model_path = "/root/ld/ld_model_pretrain/MiniCPM-1B-sft-bf16" # 模型地址
|
||||
save_path = "/root/ld/ld_model_pretrain/MiniCPM-1B-sft-bf16_int4" # 量化模型保存地址
|
||||
```
|
||||
2. 更多量化参数可根据注释以及llm.int8()算法进行修改:
|
||||
```python
|
||||
quantization_config = BitsAndBytesConfig(
|
||||
load_in_4bit=True, # 是否进行4bit量化
|
||||
load_in_8bit=False, # 是否进行8bit量化
|
||||
bnb_4bit_compute_dtype=torch.float16, # 计算精度设置
|
||||
bnb_4bit_quant_storage=torch.uint8, # 量化权重的储存格式
|
||||
bnb_4bit_quant_type="nf4", # 量化格式,这里用的是正太分布的int4
|
||||
bnb_4bit_use_double_quant=True, # 是否采用双量化,即对zeropoint和scaling参数进行量化
|
||||
llm_int8_enable_fp32_cpu_offload=False, # 是否llm使用int8,cpu上保存的参数使用fp32
|
||||
llm_int8_has_fp16_weight=False, # 是否启用混合精度
|
||||
#llm_int8_skip_modules=["out_proj", "kv_proj", "lm_head"], # 不进行量化的模块
|
||||
llm_int8_threshold=6.0, # llm.int8()算法中的离群值,根据这个值区分是否进行量化
|
||||
)
|
||||
```
|
||||
3. 运行quantize/bnb_quantize.py文件,在设置的save_path目录下可得bnb量化后的模型。
|
||||
```python
|
||||
cd MiniCPM/quantize
|
||||
python bnb_quantize.py
|
||||
```
|
||||
<p id="quantize_test"></p>
|
||||
|
||||
**量化测试**
|
||||
1. 命令行进入到 MiniCPM/quantize 目录下
|
||||
2. 修改quantize_eval.sh文件中awq_path,gptq_path,awq_path,如果不需要测试的类型保持为空字符串,如下示例表示仅测试awq模型:
|
||||
2. 修改quantize_eval.sh文件中awq_path,gptq_path,awq_path,bnb_path,如果不需要测试的类型保持为空字符串,如下示例表示仅测试awq模型:
|
||||
```
|
||||
awq_path="/root/ld/ld_project/AutoAWQ/examples/awq_cpm_1b_4bit"
|
||||
gptq_path=""
|
||||
model_path=""
|
||||
bnb_path=""
|
||||
```
|
||||
3. 在MiniCPM/quantize路径下命令行输入:
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user