-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paddle cluster design #1696
Merged
Merged
Paddle cluster design #1696
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dbb2047
cluster design
29b00fa
cluster design and thoughts
3023c65
update
bb5fb0d
update
4ecce7d
update design doc
0d0c761
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
typhoonzero 39d6d1c
update cluster design
typhoonzero 1fa58b0
update design
typhoonzero 4acf829
add picture
typhoonzero cb6cc5a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
typhoonzero 8bd6b74
update reader design
b360dec
update doc
typhoonzero a9b33f3
update
typhoonzero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## 模型参数检查点(Checkpointing) | ||
模型数据检查点的实现,可以有效的避免parameter server的单点或多点同时故障。模型参数检查点通过定期向磁盘上保存一份存储在parameter server内存中的模型数据的完整镜像,来保证训练过程可以从中间状态重新启动。在一个不可中断并缺少备份的训练任务中,可以通过阶段性的保存每个parameter server的数据快照(snapshot)到 ***分布式存储服务*** 达到容灾的目的,比如每隔10分钟最新的快照,并删除更早的快照。在出现单点故障时,只需要恢复这台节点,或者将这台节点迁移到另一个节点并启动即可恢复训练任务。 | ||
|
||
<img src="src/checkpointing.png" width="500"/> | ||
|
||
### 快照保存的设计如下: | ||
|
||
说明: | ||
|
||
* parameter server在集群中启动后,自动挂载分布式存储目录,并把快照保存到这个目录下。 | ||
* ***注:每个parameter server的检查点各自独立保存,暂时不考虑多个parameter server同步的保存一个特定时间点的全局检查点,因为这样做也没法保证消除随机性。*** | ||
|
||
检查点保存程序流程: | ||
|
||
1. 如果满足条件"每隔10分钟"时,parameter server会获取parameters内存的`read_lock`,启动一个新的线程开始保存检查点。如果已经正在执行保存检查点的线程,则忽略。由于对parameters的更新需要获取parameters内存的`write_lock`,所以在写入快照的过程中,parameter server会暂停参数更新并等待。 | ||
2. parameter server生成一个UUID,向指定的目录中一个新的文件(文件名为此UUID)写入快照数据。在快照写入完成后,计算这个文件的MD5 sum。然后在etcd的`/checkpoints/[pserver_id]`中写入json内容:`{"uuid": [UUID], "md5", "MD5 sum", "timestamp": xxxx}`。 | ||
3. 删除磁盘目录中不是当前uuid的快照文件。 | ||
4. 释放对paramters内存的锁定,停止保存检查点的线程。 | ||
|
||
这里需要用户额外注意,在您的实际环境中,训练任务的运行可能会占满trainer和parameter server之间的网络带宽,如果parameter server此时还需要通过网络访问分布式存储以保存快照,可能会造成网络拥塞,而出现阶段性的运行停滞。 | ||
|
||
### 从快照恢复 | ||
|
||
在parameter server第一次启动或任意时间parameter server故障后被Kubernetes重新启动,则需要回滚到上一个检查点: | ||
|
||
1. 从etcd中读取节点:`/checkpoints/[pserver_id]`获取最新的检查点的文件uuid | ||
1. 从磁盘文件中加载uuid文件名的检查点快照文件,并加载其中的参数 | ||
1. 如果上面两步出现错误,则使用启动参数定义的初始化方法初始化参数 | ||
1. 开始提供服务 | ||
|
||
## TODO List | ||
### 推测执行/加速执行(TODO) | ||
在异构集群中,如果存在某些trainer执行速度过慢会影响整体集群的速度(如图中Trainer 1),此时master将负责启动一个新的Trainer(Accelerate Trainer 2),使用同样的训练数据block。哪个trainer先完成block的训练,则把另一个慢速的kill掉。 | ||
|
||
### 动态扩容/缩容 | ||
目前只考虑动态扩容trainer数量,可以减小系统复杂性。 | ||
|
||
## 术语 | ||
* model: 指深度学习训练之后得到的所有参数,使用这个神经网络可以完成对新数据的预测 | ||
* parameters: 神经网络中的参数,包括权重w和偏置b。一个神经网络的模型由大量的参数组成 | ||
* shard: 分片,通常指将一个整体拆分成多份的其中的一份。 | ||
* model shard: 将一个神经网络参数拆分成多份,每个shard分别存储在其中一台parameter server之上 | ||
* parameter block: 多个parameter block构成一个model shard | ||
* 单点故障: 任意时刻只可能同时有一台服务器故障。由于集群中同时存在两台机器故障的概率极低((平均故障率*平均故障修复时间)^2)只对特殊在线系统考虑两台以上同时故障的容灾。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
## 训练数据的存储和分发 | ||
|
||
### 流程介绍 | ||
生产环境中的训练数据集通常体积很大,并被存储在诸如Hadoop HDFS,Ceph,AWS S3之类的分布式存储之上。这些分布式存储服务通常会把数据切割成多个分片分布式的存储在多个节点之上。这样就可以在云端执行多种数据类计算任务,包括: | ||
|
||
* 数据预处理任务 | ||
* Paddle训练任务 | ||
* 在线模型预测服务 | ||
|
||
<img src="src/paddle-cloud-in-data-center.png" width="500"/> | ||
|
||
在上图中显示了在一个实际生产环境中的应用(人脸识别)的数据流图。生产环境的日志数据会通过实时流的方式(Kafka)和离线数据的方式(HDFS)存储,并在集群中运行多个分布式数据处理任务,比如流式数据处理(online data process),离线批处理(offline data process)完成数据的预处理,提供给paddle作为训练数据。用于也可以上传labeled data到分布式存储补充训练数据。在paddle之上运行的深度学习训练输出的模型会提供给在线人脸识别的应用使用。 | ||
|
||
### 训练数据的存储 | ||
|
||
选择GlusterFS作为训练数据的存储服务(后续的实现考虑HDFS)。 | ||
|
||
在Kubernetes上运行的不同的计算框架,可以通过Volume或PersistentVolume挂载存储空间到每个容器中。 | ||
|
||
在GlusterFS存储系统中的公开目录,需要保存一些预置的公开数据集(比如MNIST, BOW, imagenet数据集等),并且可以被提交的job直接使用。 | ||
|
||
### 上传训练文件 | ||
|
||
使用下面命令,可以把本地的训练数据上传到存储集群中,并指定上传数据的`dataset-name`: | ||
|
||
``` | ||
paddle upload train_data.list "dataset-name" | ||
``` | ||
|
||
其中`.list`文件描述了训练数据的文件和对应的label,对于图像类数据,`.list文件`样例如下,每一行包含了图片文件的路径和其label(用tab分隔开): | ||
|
||
``` | ||
./data/image1.jpg 1 | ||
./data/image2.jpg 5 | ||
./data/image3.jpg 2 | ||
./data/image4.jpg 5 | ||
./data/image5.jpg 1 | ||
./data/image6.jpg 8 | ||
... | ||
``` | ||
|
||
对于文本类训练数据样例如下(机器翻译),一行中包含源语言,目标语言的文本(label): | ||
|
||
``` | ||
L' inflation , en Europe , a dérapé sur l' alimentation Food : Where European inflation slipped up | ||
L' inflation accélérée , mesurée dans la zone euro , est due principalement à l' augmentation rapide des prix de l' alimentation . The skyward zoom in food prices is the dominant force behind the speed up in eurozone inflation . | ||
... | ||
``` | ||
|
||
### 使用reader | ||
|
||
用户在使用v2 API编写训练任务时,可以使用paddle内置的reader完成对GlusterFS存储中的训练数据的读取,返回文件中的各列,然后在调用`trainer.train()`时传入,完成训练数据的读取: | ||
|
||
```python | ||
reader = paddle.dist.reader("dataset-name") | ||
trainer.train(reader, ...) | ||
batch_reader = paddle.batch(paddle.dataset.mnist.train(), 128) | ||
trainer.train(batch_reader, ...) | ||
``` | ||
|
||
trainer.train内部会获取reader的内容: | ||
|
||
``` | ||
def paddle.train(batch_reader): | ||
r = batch_reader() # create a iterator for one pass of data | ||
for batch in r: | ||
# train | ||
``` | ||
|
||
这里面batch是含有128个data instance的mini-batch。每一个data instance会是一个tuple,tuple元素的顺序与`.list`文件文件中每一列的顺序是一致的。每一个data instance会是(raw_image_file_binary_data, label)。其中raw_image_file_binary_data是对应图像文件的没有解码的原始二进制数据,用户需要自己解码。label是文本类型(比如:“1“,”2“),这里用户需要的其实是整形,用户需要自己转换成整形。 | ||
|
||
### 实现reader | ||
|
||
reader的实现需要考虑本地训练程序实现之后,可以不修改程序直接提交集群进行分布式训练。要达到这样的目标,需要实现下面的功能: | ||
|
||
paddle会封装一个在集群中使用的reader: `paddle.dist.reader()`。在集群训练时需要使用这个reader指定要使用的数据集开始训练。用户的训练程序需要按照如下方式初始化reader: | ||
|
||
```python | ||
if os.getenv("PADDLE_TRAIN_LOCAL"): | ||
reader = my_local_reader("dataset-name") | ||
else: | ||
reader = paddle.dist.reader("dataset-name") | ||
``` | ||
|
||
用户训练程序提交到集群之后,集群会自动设置`PADDLE_TRAIN_LOCAL`环境变量,reader会被配置成集群训练的版本。其中`paddle.dist.reader()`需要从master的队列中获得需要开始执行的训练task,并找到对应的训练数据文件,开始训练任务。如果用户的训练数据源来自于其他服务,比如从集群中的Kafka,zeromq队列读取,也可以根据实际情况实现集群中运行的reader程序。 | ||
|
||
## TODO | ||
|
||
### 支持将数据合并成内部的文件格式(key-value),方便sharding与顺序读取 | ||
### 支持用户自定义的数据预处理job |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果使用前面提到的
checkpoint.tmp
方法,这里可以改成:checkpoint
文件恢复模型。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
决定用PR里提出的方法,即使parameter server存到一半挂掉也没事。