Commit
·
5ae26f2
1
Parent(s):
0935c6f
Update README.md
Browse files
README.md
CHANGED
|
@@ -3,4 +3,111 @@ license: apache-2.0
|
|
| 3 |
tags:
|
| 4 |
- text-generation-inference
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
- text-generation-inference
|
| 5 |
pipeline_tag: text-generation
|
| 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 |
+
|
| 37 |
+
```shell
|
| 38 |
+
git-lfs install
|
| 39 |
+
git clone https://huggingface.co/lmdeploy/internlm-chat-7b-w4
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
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
|
| 43 |
+
|
| 44 |
+
```shell
|
| 45 |
+
|
| 46 |
+
## Convert the model's layout and store it in the default path, ./workspace.
|
| 47 |
+
python3 -m lmdeploy.serve.turbomind.deploy \
|
| 48 |
+
--model-name internlm \
|
| 49 |
+
--model-path ./internlm-chat-7b-w4 \
|
| 50 |
+
--model-format awq \
|
| 51 |
+
--group-size 128
|
| 52 |
+
|
| 53 |
+
## inference
|
| 54 |
+
python3 -m lmdeploy.turbomind.chat ./workspace
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Serve with gradio
|
| 58 |
+
|
| 59 |
+
If you wish to interact with the model via web ui, please initiate the gradio server as indicated below:
|
| 60 |
+
|
| 61 |
+
```shell
|
| 62 |
+
python3 -m lmdeploy.serve.turbomind ./workspace --server_name {ip_addr} ----server_port {port}
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Subsequently, you can open the website `http://{ip_addr}:{port}` in your browser and interact with the model
|
| 66 |
+
|
| 67 |
+
## Inference Performance
|
| 68 |
+
|
| 69 |
+
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.
|
| 70 |
+
|
| 71 |
+
| model | llm-awq | mlc-llm | turbomind |
|
| 72 |
+
| ----------- | ------- | ------- | --------- |
|
| 73 |
+
| Llama 2 7B | 112.9 | 159.4 | 206.4 |
|
| 74 |
+
| Llama 2 13B | N/A | 90.7 | 115.8 |
|
| 75 |
+
|
| 76 |
+
```shell
|
| 77 |
+
python benchmark/profile_generation.py \
|
| 78 |
+
./workspace \
|
| 79 |
+
--concurrency 1 --input_seqlen 1 --output_seqlen 512
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
## 4-bit Weight Quantization
|
| 83 |
+
|
| 84 |
+
It includes two steps:
|
| 85 |
+
|
| 86 |
+
- generate quantization parameter
|
| 87 |
+
- quantize model according to the parameter
|
| 88 |
+
|
| 89 |
+
### Step 1: Generate Quantization Parameter
|
| 90 |
+
|
| 91 |
+
```shell
|
| 92 |
+
python3 -m lmdeploy.lite.apis.calibrate \
|
| 93 |
+
--model $HF_MODEL \
|
| 94 |
+
--calib_dataset 'c4' \ # Calibration dataset, supports c4, ptb, wikitext2, pileval
|
| 95 |
+
--calib_samples 128 \ # Number of samples in the calibration set, if memory is insufficient, you can appropriately reduce this
|
| 96 |
+
--calib_seqlen 2048 \ # Length of a single piece of text, if memory is insufficient, you can appropriately reduce this
|
| 97 |
+
--work_dir $WORK_DIR \ # Folder storing Pytorch format quantization statistics parameters and post-quantization weight
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### Step2: Quantize Weights
|
| 101 |
+
|
| 102 |
+
LMDeploy employs AWQ algorithm for model weight quantization.
|
| 103 |
+
|
| 104 |
+
```shell
|
| 105 |
+
python3 -m lmdeploy.lite.apis.auto_awq \
|
| 106 |
+
--model $HF_MODEL \
|
| 107 |
+
--w_bits 4 \ # Bit number for weight quantization
|
| 108 |
+
--w_sym False \ # Whether to use symmetric quantization for weights
|
| 109 |
+
--w_group_size 128 \ # Group size for weight quantization statistics
|
| 110 |
+
--work_dir $WORK_DIR \ # Directory saving quantization parameters from Step 1
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
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.
|