README.md 8.9 KB
Newer Older
M
MRXLT 已提交
1 2
([简体中文](./README_CN.md)|English)

D
Dong Daxiang 已提交
3 4
<p align="center">
    <br>
D
Dong Daxiang 已提交
5
<img src='doc/serving_logo.png' width = "600" height = "130">
D
Dong Daxiang 已提交
6 7
    <br>
<p>
8

M
MRXLT 已提交
9

D
Dong Daxiang 已提交
10 11
<p align="center">
    <br>
B
barrierye 已提交
12 13 14
    <a href="https://travis-ci.com/PaddlePaddle/Serving">
        <img alt="Build Status" src="https://img.shields.io/travis/com/PaddlePaddle/Serving/develop">
    </a>
D
Dong Daxiang 已提交
15 16 17 18
    <img alt="Release" src="https://img.shields.io/badge/Release-0.0.3-yellowgreen">
    <img alt="Issues" src="https://img.shields.io/github/issues/PaddlePaddle/Serving">
    <img alt="License" src="https://img.shields.io/github/license/PaddlePaddle/Serving">
    <img alt="Slack" src="https://img.shields.io/badge/Join-Slack-green">
D
Dong Daxiang 已提交
19 20
    <br>
<p>
D
Dong Daxiang 已提交
21

D
Dong Daxiang 已提交
22
<h2 align="center">Motivation</h2>
D
Dong Daxiang 已提交
23

