README.md 4.2 KB
Newer Older
D
Dong Daxiang 已提交
1
# Paddle Serving
D
Dong Daxiang 已提交
2
An easy-to-use Machine Learning Model Inference Service Deployment Tool
D
Dong Daxiang 已提交
3

D
Dong Daxiang 已提交
4
[![Release](https://img.shields.io/badge/Release-0.0.3-yellowgreen)](Release)
D
Dong Daxiang 已提交
5
[![Issues](https://img.shields.io/github/issues/PaddlePaddle/Serving)](Issues)
D
Dong Daxiang 已提交
6 7
[![License](https://img.shields.io/github/license/PaddlePaddle/Serving)](LICENSE)

D
Dong Daxiang 已提交
8 9
[中文](./README_CN.md)

D
Dong Daxiang 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Paddle Serving is the online inference service framework of [Paddle](https://github.com/PaddlePaddle/Paddle) that can help developers easily deploy a deep learning model service on server side and send request from mobile devices, edge devices as well as data centers. Currently, Paddle Serving supports the deep learning models produced by Paddle althought it can be very easy to support other deep learning framework's model inference. Paddle Serving is designed oriented from industrial practice. For example, multiple models management for online service, double buffers model loading, models online A/B testing are supported. Highly concurrent [Baidu-rpc](https://github.com/apache/incubator-brpc) is used as the underlying communication library which is also from industry practice. Paddle Serving provides user-friendly API that can integrate with Paddle training code seamlessly, and users can finish model training and model serving in an end-to-end fasion.



## Quick Start

Paddle Serving supports light-weighted Python API for model inference and can be integrated with trainining process seemlessly. Here is a Boston House Pricing example for users to do quick start.

### Installation

```shell
pip install paddle-serving-client
pip install paddle-serving-server
```

### Training Scripts

``` python
import sys
import paddle

train_reader = paddle.batch(paddle.reader.shuffle(
    paddle.dataset.uci_housing.train(), buf_size=500), batch_size=16)

D
Dong Daxiang 已提交
34 35
x = paddle.fluid.data(name='x', shape=[None, 13], dtype='float32')
y = paddle.fluid.data(name='y', shape=[None, 1], dtype='float32')
D
Dong Daxiang 已提交
36

D
Dong Daxiang 已提交
37 38 39 40
y_predict = paddle.fluid.layers.fc(input=x, size=1, act=None)
cost = paddle.fluid.layers.square_error_cost(input=y_predict, label=y)
avg_loss = paddle.fluid.layers.mean(cost)
sgd_optimizer = paddle.fluid.optimizer.SGD(learning_rate=0.01)
D
Dong Daxiang 已提交
41 42
sgd_optimizer.minimize(avg_loss)

D
Dong Daxiang 已提交
43 44 45 46
place = paddle.fluid.CPUPlace()
feeder = paddle.fluid.DataFeeder(place=place, feed_list=[x, y])
exe = paddle.fluid.Executor(place)
exe.run(paddle.fluid.default_startup_program())
D
Dong Daxiang 已提交
47 48 49 50 51 52

import paddle_serving_client.io as serving_io

for pass_id in range(30):
    for data_train in train_reader():
        avg_loss_value, = exe.run(
D
Dong Daxiang 已提交
53
            paddle.fluid.default_main_program(),
D
Dong Daxiang 已提交
54 55 56 57 58
            feed=feeder.feed(data_train),
            fetch_list=[avg_loss])

serving_io.save_model(
    "serving_server_model", "serving_client_conf",
D
Dong Daxiang 已提交
59
    {"x": x}, {"y": y_predict}, paddle.fluid.default_main_program())
D
Dong Daxiang 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
```



### Server Side Scripts

```
import sys
from paddle_serving.serving_server import OpMaker
from paddle_serving.serving_server import OpSeqMaker
from paddle_serving.serving_server import Server

op_maker = OpMaker()
read_op = op_maker.create('general_reader')
general_infer_op = op_maker.create('general_infer')

op_seq_maker = OpSeqMaker()
op_seq_maker.add_op(read_op)
op_seq_maker.add_op(general_infer_op)

server = Server()
server.set_op_sequence(op_seq_maker.get_op_sequence())
server.load_model_config(sys.argv[1])
server.prepare_server(workdir="work_dir1", port=9393, device="cpu")
```

### Start Server

```
python test_server.py serving_server_model
```

### Client Side Scripts

```
from paddle_serving_client import Client
import paddle
import sys

client = Client()
client.load_client_config(sys.argv[1])
client.connect(["127.0.0.1:9292"])

test_reader = paddle.batch(paddle.reader.shuffle(
    paddle.dataset.uci_housing.test(), buf_size=500), batch_size=1)

for data in test_reader():
    fetch_map = client.predict(feed={"x": data[0][0]}, fetch=["y"])
    print("{} {}".format(fetch_map["y"][0], data[0][1][0]))


```



### Document

[Design Doc(Chinese)](doc/DESIGN.md)

[FAQ(Chinese)](doc/FAQ.md)

### Advanced features and development

[Develop a serving application with C++(Chinese)](doc/CREATING.md)

[Compile from source code(Chinese)](doc/INSTALL.md)

## Contribution

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