README.md 5.24 KB
Newer Older
lvhan028's avatar
lvhan028 committed
1
<div align="center">
lvhan028's avatar
lvhan028 committed
2
  <img src="resources/lmdeploy-logo.png" width="450"/>
lvhan028's avatar
lvhan028 committed
3
4
5
6
7

English | [简体中文](README_zh-CN.md)

</div>

8
9
10
<p align="center">
    👋 join us on <a href="https://discord.gg/xa29JuW87d" target="_blank">Discord</a> and <a href="https://r.vansin.top/?r=internwx" target="_blank">WeChat</a>
</p>
lvhan028's avatar
lvhan028 committed
11
12
13

## Introduction

lvhan028's avatar
lvhan028 committed
14
15
LMDeploy is a toolkit for compressing, deploying, and serving LLM, developed by the [MMRazor](https://github.com/open-mmlab/mmrazor) and [MMDeploy](https://github.com/open-mmlab/mmdeploy) teams. It has the following core features:

tpoisonooo's avatar
tpoisonooo committed
16
- **Efficient Inference Engine (TurboMind)**: Based on [FasterTransformer](https://github.com/NVIDIA/FasterTransformer), we have implemented an efficient inference engine - TurboMind, which supports the inference of LLaMA and its variant models on NVIDIA GPUs.
lvhan028's avatar
lvhan028 committed
17

18
- **Interactive Inference Mode**: By caching the k/v of attention during multi-round dialogue processes, it remembers dialogue history, thus avoiding repetitive processing of historical sessions.
lvhan028's avatar
lvhan028 committed
19

tpoisonooo's avatar
tpoisonooo committed
20
- **Multi-GPU Model Deployment and Quantization**: We provide comprehensive model deployment and quantification support, and have been validated at different scales.
21
22

- **Persistent Batch Inference**: Further optimization of model execution efficiency.
lvhan028's avatar
lvhan028 committed
23

pppppM's avatar
pppppM committed
24
![PersistentBatchInference](https://github.com/InternLM/lmdeploy/assets/67539920/e3876167-0671-44fc-ac52-5a0f9382493e)
lvhan028's avatar
lvhan028 committed
25

lvhan028's avatar
lvhan028 committed
26
27
28
29
30
31
32
33
34
35
36
37
## Performance

As shown in the figure below, we have compared the token generation speed among facebookresearch/llama, HuggingFace Transformers, and DeepSpeed on the 7B model.

Target Device: NVIDIA A100(80G)

Metrics: Throughput (token/s)

Test Data: The number of input tokens is 1, and the number of generated tokens is 2048

The throughput of TurboMind exceeds 2000 tokens/s, which is about 5% - 15% higher than DeepSpeed overall and outperforms huggingface transformers by up to 2.3x

pppppM's avatar
pppppM committed
38
![benchmark](https://user-images.githubusercontent.com/12756472/251422522-e94a3db9-eb16-432a-8d8c-078945e7b99a.png)
lvhan028's avatar
lvhan028 committed
39

lvhan028's avatar
lvhan028 committed
40
41
42
## Quick Start

### Installation
lvhan028's avatar
lvhan028 committed
43
44
45
46

Below are quick steps for installation:

```shell
lvhan028's avatar
lvhan028 committed
47
48
conda create -n lmdeploy python=3.10
conda activate lmdeploy
49
git clone https://github.com/InternLM/lmdeploy.git
lvhan028's avatar
lvhan028 committed
50
cd lmdeploy
lvhan028's avatar
lvhan028 committed
51
52
53
pip install -e .
```

lvhan028's avatar
lvhan028 committed
54
### Deploy InternLM
lvhan028's avatar
lvhan028 committed
55

lvhan028's avatar
lvhan028 committed
56
#### Get InternLM model
lvhan028's avatar
lvhan028 committed
57
58

```shell
lvhan028's avatar
lvhan028 committed
59
# 1. Download InternLM model
lvhan028's avatar
lvhan028 committed
60

pppppM's avatar
pppppM committed
61
62
# Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install
del-zhenwu's avatar
del-zhenwu committed
63
git clone https://huggingface.co/internlm/internlm-chat-7b /path/to/internlm-chat-7b
pppppM's avatar
pppppM committed
64
65
66
67
68

# if you want to clone without large files – just their pointers
# prepend your git clone with the following env var:
GIT_LFS_SKIP_SMUDGE=1

lvhan028's avatar
lvhan028 committed
69
# 2. Convert InternLM model to turbomind's format, which will be in "./workspace" by default
del-zhenwu's avatar
del-zhenwu committed
70
python3 -m lmdeploy.serve.turbomind.deploy internlm-7b /path/to/internlm-chat-7b hf
lvhan028's avatar
lvhan028 committed
71
72
73

```

lvhan028's avatar
lvhan028 committed
74
#### Inference by TurboMind
lvhan028's avatar
lvhan028 committed
75
76

```shell
tpoisonooo's avatar
tpoisonooo committed
77
docker run --gpus all --rm -v $(pwd)/workspace:/workspace -it openmmlab/lmdeploy:latest \
lvhan028's avatar
lvhan028 committed
78
    python3 -m lmdeploy.turbomind.chat internlm /workspace
lvhan028's avatar
lvhan028 committed
79
80
```

lvhan028's avatar
lvhan028 committed
81
82
```{note}
When inferring with FP16 precision, the InternLM-7B model requires at least 22.7G of GPU memory overhead on TurboMind. It is recommended to use NVIDIA cards such as 3090, V100, A100, etc.
lvhan028's avatar
lvhan028 committed
83
84
```

lvhan028's avatar
lvhan028 committed
85
#### Serving
lvhan028's avatar
lvhan028 committed
86

lvhan028's avatar
lvhan028 committed
87
Launch inference server by:
lvhan028's avatar
lvhan028 committed
88
89

```shell
lvhan028's avatar
lvhan028 committed
90
bash workspace/service_docker_up.sh
lvhan028's avatar
lvhan028 committed
91
92
```

lvhan028's avatar
lvhan028 committed
93
Then, you can communicate with the inference server by command line,
lvhan028's avatar
lvhan028 committed
94
95

```shell
96
python3 -m lmdeploy.serve.client {server_ip_addresss}:33337 internlm
lvhan028's avatar
lvhan028 committed
97
98
```

lvhan028's avatar
lvhan028 committed
99
or webui,
AllentDan's avatar
AllentDan committed
100

vansin's avatar
vansin committed
101
```shell
102
python3 -m lmdeploy.app {server_ip_addresss}:33337 internlm
AllentDan's avatar
AllentDan committed
103
104
```

pppppM's avatar
pppppM committed
105
![](https://github.com/InternLM/lmdeploy/assets/67539920/08d1e6f2-3767-44d5-8654-c85767cec2ab)
AllentDan's avatar
AllentDan committed
106

lvhan028's avatar
lvhan028 committed
107
For the deployment of other supported models, such as LLaMA, vicuna, you can find the guide from [here](docs/en/serving.md)
lvhan028's avatar
lvhan028 committed
108

WRH's avatar
WRH committed
109
110
111
112
113
### Inference with PyTorch

#### Single GPU

```shell
WRH's avatar
WRH committed
114
python3 -m lmdeploy.pytorch.chat $NAME_OR_PATH_TO_HF_MODEL \
WRH's avatar
WRH committed
115
116
117
118
119
120
121
122
123
    --max_new_tokens 64 \
    --temperture 0.8 \
    --top_p 0.95 \
    --seed 0
```

#### Tensor Parallel with DeepSpeed

```shell
WRH's avatar
WRH committed
124
deepspeed --module --num_gpus 2 lmdeploy.pytorch.chat \
WRH's avatar
WRH committed
125
126
127
128
129
130
131
    $NAME_OR_PATH_TO_HF_MODEL \
    --max_new_tokens 64 \
    --temperture 0.8 \
    --top_p 0.95 \
    --seed 0
```

132
133
134
## Quantization

In fp16 mode, kv_cache int8 quantization can be enabled, and a single card can serve more users.
tpoisonooo's avatar
tpoisonooo committed
135
First execute the quantization script, and the quantization parameters are stored in the `workspace/triton_models/weights` transformed by `deploy.py`.
136
137
138
139
140
141
142
143
144
145

```
python3 -m lmdeploy.lite.apis.kv_qparams \
  --model $HF_MODEL \
  --output_dir $DEPLOY_WEIGHT_DIR \
  --symmetry True \   # Whether to use symmetric or asymmetric quantization.
  --offload  False \  # Whether to offload some modules to CPU to save GPU memory.
  --num_tp 1 \   # The number of GPUs used for tensor parallelism
```

tpoisonooo's avatar
tpoisonooo committed
146
Then adjust `workspace/triton_models/weights/config.ini`
lvhan028's avatar
lvhan028 committed
147

lvhan028's avatar
lvhan028 committed
148
149
- `use_context_fmha` changed to 0, means off
- `quant_policy` is set to 4. This parameter defaults to 0, which means it is not enabled
lvhan028's avatar
lvhan028 committed
150

151
152
Here is [quantization test results](./docs/zh_cn/quantization.md).

lvhan028's avatar
lvhan028 committed
153
## Contributing
lvhan028's avatar
lvhan028 committed
154

lvhan028's avatar
lvhan028 committed
155
We appreciate all contributions to LMDeploy. Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for the contributing guideline.
156

lvhan028's avatar
lvhan028 committed
157
158
159
160
161
162
163
## Acknowledgement

- [FasterTransformer](https://github.com/NVIDIA/FasterTransformer)

## License

This project is released under the [Apache 2.0 license](LICENSE).