J
Jiawei Wang 已提交
24
We consider deploying deep learning inference service online to be a user-facing application in the future. **The goal of this project**: When you have trained a deep neural net with [Paddle](https://github.com/PaddlePaddle/Paddle), you are also capable to deploy the model online easily. A demo of Paddle Serving is as follows:
D
Dong Daxiang 已提交
25
<p align="center">
D
Dong Daxiang 已提交
26
    <img src="doc/demo.gif" width="700">
D
Dong Daxiang 已提交
27
</p>
D
Dong Daxiang 已提交
28 29


D
Dong Daxiang 已提交
30
<h2 align="center">Installation</h2>
D
Dong Daxiang 已提交
31

B
barrierye 已提交
32
We **highly recommend** you to **run Paddle Serving in Docker**, please visit [Run in Docker](https://github.com/PaddlePaddle/Serving/blob/develop/doc/RUN_IN_DOCKER.md)
M
MRXLT 已提交
33 34
```
# Run CPU Docker
B
barrierye 已提交
35 36
docker pull hub.baidubce.com/paddlepaddle/serving:latest
docker run -p 9292:9292 --name test -dit hub.baidubce.com/paddlepaddle/serving:latest
M
MRXLT 已提交
37 38 39 40
docker exec -it test bash
```
```
# Run GPU Docker
B
barrierye 已提交
41 42
nvidia-docker pull hub.baidubce.com/paddlepaddle/serving:latest-gpu
nvidia-docker run -p 9292:9292 --name test -dit hub.baidubce.com/paddlepaddle/serving:latest-gpu
M
MRXLT 已提交
43 44
nvidia-docker exec -it test bash
```
D
Dong Daxiang 已提交
45

D
Dong Daxiang 已提交
46
```shell
M
MRXLT 已提交
47 48 49
pip install paddle-serving-client 
pip install paddle-serving-server # CPU
pip install paddle-serving-server-gpu # GPU
D
Dong Daxiang 已提交
50 51
```

M
MRXLT 已提交
52
You may need to use a domestic mirror source (in China, you can use the Tsinghua mirror source, add `-i https://pypi.tuna.tsinghua.edu.cn/simple` to pip command) to speed up the download.
B
barrierye 已提交
53

M
MRXLT 已提交
54 55
If you need install modules compiled with develop branch, please download packages from [latest packages list](./doc/LATEST_PACKAGES.md) and install with `pip install` command.

M
MRXLT 已提交
56
Packages of paddle-serving-server and paddle-serving-server-gpu support Centos 6/7 and Ubuntu 16/18.
57

M
MRXLT 已提交
58 59 60
Packages of paddle-serving-client and paddle-serving-app support Linux and Windows, but only support python2.7/3.6/3.7.

Recommended to install paddle >= 1.8.2.
D
Dong Daxiang 已提交
61 62 63 64 65 66

<h2 align="center"> Pre-built services with Paddle Serving</h2>

<h3 align="center">Chinese Word Segmentation</h4>

``` shell
M
MRXLT 已提交
67
> python -m paddle_serving_app.package --get_model lac
D
Dong Daxiang 已提交
68
> tar -xzf lac.tar.gz
M
MRXLT 已提交
69
> python lac_web_service.py lac_model/ lac_workdir 9393 &
D
Dong Daxiang 已提交
70 71 72 73 74 75 76 77 78 79 80
> curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "我爱北京天安门"}], "fetch":["word_seg"]}' http://127.0.0.1:9393/lac/prediction
{"result":[{"word_seg":"我|爱|北京|天安门"}]}
```

<h3 align="center">Image Classification</h4>

<p align="center">
    <br>
<img src='https://paddle-serving.bj.bcebos.com/imagenet-example/daisy.jpg' width = "200" height = "200">
    <br>
<p>
D
Dong Daxiang 已提交
81
    
D
Dong Daxiang 已提交
82
``` shell
M
MRXLT 已提交
83
> python -m paddle_serving_app.package --get_model resnet_v2_50_imagenet
D
Dong Daxiang 已提交
84 85 86 87
> tar -xzf resnet_v2_50_imagenet.tar.gz
> python resnet50_imagenet_classify.py resnet50_serving_model &
> curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"image": "https://paddle-serving.bj.bcebos.com/imagenet-example/daisy.jpg"}], "fetch": ["score"]}' http://127.0.0.1:9292/image/prediction
{"result":{"label":["daisy"],"prob":[0.9341403245925903]}}
D
Dong Daxiang 已提交
88 89 90
```


D
Dong Daxiang 已提交
91
<h2 align="center">Quick Start Example</h2>
D
Dong Daxiang 已提交
92

D
Dong Daxiang 已提交
93 94
This quick start example is only for users who already have a model to deploy and we prepare a ready-to-deploy model here. If you want to know how to use paddle serving from offline training to online serving, please reference to [Train_To_Service](https://github.com/PaddlePaddle/Serving/blob/develop/doc/TRAIN_TO_SERVICE.md)

D
Dong Daxiang 已提交
95
### Boston House Price Prediction model
D
Dong Daxiang 已提交
96
``` shell
D
Dong Daxiang 已提交
97
wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
D
Dong Daxiang 已提交
98
tar -xzf uci_housing.tar.gz
D
Dong Daxiang 已提交
99
```
D
Dong Daxiang 已提交
100

D
Dong Daxiang 已提交
101 102
Paddle Serving provides HTTP and RPC based service for users to access

D
Dong Daxiang 已提交
103
### HTTP service
D
Dong Daxiang 已提交
104

J
Jiawei Wang 已提交
105
Paddle Serving provides a built-in python module called `paddle_serving_server.serve` that can start a RPC service or a http service with one-line command. If we specify the argument `--name uci`, it means that we will have a HTTP service with a url of `$IP:$PORT/uci/prediction`
D
Dong Daxiang 已提交
106
``` shell
D
Dong Daxiang 已提交
107
python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9292 --name uci
D
Dong Daxiang 已提交
108
```
D
Dong Daxiang 已提交
109 110
<center>

D
Dong Daxiang 已提交
111 112
| Argument | Type | Default | Description |
|--------------|------|-----------|--------------------------------|
D
Dong Daxiang 已提交
113
| `thread` | int | `4` | Concurrency of current service |
D
Dong Daxiang 已提交
114
| `port` | int | `9292` | Exposed port of current service to users|
D
Dong Daxiang 已提交
115 116
| `name` | str | `""` | Service name, can be used to generate HTTP request url |
| `model` | str | `""` | Path of paddle model directory to be served |
M
MRXLT 已提交
117 118 119
| `mem_optim` | - | - | Enable memory / graphic memory optimization |
| `ir_optim` | - | - | Enable analysis and optimization of calculation graph |
| `use_mkl` (Only for cpu version) | - | - | Run inference with MKL |
D
Dong Daxiang 已提交
120

D
Dong Daxiang 已提交
121
Here, we use `curl` to send a HTTP POST request to the service we just started. Users can use any python library to send HTTP POST as well, e.g, [requests](https://requests.readthedocs.io/en/master/).
D
Dong Daxiang 已提交
122 123
</center>

D
Dong Daxiang 已提交
124
``` shell
M
MRXLT 已提交
125
curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' http://127.0.0.1:9292/uci/prediction
D
Dong Daxiang 已提交
126
```
D
Dong Daxiang 已提交
127

D
Dong Daxiang 已提交
128
### RPC service
D
Dong Daxiang 已提交
129

J
Jiawei Wang 已提交
130
A user can also start a RPC service with `paddle_serving_server.serve`. RPC service is usually faster than HTTP service, although a user needs to do some coding based on Paddle Serving's python client API. Note that we do not specify `--name` here. 
D
Dong Daxiang 已提交
131 132 133
``` shell
python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9292
```
D
Dong Daxiang 已提交
134

D
Dong Daxiang 已提交
135
``` python
D
Dong Daxiang 已提交
136
# A user can visit rpc service through paddle_serving_client API
D
Dong Daxiang 已提交
137 138 139
from paddle_serving_client import Client

client = Client()
D
Dong Daxiang 已提交
140
client.load_client_config("uci_housing_client/serving_client_conf.prototxt")
D
Dong Daxiang 已提交
141
client.connect(["127.0.0.1:9292"])
D
Dong Daxiang 已提交
142
data = [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727,
D
Dong Daxiang 已提交
143
        -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]
D
Dong Daxiang 已提交
144
fetch_map = client.predict(feed={"x": data}, fetch=["price"])
D
Dong Daxiang 已提交
145
print(fetch_map)
D
Dong Daxiang 已提交
146 147

```
D
Dong Daxiang 已提交
148
Here, `client.predict` function has two arguments. `feed` is a `python dict` with model input variable alias name and values. `fetch` assigns the prediction variables to be returned from servers. In the example, the name of `"x"` and `"price"` are assigned when the servable model is saved during training.
D
Dong Daxiang 已提交
149

D
Dong Daxiang 已提交
150
<h2 align="center">Some Key Features of Paddle Serving</h2>
M
MRXLT 已提交
151

D
Dong Daxiang 已提交
152 153 154 155 156
- Integrate with Paddle training pipeline seamlessly, most paddle models can be deployed **with one line command**.
- **Industrial serving features** supported, such as models management, online loading, online A/B testing etc.
- **Distributed Key-Value indexing** supported which is especially useful for large scale sparse features as model inputs.
- **Highly concurrent and efficient communication** between clients and servers supported.
- **Multiple programming languages** supported on client side, such as Golang, C++ and python.
M
MRXLT 已提交
157

D
Dong Daxiang 已提交
158
<h2 align="center">Document</h2>
D
Dong Daxiang 已提交
159

D
Dong Daxiang 已提交
160
### New to Paddle Serving
D
Dong Daxiang 已提交
161
- [How to save a servable model?](doc/SAVE.md)
J
Jiawei Wang 已提交
162
- [An End-to-end tutorial from training to inference service deployment](doc/TRAIN_TO_SERVICE.md)
J
Jiawei Wang 已提交
163
- [Write Bert-as-Service in 10 minutes](doc/BERT_10_MINS.md)
D
Dong Daxiang 已提交
164

D
Dong Daxiang 已提交
165
### Developers
D
Dong Daxiang 已提交
166
- [How to config Serving native operators on server side?](doc/SERVER_DAG.md)
J
Jiawei Wang 已提交
167
- [How to develop a new Serving operator?](doc/NEW_OPERATOR.md)
B
barrierye 已提交
168
- [How to develop a new Web Service?](doc/NEW_WEB_SERVICE.md)
D
Dong Daxiang 已提交
169
- [Golang client](doc/IMDB_GO_CLIENT.md)
J
Jiawei Wang 已提交
170
- [Compile from source code](doc/COMPILE.md)
M
MRXLT 已提交
171 172
- [Deploy Web Service with uWSGI](doc/UWSGI_DEPLOY.md)
- [Hot loading for model file](doc/HOT_LOADING_IN_SERVING.md)
D
Dong Daxiang 已提交
173

D
Dong Daxiang 已提交
174
### About Efficiency
M
MRXLT 已提交
175
- [How to profile Paddle Serving latency?](python/examples/util)
M
MRXLT 已提交
176
- [How to optimize performance?](doc/PERFORMANCE_OPTIM.md)
M
MRXLT 已提交
177
- [Deploy multi-services on one GPU(Chinese)](doc/MULTI_SERVICE_ON_ONE_GPU_CN.md)
J
Jiawei Wang 已提交
178 179
- [CPU Benchmarks(Chinese)](doc/BENCHMARKING.md)
- [GPU Benchmarks(Chinese)](doc/GPU_BENCHMARKING.md)
D
Dong Daxiang 已提交
180

D
Dong Daxiang 已提交
181
### FAQ
M
add FAQ  
MRXLT 已提交
182
- [FAQ(Chinese)](doc/FAQ.md)
D
Dong Daxiang 已提交
183

D
Dong Daxiang 已提交
184

D
Dong Daxiang 已提交
185
### Design
J
Jiawei Wang 已提交
186
- [Design Doc](doc/DESIGN_DOC.md)
D
Dong Daxiang 已提交
187

D
Dong Daxiang 已提交
188 189
<h2 align="center">Community</h2>

D
Dong Daxiang 已提交
190

D
Dong Daxiang 已提交
191
### Slack
D
Dong Daxiang 已提交
192

D
Dong Daxiang 已提交
193 194
To connect with other users and contributors, welcome to join our [Slack channel](https://paddleserving.slack.com/archives/CUBPKHKMJ)

D
Dong Daxiang 已提交
195
### Contribution
D
Dong Daxiang 已提交
196

D
Dong Daxiang 已提交
197
If you want to contribute code to Paddle Serving, please reference [Contribution Guidelines](doc/CONTRIBUTE.md)
D
Dong Daxiang 已提交
198 199

### Feedback
D
Dong Daxiang 已提交
200

D
Dong Daxiang 已提交
201 202
For any feedback or to report a bug, please propose a [GitHub Issue](https://github.com/PaddlePaddle/Serving/issues).

D
Dong Daxiang 已提交
203 204
### License

D
Dong Daxiang 已提交
205
[Apache 2.0 License](https://github.com/PaddlePaddle/Serving/blob/develop/LICENSE)