parameter_server.md 4.5 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
different purposes.

## Background

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

17 18 19 20 21
It would be great if we can write code once and use them on both: the
trainer and the parameter server, since this reduces code duplication and
improves extensibility. Given that after the current refactoring, we are
representing everything as a computation graph on the
trainer. Representing everything as a computation graph on the parameter
22 23 24 25
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
1. OP placement: the OPs will be placed on different nodes according
33
   to a heuristic that minimizes the estimated total computation
34
   time. Currently we will use a simple heuristic that puts parameter
35
   variable on parameter server workers and everything else on trainer
36 37 38 39
   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

_青葱's avatar
_青葱 已提交
44
<img src="https://github.com/PaddlePaddle/Paddle/tree/develop/doc/fluid/images/local-graph.png" width="300"/>
45 46 47

After converting:

_青葱's avatar
_青葱 已提交
48
<img src="https://github.com/PaddlePaddle/Paddle/tree/develop/doc/fluid/images/dist-graph.png" width="700"/>
49

50
1. The parameter variable W and its optimizer program are placed on the parameter server.
T
typhoonzero 已提交
51
1. Operators are added to the program.
52 53 54 55
   - *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).
56
   - *Enqueue* enqueues the input variable, it can block until space
57 58
     become available in the queue.
   - *Dequeue* outputs configurable numbers of tensors from the
59
     queue. It will block until the queue has the required number of
60 61
     tensors.

62 63 64 65 66 67 68 69 70 71
### Sparse Update

For embedding layers, the gradient may have many rows containing only 0 when training,
if the gradient uses a dense tensor to do parameter optimization,
it could spend unnecessary memory, slow down the calculations and waste
the bandwidth while doing distributed training.
In Fluid, we introduce [SelectedRows](../selected_rows.md) to represent a list of rows containing
non-zero gradient data. So when we do parameter optimization both locally and remotely,
we only need to send those non-zero rows to the optimizer operators:

_青葱's avatar
_青葱 已提交
72
<img src="https://github.com/PaddlePaddle/Paddle/tree/develop/doc/fluid/images/sparse_update.png" width="700" />
73 74 75

### Benefits

76
- Model parallelism becomes easier to implement: it is an extension to
T
typhoonzero 已提交
77 78
  the trainer - parameter server approach. We can have several "Transpilers"
  to achieve different goals.
79
- User-defined optimizer is easier to add - user can now express it as
T
typhoonzero 已提交
80
  a sub-program.
81
- No more duplication logic inside the trainer and the parameter
H
Helin Wang 已提交
82
  server mentioned in the background section.
83 84 85

### Challenges

86 87
- It is important to balance the parameter shards on multiple
  parameter servers. If a single parameter is very big (for example: some
88 89 90 91
  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).
92 93
- In the "Async SGD" figure, the "W" variable on the parameter server
  could be read and written concurrently. See
T
typhoonzero 已提交
94
  [here](https://github.com/PaddlePaddle/Paddle/pull/6394) for more
95
  details about concurrent program in Fluid.
96 97 98

### Discussion

H
polish  
Helin Wang 已提交
99
- Can the Enqueue OP be implemented under our current tensor design
100 101
  (put the input tensor into the queue tensor)?
- *Dequeue* OP will have variable numbers of output (depending on the
102 103 104
  `min_count` attribute), does our current design support it? (similar
  question for the *Add* OP)

105
### References
106

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