README.md 4.68 KB
Newer Older
1
2
## Distributed training

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
This is an example of training GraphSage in a distributed fashion. To train GraphSage, it has five steps:

### Step 0: set IP configuration file.

User need to set their own IP configuration file before training. For example, if we have four machines in current cluster, the IP configuration
could like this:

```bash
172.31.19.1
172.31.23.205
172.31.29.175
172.31.16.98
```

Users need to make sure that the master node (node-0) has right permission to ssh to all the other nodes.
18
19
20
21
22
23
24
25
26
27
28

### Step 1: partition the graph.

The example provides a script to partition some builtin graphs such as Reddit and OGB product graph.
If we want to train GraphSage on 4 machines, we need to partition the graph into 4 parts.

We need to load some function from the parent directory.
```bash
export PYTHONPATH=$PYTHONPATH:..
```

29
In this example, we partition the OGB product graph into 4 parts with Metis on node-0. The partitions are balanced with respect to
30
31
32
33
34
the number of nodes, the number of edges and the number of labelled nodes.
```bash
python3 partition_graph.py --dataset ogb-product --num_parts 4 --balance_train --balance_edges
```

35
### Step 2: copy the partitioned data and files to the cluster
36

37
38
39
40
41
42
43
44
45
DGL provides a script for copying partitioned data and files to the cluster. Before that, copy the training script to a local folder:

```bash
mkdir ~/dgl_code
cp ~/dgl/examples/pytorch/graphsage/experimental/train_dist.py ~/dgl_code
cp ~/dgl/examples/pytorch/graphsage/experimental/train_dist_unsupervised.py ~/dgl_code
```

The command below copies partition data, ip config file, as well as training scripts to the machines in the cluster. The configuration of the cluster is defined by `ip_config.txt`, The data is copied to `~/graphsage/ogb-product` on each of the remote machines. The training script is copied to `~/graphsage/dgl_code` on each of the remote machines. `--part_config` specifies the location of the partitioned data in the local machine (a user only needs to specify
46
the location of the partition configuration file).
47

48
```bash
49
python3 ~/dgl/tools/copy_files.py \
50
51
52
--ip_config ip_config.txt \
--workspace ~/graphsage \
--rel_data_path ogb-product \
53
54
--part_config data/ogb-product.json \
--script_folder ~/dgl_code
55
```
56

57
After runing this command, user can find a folder called ``graphsage`` on each machine. The folder contains ``ip_config.txt``, ``dgl_code``, and ``ogb-product`` inside.
58
59

### Step 3: Launch distributed jobs
60

61
62
DGL provides a script to launch the training job in the cluster. `part_config` and `ip_config`
specify relative paths to the path of the workspace.
63
64

```bash
65
python3 ~/dgl/tools/launch.py \
66
--workspace ~/graphsage/ \
67
68
--num_trainers 1 \
--num_samplers 4 \
69
--num_servers 1 \
70
--part_config ogb-product/ogb-product.json \
71
--ip_config ip_config.txt \
72
"python3 dgl_code/train_dist.py --graph_name ogb-product --ip_config ip_config.txt --num_servers 1 --num_epochs 30 --batch_size 1000 --num_workers 4"
73
```
74

75
76
77
78
To run unsupervised training:

```bash
python3 ~/dgl/tools/launch.py \
79
--workspace ~/graphsage/ \
80
--num_trainers 1 \
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--num_samplers 4 \
--num_servers 1 \
--part_config ogb-product/ogb-product.json \
--ip_config ip_config.txt \
"python3 dgl_code/train_dist_unsupervised.py --graph_name ogb-product --ip_config ip_config.txt --num_servers 1 --num_epochs 3 --batch_size 1000 --num_workers 4"
```

By default, this code will run on CPU. If you have GPU support, you can just add a `--num_gpus` argument in user command:

```bash
python3 ~/dgl/tools/launch.py \
--workspace ~/graphsage/ \
--num_trainers 4 \
--num_samplers 4 \
95
--num_servers 1 \
96
--part_config ogb-product/ogb-product.json \
97
--ip_config ip_config.txt \
98
"python3 dgl_code/train_dist.py --graph_name ogb-product --ip_config ip_config.txt --num_servers 1 --num_epochs 30 --batch_size 1000 --num_workers 4 --num_gpus 4"
99
100
```

101

102
103
104
105
106
107
108
109
110
111
112
113
114
## Distributed code runs in the standalone mode

The standalone mode is mainly used for development and testing. The procedure to run the code is much simpler.

### Step 1: graph construction.

When testing the standalone mode of the training script, we should construct a graph with one partition.
```bash
python3 partition_graph.py --dataset ogb-product --num_parts 1
```

### Step 2: run the training script

115
116
To run supervised training:

117
```bash
118
python3 train_dist.py --graph_name ogb-product --ip_config ip_config.txt --num_epochs 3 --batch_size 1000 --part_config data/ogb-product.json --standalone
119
120
```

121
122
123
To run unsupervised training:

```bash
124
python3 train_dist_unsupervised.py --graph_name ogb-product --ip_config ip_config.txt --num_epochs 3 --batch_size 1000 --part_config data/ogb-product.json --standalone
125
126
```

127
Note: please ensure that all environment variables shown above are unset if they were set for testing distributed training.