@@ -6,13 +6,14 @@ This document is an e2e tutorial of offline training and online inference for a
6
6
- Tensorflow model serving.
7
7
8
8
Here is an example of a supervised job with EgoBipartiteSage, containing the following sections.
9
- 1 . Prepare data, including bulk-loading data for offline training and streaming data for online inference.
10
- 2 . Train the EgoBipartiteSage model using the offline bulk-loading data.
11
- 3 . Exporting TF model.
12
- 4 . Deploying TF model on tensorflow model serving.
9
+ 1 . Prepare u2i and i2i bipartite graph data, including bulk-loading data for offline training and streaming data for online inference.
10
+ 2 . Train the EgoBipartiteSage model using the offline bulk-loading data, it contains user model and item model .
11
+ 3 . Exporting user model.
12
+ 4 . Deploying the model on tensorflow model serving.
13
13
5 . Deploy the online dynamic graph service and ingest the streaming data.
14
14
6 . Start Java Client, sample and predict.
15
15
16
+ The first 3 parts need to use the training framework GraphLearn-Training, a detailed description refs:[ GraphLearn-Training] ( ../gl/intro.md ) .
16
17
17
18
## 1. Prepare data
18
19
@@ -33,81 +34,53 @@ The generated data are stored in `/tmp/u2i_gen/training` and `/tmp/u2i_gen/strea
33
34
34
35
## 2. Train model offline
35
36
36
- FIXME(@Seventeen17 ): refactor this section
37
37
``` shell
38
- cd graphlearn/examples/tf/ego_sage
39
- python train_supervised .py
38
+ cd graphlearn/examples/tf/ego_bipartite_sage
39
+ python train .py
40
40
```
41
41
42
42
Ref to [ GraphLearn-Training] ( ../gl/intro.md ) for more details.
43
43
44
44
45
45
## 3. Export TF SavedModel
46
46
47
- FIXME(@Seventeen17 ): refactor this section
48
47
49
48
First, export model as tf SavedModel, we need to filter some of the placeholders as model serving inputs based on the
50
49
computational graph, you can view the computational graph with the help of Tensorboard to determine the inputs for the
51
50
serving subgraph.
52
51
53
- The offline training model is saved in ` graphlearn/examples/tf/ego_sage /ckpt ` , and we save the final serving model in
54
- ` ./ego_sage_sup_model ` directory, the inputs to the subgraphs are the placeholders ` 0,2,3 ` .
52
+ The offline training model is saved in ` graphlearn/examples/tf/ego_bipartite_sage /ckpt ` , and we save the final serving model in
53
+ ` graphlearn/examples/tf/serving/ego_bipartite_sage ` directory, the inputs to the user-subgraph are the placeholders ` 0,3,4 ` according to TensorBoard .
55
54
56
55
``` shell
57
56
cd graphlearn/examples/tf/serving
58
- python export_serving_model.py ../ego_sage ckpt ego_sage_sup_model 0,2,3
57
+ python export_serving_model.py --input_ckpt_dir= ../ego_bipartite_sage --input_ckpt_name= ckpt --placeholders=0,3,4 --output_model_path=./ego_bipartite_sage
59
58
```
60
59
61
60
Check inputs and output of saved model.
62
61
``` shell
63
- saved_model_cli show --dir ego_sage_sup_model /1/ --all
62
+ saved_model_cli show --dir ego_bipartite_sage /1/ --all
64
63
```
65
64
66
- Outputs are as following.
67
- ```
68
- MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
69
-
70
- signature_def['predict_actions']:
71
- The given SavedModel SignatureDef contains the following input(s):
72
- inputs['IteratorGetNext_ph_input_0'] tensor_info:
73
- dtype: DT_FLOAT
74
- shape: (-1, 1433)
75
- name: IteratorGetNext_placeholder:0
76
- inputs['IteratorGetNext_ph_input_2'] tensor_info:
77
- dtype: DT_FLOAT
78
- shape: (-1, 1433)
79
- name: IteratorGetNext_placeholder_2:0
80
- inputs['IteratorGetNext_ph_input_3'] tensor_info:
81
- dtype: DT_FLOAT
82
- shape: (-1, 1433)
83
- name: IteratorGetNext_placeholder_3:0
84
- The given SavedModel SignatureDef contains the following output(s):
85
- outputs['output_embeddings'] tensor_info:
86
- dtype: DT_FLOAT
87
- shape: (-1, 7)
88
- name: output_embeddings:0
89
- Method name is: tensorflow/serving/predict
90
- ```
91
-
92
-
93
65
## 4. Deploy TF Model
94
- FIXME(@Seventeen17 ): refactor this section
95
66
96
67
Install tensorflow-model-server.
68
+
97
69
``` shell
98
70
echo " deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | sudo tee /etc/apt/sources.list.d/tensorflow-serving.list && \
99
71
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -
100
72
apt-get update && apt-get install tensorflow-model-server
101
73
```
74
+
102
75
Start tensorflow-model-server and deploy model
76
+
103
77
``` shell
104
78
nohup tensorflow_model_server --port=9000 \
105
- --model_name=saved_model_modified \
106
- --model_base_path=/home/wenting.swt/code/graph-learn/ examples/tf/ego_sage/saved_model_modified \
79
+ --model_name=egomodel \
80
+ --model_base_path=graphlearn/ examples/tf/serving/ego_bipartite_sage \
107
81
> server.log 2>&1
108
82
```
109
83
110
-
111
84
## 5. Deploy Dynamic Graph Service.
112
85
113
86
### 5.1 Deploy kafka service
@@ -191,39 +164,18 @@ cd dynamic_graph_service/dataloader
191
164
192
165
193
166
## 6. Sample and Predict
194
- We show a quick start example without dgs.
195
- TODO( @ Seventeen17 ): replace me when dgs deployment doc is ready .
167
+
168
+ We provide a Java Client for Sampling from DGS and predict with TF model service .
196
169
197
170
```
198
- cd dgs/gsl_client
199
- mvn -Dtest=PredictClientTest test
200
- ```
171
+ cd dynamic_graph_service/gsl_client
172
+ mvn clean compile assembly:single
201
173
202
- The complete usgaes are shown in ` App ` .
203
-
204
- ``` java
205
- String server = " http://dynamic-graph-service.info" ;
206
- Graph g = Graph . connect(server);
207
-
208
- Query query = g. V (" user" ). feed(source). properties(1 ). alias(" seed" )
209
- .outV(" u2i" ). sample(15 ). by(" topk_by_timestamp" ). properties(1 ). alias(" hop1" )
210
- .outV(" i2i" ). sample(10 ). by(" topk_by_timestamp" ). properties(1 ). alias(" hop2" )
211
- .values();
212
- Status s = g. install(query);
213
-
214
- Decoder decoder = new Decoder (g);
215
- decoder. addFeatDesc(" user" ,
216
- new ArrayList<String > (Arrays . asList(" float" )),
217
- new ArrayList<Integer > (Arrays . asList(128 )));
218
- decoder. addFeatDesc(" item" ,
219
- new ArrayList<String > (Arrays . asList(" float" )),
220
- new ArrayList<Integer > (Arrays . asList(128 )));
221
- ArrayList<Integer > phs = new ArrayList<Integer > (Arrays . asList(0 , 1 , 2 ));
222
-
223
- TFPredictClient client = new TFPredictClient (decoder, " localhost" , 9000 );
224
- for (int i = 0 ; i < iters; ++ i) {
225
- Value content = g. run(query);
226
- EgoGraph egoGraph = content. getEgoGraph(" seed" );
227
- client. predict(" model" , 1 , egoGraph, phs);
228
- }
174
+ java -jar gsl_client-1.0-SNAPSHOT-jar-with-dependencies.jar http://dynamic-graph-service.info egomodel
229
175
```
176
+
177
+ Java command with the following args,
178
+ 0: DGS service host name
179
+ 1: Serving model name.
180
+
181
+ refs to ` dynamic_graph_service/gsl_client/src/main/java/org/aliyun/App.java `
0 commit comments