unsubscribe commited on
Commit
41c76d9
1 Parent(s): 5ae26f2

Create README_zh-CN.md

Browse files
Files changed (1) hide show
  1. README_zh-CN.md +89 -0
README_zh-CN.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # W4A16 LLM 模型部署
2
+
3
+ LMDeploy 支持 4bit 权重模型的推理,**对 NVIDIA 显卡的最低要求是 sm80**。
4
+
5
+ 在推理之前,请确保安装了 lmdeploy,版本 >= v0.0.4
6
+
7
+ ```shell
8
+ pip install lmdeploy
9
+ ```
10
+
11
+ ## 4bit 权重模型推理
12
+
13
+ 你可以直接从 LMDeploy 的 [model zoo](https://huggingface.co/lmdeploy) 下载已经量化好的 4bit 权重模型,直接使用下面的命令推理。也可以根据["4bit 权重量化"](#4bit-权重量化)章节的内容,把 16bit 权重量化为 4bit 权重,然后再按下述说明推理
14
+
15
+
16
+ ```shell
17
+ git-lfs install
18
+ git clone https://huggingface.co/lmdeploy/internlm-chat-7b-w4
19
+ ```
20
+
21
+ 执行以下命令,即可在终端与模型对话:
22
+
23
+ ```shell
24
+
25
+ ## 转换模型的layout,存放在默认路径 ./workspace 下
26
+ python3 -m lmdeploy.serve.turbomind.deploy \
27
+ --model-name internlm \
28
+ --model-path ./internlm-chat-7b-w4 \
29
+ --model-format awq \
30
+ --group-size 128
31
+
32
+ ## 推理
33
+ python3 -m lmdeploy.turbomind.chat ./workspace
34
+ ```
35
+
36
+ ## 启动 gradio 服务
37
+
38
+ 如果想通过 webui 与模型对话,请执行以下命令启动 gradio 服务
39
+
40
+ ```shell
41
+ python3 -m lmdeploy.serve.turbomind ./workspace --server_name {ip_addr} ----server_port {port}
42
+ ```
43
+
44
+ 然后,在浏览器中打开 http://{ip_addr}:{port},即可在线对话
45
+
46
+ ## 推理速度
47
+
48
+ 我们在 NVIDIA GeForce RTX 4090 上使用 [profile_generation.py](https://github.com/InternLM/lmdeploy/blob/main/benchmark/profile_generation.py),分别测试了 4-bit Llama-2-7B 和 Llama-2-13B 模型的 token 生成速度。测试配置为 batch size = 1,(prompt_tokens, completion_tokens) = (1, 512)
49
+
50
+ | model | llm-awq | mlc-llm | turbomind |
51
+ | ----------- | ------- | ------- | --------- |
52
+ | Llama 2 7B | 112.9 | 159.4 | 206.4 |
53
+ | Llama 2 13B | N/A | 90.7 | 115.8 |
54
+
55
+ ```shell
56
+ python benchmark/profile_generation.py \
57
+ ./workspace \
58
+ --concurrency 1 --input_seqlen 1 --output_seqlen 512
59
+ ```
60
+
61
+ ## 4bit 权重量化
62
+
63
+ 4bit 权重量化包括 2 步:
64
+
65
+ - 生成量化参数
66
+ - 根据量化参数,量化模型权重
67
+
68
+ ### 第一步:生成量化参数
69
+
70
+ ```shell
71
+ python3 -m lmdeploy.lite.apis.calibrate \
72
+ --model $HF_MODEL \
73
+ --calib_dataset 'c4' \ # 校准数据集,支持 c4, ptb, wikitext2, pileval
74
+ --calib_samples 128 \ # 校准集的样本数,如果显存不够,可以适当调小
75
+ --calib_seqlen 2048 \ # 单条的文本长度,如果显存不够,可以适当调小
76
+ --work_dir $WORK_DIR \ # 保存 Pytorch 格式量化统计参数和量化后权重的文件夹
77
+ ```
78
+
79
+ ### 第二步:量化权重模型
80
+
81
+ LMDeploy 使用 AWQ 算法对模型权重进行量化。在执行下面的命令时,需要把步骤1的`$WORK_DIR`传入。量化结束后,权重文件也会存放在这个目录中。然后就可以根据 ["4bit权重模型推理"](#4bit-权重模型推理)章节的说明,进行模型推理。
82
+
83
+ ```shell
84
+ python3 -m lmdeploy.lite.apis.auto_awq \
85
+ --model $HF_MODEL \
86
+ --w_bits 4 \ # 权重量化的 bit 数
87
+ --w_group_size 128 \ # 权重量化分组统计尺寸
88
+ --work_dir $WORK_DIR \ # 步骤 1 保存量化参数的目录
89
+ ```