unsubscribe
commited on
Commit
·
ee56a27
1
Parent(s):
3f4f3be
Update README.md
Browse files
README.md
CHANGED
@@ -3,4 +3,112 @@ license: llama2
|
|
3 |
pipeline_tag: text-generation
|
4 |
tags:
|
5 |
- text-generation-inference
|
6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
pipeline_tag: text-generation
|
4 |
tags:
|
5 |
- text-generation-inference
|
6 |
+
---
|
7 |
+
|
8 |
+
<div align="center">
|
9 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/64ccdc322e592905f922a06e/VhwQtaklohkUXFWkjA-3M.png" width="450"/>
|
10 |
+
|
11 |
+
English | [简体中文](README_zh-CN.md)
|
12 |
+
|
13 |
+
</div>
|
14 |
+
|
15 |
+
<p align="center">
|
16 |
+
👋 join us on <a href="https://twitter.com/intern_lm" target="_blank">Twitter</a>, <a href="https://discord.gg/xa29JuW87d" target="_blank">Discord</a> and <a href="https://r.vansin.top/?r=internwx" target="_blank">WeChat</a>
|
17 |
+
</p>
|
18 |
+
|
19 |
+
|
20 |
+
# W4A16 LLM Model Deployment
|
21 |
+
|
22 |
+
LMDeploy supports LLM model inference of 4-bit weight, with the minimum requirement for NVIDIA graphics cards being sm80.
|
23 |
+
|
24 |
+
Before proceeding with the inference, please ensure that lmdeploy(>=v0.0.4) is installed.
|
25 |
+
|
26 |
+
```shell
|
27 |
+
pip install lmdeploy
|
28 |
+
```
|
29 |
+
|
30 |
+
## 4-bit LLM model Inference
|
31 |
+
|
32 |
+
You can download the pre-quantized 4-bit weight models from LMDeploy's [model zoo](https://huggingface.co/lmdeploy) and conduct inference using the following command.
|
33 |
+
|
34 |
+
Alternatively, you can quantize 16-bit weights to 4-bit weights following the ["4-bit Weight Quantization"](#4-bit-weight-quantization) section, and then perform inference as per the below instructions.
|
35 |
+
|
36 |
+
Take the 4-bit Llama-2-7B model from the model zoo as an example:
|
37 |
+
|
38 |
+
```shell
|
39 |
+
git-lfs install
|
40 |
+
git clone https://huggingface.co/lmdeploy/llama2-chat-7b-w4
|
41 |
+
```
|
42 |
+
|
43 |
+
As demonstrated in the command below, first convert the model's layout using `turbomind.deploy`, and then you can interact with the AI assistant in the terminal
|
44 |
+
|
45 |
+
```shell
|
46 |
+
|
47 |
+
## Convert the model's layout and store it in the default path, ./workspace.
|
48 |
+
python3 -m lmdeploy.serve.turbomind.deploy \
|
49 |
+
--model-name llama2 \
|
50 |
+
--model-path ./llama2-chat-7b-w4 \
|
51 |
+
--model-format awq \
|
52 |
+
--group-size 128
|
53 |
+
|
54 |
+
## inference
|
55 |
+
python3 -m lmdeploy.turbomind.chat ./workspace
|
56 |
+
```
|
57 |
+
|
58 |
+
## Serve with gradio
|
59 |
+
|
60 |
+
If you wish to interact with the model via web ui, please initiate the gradio server as indicated below:
|
61 |
+
|
62 |
+
```shell
|
63 |
+
python3 -m lmdeploy.serve.turbomind ./workspace --server_name {ip_addr} ----server_port {port}
|
64 |
+
```
|
65 |
+
|
66 |
+
Subsequently, you can open the website `http://{ip_addr}:{port}` in your browser and interact with the model
|
67 |
+
|
68 |
+
## Inference Performance
|
69 |
+
|
70 |
+
We benchmarked the Llama 2 7B and 13B with 4-bit quantization on NVIDIA GeForce RTX 4090 using [profile_generation.py](https://github.com/InternLM/lmdeploy/blob/main/benchmark/profile_generation.py). And we measure the token generation throughput (tokens/s) by setting a single prompt token and generating 512 tokens. All the results are measured for single batch inference.
|
71 |
+
|
72 |
+
| model | llm-awq | mlc-llm | turbomind |
|
73 |
+
| ----------- | ------- | ------- | --------- |
|
74 |
+
| Llama 2 7B | 112.9 | 159.4 | 206.4 |
|
75 |
+
| Llama 2 13B | N/A | 90.7 | 115.8 |
|
76 |
+
|
77 |
+
```shell
|
78 |
+
python benchmark/profile_generation.py \
|
79 |
+
./workspace \
|
80 |
+
--concurrency 1 --input_seqlen 1 --output_seqlen 512
|
81 |
+
```
|
82 |
+
|
83 |
+
## 4-bit Weight Quantization
|
84 |
+
|
85 |
+
It includes two steps:
|
86 |
+
|
87 |
+
- generate quantization parameter
|
88 |
+
- quantize model according to the parameter
|
89 |
+
|
90 |
+
### Step 1: Generate Quantization Parameter
|
91 |
+
|
92 |
+
```shell
|
93 |
+
python3 -m lmdeploy.lite.apis.calibrate \
|
94 |
+
--model $HF_MODEL \
|
95 |
+
--calib_dataset 'c4' \ # Calibration dataset, supports c4, ptb, wikitext2, pileval
|
96 |
+
--calib_samples 128 \ # Number of samples in the calibration set, if memory is insufficient, you can appropriately reduce this
|
97 |
+
--calib_seqlen 2048 \ # Length of a single piece of text, if memory is insufficient, you can appropriately reduce this
|
98 |
+
--work_dir $WORK_DIR \ # Folder storing Pytorch format quantization statistics parameters and post-quantization weight
|
99 |
+
```
|
100 |
+
|
101 |
+
### Step2: Quantize Weights
|
102 |
+
|
103 |
+
LMDeploy employs AWQ algorithm for model weight quantization.
|
104 |
+
|
105 |
+
```shell
|
106 |
+
python3 -m lmdeploy.lite.apis.auto_awq \
|
107 |
+
--model $HF_MODEL \
|
108 |
+
--w_bits 4 \ # Bit number for weight quantization
|
109 |
+
--w_sym False \ # Whether to use symmetric quantization for weights
|
110 |
+
--w_group_size 128 \ # Group size for weight quantization statistics
|
111 |
+
--work_dir $WORK_DIR \ # Directory saving quantization parameters from Step 1
|
112 |
+
```
|
113 |
+
|
114 |
+
After the quantization is complete, the quantized model is saved to `$WORK_DIR`. Then you can proceed with model inference according to the instructions in the ["4-Bit Weight Model Inference"](#4-bit-llm-model-inference) section.
|