mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
Sync v2.0 version of code to github repo
This commit is contained in:
47
docs/zh/quantization/README.md
Normal file
47
docs/zh/quantization/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# 量化
|
||||
|
||||
FastDeploy支持FP8、INT8、INT4、2-bit等多种量化推理精度,支持模型权重、激活和KVCache 3种张量的不同精度推理,可以满足低成本、低时延、长上下文等不同场景的推理需求。
|
||||
|
||||
## 1. 精度支持列表
|
||||
|
||||
| 量化方法 | 权重精度 | 激活精度 | KVCache精度 | 在线/离线 | 支持硬件 |
|
||||
|---------|---------|---------|------------|---------|---------|
|
||||
| [WINT8](online_quantization.md#1-wint8--wint4) | INT8 | BF16 | BF16 | 在线 | GPU, XPU |
|
||||
| [WINT4](online_quantization.md#1-wint8--wint4) | INT4 | BF16 | BF16 | 在线 | GPU, XPU |
|
||||
| [block_wise_fp8](online_quantization.md#2-block-wise-fp8) | block-wise static FP8 | token-wise dynamic FP8 | BF16 | 在线 | GPU |
|
||||
| [WINT2](wint2.md) | 2Bits | BF16 | BF16 | 离线 | GPU |
|
||||
| MixQuant | INT4/INT8 | INT8/BF16 | INT8/BF16 | 离线 | GPU, XPU |
|
||||
|
||||
**说明**
|
||||
|
||||
1. **量化方法**:对应量化配置文件中的"quantization"字段;
|
||||
2. **在线/离线量化**:主要用于区分权重的量化时间
|
||||
- **在线量化**:推理引擎在加载 BF16 权重后,再对权重做量化;
|
||||
- **离线量化**:在推理之前,将权重离线地量化并存储为低比特数值类型,推理时,加载量化后的低比特数值。
|
||||
3. **动态量化/静态量化**:主要用于区别激活的量化方式
|
||||
- **静态量化(static)**:在推理之前,确定并存储量化系数,推理时加载提前计算好的量化系数。因为量化系数在推理时是固定不变的,所以叫静态量化(static quantization);
|
||||
- **动态量化(dynamic)**:在推理时,即时地统计当前batch的量化系数。因为量化系数在推理时是动态地变化的,所以叫动态量化(dynamic quantization)。
|
||||
|
||||
## 2. 模型支持列表
|
||||
|
||||
| 模型名称 | 支持量化精度 |
|
||||
|---------|---------|
|
||||
| ERNIE-4.5-300B-A47B | WINT8, WINT4, Block_wise= FP8, MixQuant|
|
||||
|
||||
## 3. 量化精度术语
|
||||
|
||||
FastDeploy 按以下格式命名各种量化精度:
|
||||
|
||||
```
|
||||
{tensor缩写}{数值类型}{tensor缩写}{数值类型}{tensor缩写}{数值类型}
|
||||
```
|
||||
|
||||
部分示例如下:
|
||||
|
||||
- **W8A8C8**:W=weights,A=activations,C=CacheKV;8默认为INT8
|
||||
- **W8A8C16**:16默认为BF16,其它同上
|
||||
- **W4A16C16 / WInt4 / weight-only int4**:4默认为INT4
|
||||
- **WNF4A8C8**:NF4指4bit norm-float数值类型
|
||||
- **Wfp8Afp8**:权重和激活均为FP8精度
|
||||
- **W4Afp8**:权重为INT4, 激活为FP8
|
||||
|
||||
57
docs/zh/quantization/online_quantization.md
Normal file
57
docs/zh/quantization/online_quantization.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# 在线量化
|
||||
|
||||
在线量化是指推理引擎在加载 BF16 权重后对权重做量化,而不是加载离线量化好的低精度权重。FastDeploy 支持将 BF16 在线量化到多种精度,包括:INT4, INT8 和 FP8.
|
||||
|
||||
## 1. WINT8 & WINT4
|
||||
|
||||
仅将权重在线量化为 INT8 或 INT4,推理时即时地将权重反量化为 BF16 后与激活进行计算。
|
||||
- **量化粒度**:仅支持 channel-wise 粒度的量化;
|
||||
- **支持硬件**:GPU,XPU
|
||||
- **支持结构**:MoE 结构,Dense Linear
|
||||
|
||||
### 启动WINT8或WINT4推理服务
|
||||
|
||||
```
|
||||
python -m fastdeploy.entrypoints.openai.api_server \
|
||||
--model baidu/ERNIE-4.5-300B-A47B-Paddle \
|
||||
--port 8180 --engine-worker-queue-port 8181 \
|
||||
--cache-queue-port 8182 --metrics-port 8182 \
|
||||
--tensor-parallel-size 8 \
|
||||
--quantization wint8 \
|
||||
--max-model-len 32768 \
|
||||
--max-num-seqs 32
|
||||
```
|
||||
|
||||
- 通过指定 `--model baidu/ERNIE-4.5-300B-A47B-Paddle` 可自动从AIStudio下载模型。FastDeploy依赖Paddle格式的模型,更多说明参考[支持模型列表](https://console.cloud.baidu-int.com/devops/icode/repos/baidu/paddle_internal/FastDeploy/blob/feature%2Finference-refactor-20250528/docs/supported_models.md)。
|
||||
- 通过设置 `--quantization` 为 `wint8` 或 `wint4` 选择在线 INT8/INT4 量化。
|
||||
- 部署 ERNIE-4.5-300B-A47B-Paddle WINT8 最少需要 80G * 8卡, WINT4 则需要 80GB * 4卡。
|
||||
- 更多部署教程请参考[get_started](../get_started/ernie-4.5.md).
|
||||
|
||||
## 2. Block-wise FP8
|
||||
|
||||
加载 BF16 模型,将权重以 128X128 block-wise 的粒度在线量化为 FP8 数值类型。推理时,激活会动态、即时地做 token-wise FP8 量化。
|
||||
|
||||
- **FP8规格**:float8_e4m3fn
|
||||
- **支持硬件**:Hopper GPU 架构
|
||||
- **支持结构**:MoE 结构,Dense Linear
|
||||
|
||||
### 启动Block-wise FP8推理服务
|
||||
|
||||
```
|
||||
python -m fastdeploy.entrypoints.openai.api_server \
|
||||
--model baidu/ERNIE-4.5-300B-A47B-Paddle \
|
||||
--port 8180 --engine-worker-queue-port 8181 \
|
||||
--cache-queue-port 8182 --metrics-port 8182 \
|
||||
--tensor-parallel-size 8 \
|
||||
--quantization block_wise_fp8 \
|
||||
--max-model-len 32768 \
|
||||
--max-num-seqs 32
|
||||
```
|
||||
|
||||
- 通过指定 `--model baidu/ERNIE-4.5-300B-A47B-Paddle` 可自动从AIStudio下载模型。FastDeploy依赖Paddle格式的模型,更多说明参考[支持模型列表](https://console.cloud.baidu-int.com/devops/icode/repos/baidu/paddle_internal/FastDeploy/blob/feature%2Finference-refactor-20250528/docs/supported_models.md)。
|
||||
- 通过设置 `--quantization` 为 `block_wise_fp8` 选择在线 Block-wise FP8 量化。
|
||||
- 部署 ERNIE-4.5-300B-A47B-Paddle Block-wise FP8 最少需要 80G * 8卡。
|
||||
- 更多部署教程请参考[get_started](../get_started/ernie-4.5.md)
|
||||
|
||||
|
||||
|
||||
62
docs/zh/quantization/wint2.md
Normal file
62
docs/zh/quantization/wint2.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# WINT2量化
|
||||
|
||||
权重经过CCQ(Convolutional Coding Quantization)方法离线压缩。权重实际存储的数值类型是INT8,每个INT8数值中打包了4个权重,等价于每个权重2bits. 激活不做量化,计算时将权重实时地反量化、解码为BF16数值类型,并用BF16数值类型计算。
|
||||
- **支持硬件**:GPU
|
||||
- **支持结构**:MoE结构
|
||||
|
||||
CCQ WINT2一般用于资源受限的低门槛场景,以ERNIE-4.5-300B-A47B为例,将权重压缩到89GB,可支持141GB H20单卡部署。
|
||||
|
||||
## 启动WINT2推理服务
|
||||
|
||||
```
|
||||
python -m fastdeploy.entrypoints.openai.api_server \
|
||||
--model baidu/ERNIE-4.5-300B-A47B-2Bits-Paddle \
|
||||
--port 8180 --engine-worker-queue-port 8181 \
|
||||
--cache-queue-port 8182 --metrics-port 8182 \
|
||||
--tensor-parallel-size 1 \
|
||||
--max-model-len 32768 \
|
||||
--max-num-seqs 32
|
||||
```
|
||||
|
||||
通过指定 `--model baidu/ERNIE-4.5-300B-A47B-2Bits-Paddle` 可自动从AIStudio下载已离线量化好的WINT2模型,在该模型的config.json文件中,会有WINT2量化相关的配置信息,不用再在启动推理服务时设置 `--quantization`.
|
||||
|
||||
模型的config.json文件中的量化配置示例如下:
|
||||
|
||||
```
|
||||
"quantization_config": {
|
||||
"dense_quant_type": "wint8",
|
||||
"moe_quant_type": "w4w2",
|
||||
"quantization": "wint2",
|
||||
"moe_quant_config": {
|
||||
"moe_w4_quant_config": {
|
||||
"quant_type": "wint4",
|
||||
"quant_granularity": "per_channel",
|
||||
"quant_start_layer": 0,
|
||||
"quant_end_layer": 6
|
||||
},
|
||||
"moe_w2_quant_config": {
|
||||
"quant_type": "wint2",
|
||||
"quant_granularity": "pp_acc",
|
||||
"quant_group_size": 64,
|
||||
"quant_start_layer": 7,
|
||||
"quant_end_layer": 53
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- 更多部署教程请参考[get_started](../get_started/ernie-4.5.md);
|
||||
- 更多模型说明请参考[支持模型列表](https://console.cloud.baidu-int.com/devops/icode/repos/baidu/paddle_internal/FastDeploy/blob/feature%2Finference-refactor-20250528/docs/supported_models.md)。
|
||||
|
||||
|
||||
## WINT2效果
|
||||
|
||||
在ERNIE-4.5-300B-A47B模型上,WINT2与WINT4效果对比:
|
||||
|
||||
| 测试集 |数据集大小| WINT4 | WINT2 |
|
||||
|---------|---------|---------|---------|
|
||||
| IFEval |500|88.17 | 85.40 |
|
||||
|BBH|6511|94.43|92.02|
|
||||
|DROP|9536|91.17|89.97|
|
||||
|
||||
## WINT2推理性能
|
||||
Reference in New Issue
Block a user