parameter_server.md 3.7 KB
Newer Older
T
typhoonzero 已提交
1
# Design Doc: Parameter Server
2 3 4

## Abstract

H
Helin Wang 已提交
5 6
We propose an approach to implement the parameter server. In this
approach, there is no fundamental difference between the trainer and
7
the parameter server: they both run subgraphs, but subgraphs of
8 9 10 11 12
different purposes.

## Background

The previous implementations of the parameter server does not run a
T
typhoonzero 已提交
13
fluid sub-program. Parameter initialization, optimizer computation, network
14 15 16 17 18
communication and checkpointing are implemented twice on both the
trainer and the parameter server.

It would be great if we can write code once and use them on both the
trainer and the parameter server: reduces code duplication and
H
Helin Wang 已提交
19
improves extensibility. Given that after the current refactor, we are
20 21 22 23 24 25
representing everything as a computing graph on the
trainer. Representing everything as a computing graph on the parameter
server becomes a natural extension.

## Design

T
typhoonzero 已提交
26
### Distributed Transpiler
27

T
typhoonzero 已提交
28 29
The *Distributed Transpiler* converts the user-defined fluid program
into sub-programs to be scheduled on different nodes with the following
30
steps:
31

32 33 34 35 36 37 38 39
1. OP placement: the OPs will be placed on different nodes according
   to heuristic that minimizes estimated total computation
   time. Currently we will use a simple heuristic that puts parameter
   varable on parameter server workers and everything else on trainer
   workers.
1. Add communication OPs to enable the communication between nodes.

We will need these OPs: *Send*, *Recv*, *Enqueue*, *Dequeue*.
40 41

Below is an example of converting the user defined graph to the
42
subgraphs for the trainer and the parameter server:
43

H
Helin Wang 已提交
44
<img src="src/local-graph.png" width="300"/>
45 46 47

After converting:

48
<img src="src/dist-graph.png" width="700"/>
49

T
typhoonzero 已提交
50 51
1. The parameter variable W and it's optimizer program are placed on the parameter server.
1. Operators are added to the program.
52 53 54 55 56 57 58 59 60 61
   - *Send* sends data to the connected *Recv* operator.  The
	 scheduler on the receive node will only schedule *Recv* operator
	 to run when the *Send* operator has ran (the *Send* OP will mark
	 the *Recv* OP runnable automatically).
   - *Enueue* enqueues the input variable, it can block until space
     become available in the queue.
   - *Dequeue* outputs configurable numbers of tensors from the
     queue. It will block until the queue have the required number of
     tensors.

62 63 64 65

### Benefits

- Model parallelism become easier to implement: it's an extension to
T
typhoonzero 已提交
66 67
  the trainer - parameter server approach. We can have several "Transpilers"
  to achieve different goals.
68
- User-defined optimizer is easier to add - user can now express it as
T
typhoonzero 已提交
69
  a sub-program.
70
- No more duplication logic inside the trainer and the parameter
H
Helin Wang 已提交
71
  server mentioned in the background section.
72 73 74 75 76 77 78 79 80

### Challenges

- It's important to balance the parameter shards of on multiple
  parameter server. If a single parameter is very big (some
  word-embedding, fully connected, softmax layer), we need to
  automatically partition the single parameter onto different
  parameter servers when possible (only element-wise optimizer depends
  on the parameter variable).
T
typhoonzero 已提交
81 82 83 84
- In the "Aync SGD" figure, the "W" variable on the parameter server
  could be read and wrote concurrently. See
  [here](https://github.com/PaddlePaddle/Paddle/pull/6394) for more
  details about concurrent program in fluid.
85 86 87

### Discussion

H
polish  
Helin Wang 已提交
88 89
- Can the Enqueue OP be implemented under our current tensor design
  (puts the input tensor into the queue tensor)?
90 91 92 93 94
- *Dequeue* OP will have variable numbers of output (depends on the
  `min_count` attribute), does our current design support it? (similar
  question for the *Add* OP)


H
polish  
Helin Wang 已提交
95 96
### References:
[1] [TensorFlow: Large-Scale Machine Learning on Heterogeneous Distributed Systems](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45166.pdf)