Skip to content

Commit 434957d

Browse files
authored
Add end-to-end tutorial for EgoBipartiteGraphSAGE model. (#216)
1. Trained with GraphLearn-Training: implement model with u2i2i and i2i2i meta-path; 2. Infered user embedding with Dynamic-Graph-Service: - Add getQuery http request; - Refine EgoGraph/EgoTensor for parsing sampled fbs records; - Refine App and add uts.
1 parent a0bf012 commit 434957d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1601
-809
lines changed

.readthedocs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ build:
1919

2020
# Build documentation in the docs/ directory with Sphinx
2121
sphinx:
22-
configuration: docs/en/conf.py
22+
configuration: docs/conf.py
2323

2424
# If using Sphinx, optionally build your docs in additional formats such as PDF
2525
# formats:

docs/en/Makefile docs/Makefile

File renamed without changes.
File renamed without changes.

docs/en/conf.py docs/conf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
import sys
1515

1616
os.system("mkdir -p apis/apis/apis/")
17-
os.system("javadoc -d apis/apis/apis/ -sourcepath ../../dynamic_graph_service/gsl_client/src/main/java/ -classpath ../../dynamic_graph_service/gsl_client/src/main/java/ org.aliyun.gsl_client")
18-
19-
17+
os.system("javadoc -d apis/apis/apis/ -sourcepath ../dynamic_graph_service/gsl_client/src/main/java/ -classpath ../dynamic_graph_service/gsl_client/src/main/java/ org.aliyun.gsl_client")
2018

2119
# -- Project information -----------------------------------------------------
2220

2321
project = 'GraphLearn'
2422
copyright = '2022, Alibaba-inc PAI'
2523
author = 'Alibaba-inc PAI'
2624

25+
root_doc = "index_" + str(os.environ.get("READTHEDOCS_LANGUAGE"))
26+
2727
# The full version, including alpha/beta/rc tags
2828
release = '2.0.0'
2929

docs/en/dgs/dataloader.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,8 @@ after all dataloader instances have set the barrier.
176176
177177
Users can also check barrier status on their gsl-clients:
178178
```java
179-
TODO(@Seventeen17): add the java example code here
179+
// public interface Graph
180+
Status checkBarrier(String name) throws UserException;
181+
182+
// if Status.ok(), then the given barrier is READY.
180183
```

docs/en/dgs/deploy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ helm install my-release dgs/dgs \
3636
```
3737

3838
The graph schema must be specified from a json string or file by parameter `graphSchema`.
39-
A [template](https://github.com/alibaba/graph-learn/blob/master/dynamic_graph_service/conf/schema.template.json)
39+
An [example](https://github.com/alibaba/graph-learn/blob/master/dynamic_graph_service/conf/u2i/schema.u2i.json)
4040
schema file can be followed to write your customized graph schema.
4141

4242
The info of `dl2spl` and `spl2srv` of your pre-deployed kafka cluster should be configured when you install the chart,

docs/en/dgs/tutorial.md

+27-75
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ This document is an e2e tutorial of offline training and online inference for a
66
- Tensorflow model serving.
77

88
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.
1313
5. Deploy the online dynamic graph service and ingest the streaming data.
1414
6. Start Java Client, sample and predict.
1515

16+
The first 3 parts need to use the training framework GraphLearn-Training, a detailed description refs:[GraphLearn-Training](../gl/intro.md).
1617

1718
## 1. Prepare data
1819

@@ -33,81 +34,53 @@ The generated data are stored in `/tmp/u2i_gen/training` and `/tmp/u2i_gen/strea
3334

3435
## 2. Train model offline
3536

36-
FIXME(@Seventeen17): refactor this section
3737
```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
4040
```
4141

4242
Ref to [GraphLearn-Training](../gl/intro.md) for more details.
4343

4444

4545
## 3. Export TF SavedModel
4646

47-
FIXME(@Seventeen17): refactor this section
4847

4948
First, export model as tf SavedModel, we need to filter some of the placeholders as model serving inputs based on the
5049
computational graph, you can view the computational graph with the help of Tensorboard to determine the inputs for the
5150
serving subgraph.
5251

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.
5554

5655
```shell
5756
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
5958
```
6059

6160
Check inputs and output of saved model.
6261
```shell
63-
saved_model_cli show --dir ego_sage_sup_model/1/ --all
62+
saved_model_cli show --dir ego_bipartite_sage/1/ --all
6463
```
6564

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-
9365
## 4. Deploy TF Model
94-
FIXME(@Seventeen17): refactor this section
9566

9667
Install tensorflow-model-server.
68+
9769
```shell
9870
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 && \
9971
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -
10072
apt-get update && apt-get install tensorflow-model-server
10173
```
74+
10275
Start tensorflow-model-server and deploy model
76+
10377
```shell
10478
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 \
10781
>server.log 2>&1
10882
```
10983

110-
11184
## 5. Deploy Dynamic Graph Service.
11285

11386
### 5.1 Deploy kafka service
@@ -191,39 +164,18 @@ cd dynamic_graph_service/dataloader
191164
192165

193166
## 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.
196169

197170
```
198-
cd dgs/gsl_client
199-
mvn -Dtest=PredictClientTest test
200-
```
171+
cd dynamic_graph_service/gsl_client
172+
mvn clean compile assembly:single
201173
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
229175
```
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`

docs/images/dgs_arch.png

3.7 KB
Loading

docs/zh_CN/index.rst docs/index_en.rst

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ Welcome to GraphLearn's documentation!
1010
:maxdepth: 2
1111
:caption: Introduction
1212

13-
intro
13+
en/intro
1414

1515
.. toctree::
1616
:maxdepth: 3
1717
:caption: GraphLearn-Training
1818

19-
gl/intro
20-
gl/install
21-
gl/quick_start
22-
gl/graph/index
23-
gl/algo/index
24-
gl/developer/index
19+
en/gl/intro
20+
en/gl/install
21+
en/gl/quick_start
22+
en/gl/graph/index
23+
en/gl/algo/index
24+
en/gl/developer/index
2525

2626

2727
.. toctree::
2828
:maxdepth: 2
2929
:caption: Dynamic-Graph-Service
3030

31-
dgs/intro
32-
dgs/deploy
33-
dgs/dataloader
34-
dgs/tutorial
35-
dgs/developer
31+
en/dgs/intro
32+
en/dgs/deploy
33+
en/dgs/dataloader
34+
en/dgs/tutorial
35+
en/dgs/developer
3636
apis/index
3737

3838

docs/en/index.rst docs/index_zh_CN.rst

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ Welcome to GraphLearn's documentation!
1010
:maxdepth: 2
1111
:caption: Introduction
1212

13-
intro
13+
zh_CN/intro
1414

1515
.. toctree::
1616
:maxdepth: 3
1717
:caption: GraphLearn-Training
1818

19-
gl/intro
20-
gl/install
21-
gl/quick_start
22-
gl/graph/index
23-
gl/algo/index
24-
gl/developer/index
19+
zh_CN/gl/intro
20+
zh_CN/gl/install
21+
zh_CN/gl/quick_start
22+
zh_CN/gl/graph/index
23+
zh_CN/gl/algo/index
24+
zh_CN/gl/developer/index
2525

2626

2727
.. toctree::
2828
:maxdepth: 2
2929
:caption: Dynamic-Graph-Service
3030

31-
dgs/intro
32-
dgs/deploy
33-
dgs/dataloader
34-
dgs/tutorial
35-
dgs/developer
31+
zh_CN/dgs/intro
32+
zh_CN/dgs/deploy
33+
zh_CN/dgs/dataloader
34+
zh_CN/dgs/tutorial
35+
zh_CN/dgs/developer
3636
apis/index
3737

3838

docs/en/make.bat docs/make.bat

File renamed without changes.

docs/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sphinx
22
sphinx_rtd_theme
33
recommonmark
4-
markdown==3.3.7
4+
markdown
55
sphinx-markdown-tables
66
myst-parser

docs/zh_CN/Makefile

-20
This file was deleted.

docs/zh_CN/apis/index.rst

-2
This file was deleted.

0 commit comments

Comments
 (0)