From b2b166d626e64fda0e30569d734bb9034b72d7ae Mon Sep 17 00:00:00 2001 From: frankwhzhang Date: Sun, 29 Sep 2019 13:42:38 +0800 Subject: [PATCH] test readme --- docs/source/examples/md/gru4rec_examples.md | 64 ++++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/docs/source/examples/md/gru4rec_examples.md b/docs/source/examples/md/gru4rec_examples.md index a5b8b69..b4c80ca 100644 --- a/docs/source/examples/md/gru4rec_examples.md +++ b/docs/source/examples/md/gru4rec_examples.md @@ -1,9 +1,67 @@ -# Gru4Rec for session-based recommendation +# Train gru4rec model with FedAvg Strategy +This doc introduce how to use PaddleFL to train model with Fl Strategy. -[Graph Convolutional Network \(GCN\)](https://arxiv.org/abs/1609.02907) is a powerful neural network designed for machine learning on graphs. Based on PGL, we reproduce GCN algorithms and reach the same level of indicators as the paper in citation network benchmarks. +### Dependencies +- paddlepaddle>=1.6 + +### How to install PaddleFL +please use the python which has installed paddlepaddle. +```sh +python setup.py install +``` + +### Model +[Gru4rec](https://arxiv.org/abs/1511.06939) is the classical session-based recommendation model. The details implement by paddlepaddle is [here](https://github.com/PaddlePaddle/models/tree/develop/PaddleRec/gru4rec). + + +### Datasets +We use [Rsc15](https://2015.recsyschallenge.com) dataset as our data. -### Simple example to build GCN +```sh +#download data +cd example/gru4rec_demo +sh download.sh +``` + +### How to work in PaddleFL +PaddleFL has two period , CompileTime and RunTime. In CompileTime, define a federated learning task by fl_master. In RunTime, train a federated learning job by fl_server and fl_trainer . + +### How to work in CompileTime +In this example, we implement it in fl_master.py +```sh +# please run fl_master to generate fl_job +python fl_master.py +``` +In fl_master.py, we first define FL-Strategy, User-Defined-Program and Distributed-Config. Then FL-Job-Generator generate FL-Job for federated server and worker. +```python +# define model +model = Model() +model.gru4rec_network() + +# define JobGenerator and set model config +# feed_name and target_name are config for save model. +job_generator = JobGenerator() +optimizer = fluid.optimizer.SGD(learning_rate=2.0) +job_generator.set_optimizer(optimizer) +job_generator.set_losses([model.loss]) +job_generator.set_startup_program(model.startup_program) +job_generator.set_infer_feed_and_target_names( + [x.name for x in model.inputs], [model.loss.name, model.recall.name]) + +# define FL-Strategy , we now support two flstrategy, fed_avg and dpsgd. Inner_step means fl_trainer locally train inner_step mini-batch. +build_strategy = FLStrategyFactory() +build_strategy.fed_avg = True +build_strategy.inner_step = 1 +strategy = build_strategy.create_fl_strategy() + +# define Distributed-Config and generate fl_job +endpoints = ["127.0.0.1:8181"] +output = "fl_job_config" +job_generator.generate_fl_job( + strategy, server_endpoints=endpoints, worker_num=2, output=output) + +``` To build a gcn layer, one can use our pre-defined ```pgl.layers.gcn``` or just write a gcn layer with message passing interface. ```python -- GitLab