Skip to content

Commit 2efac83

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into merge
2 parents 98b7c67 + bba8573 commit 2efac83

File tree

141 files changed

+4141
-696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+4141
-696
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- id: clang-format-with-version-check
2323
name: clang-format
2424
description: Format files with ClangFormat.
25-
entry: ./.clang_format.hook -i
25+
entry: bash ./.clang_format.hook -i
2626
language: system
2727
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$
2828
- repo: https://github.com/PaddlePaddle/pre-commit-golang

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF)
5555
option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF)
5656
option(GLIDE_INSTALL "Download and install go dependencies " ON)
5757
option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF)
58+
option(USE_EIGEN_FOR_BLAS "Use matrix multiplication in Eigen" OFF)
5859

5960
# CMAKE_BUILD_TYPE
6061
if(NOT CMAKE_BUILD_TYPE)
@@ -137,9 +138,9 @@ set(EXTERNAL_LIBS
137138
)
138139

139140
if(WITH_GPU)
140-
list(APPEND EXTERNAL_LIB ${CUDA_LIBRARIES} ${CUDA_rt_LIBRARY})
141+
list(APPEND EXTERNAL_LIBS ${CUDA_LIBRARIES} ${CUDA_rt_LIBRARY})
141142
if(NOT WITH_DSO)
142-
list(APPEND EXTERNAL_LIB ${CUDNN_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY})
143+
list(APPEND EXTERNAL_LIBS ${CUDNN_LIBRARY} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY})
143144
endif(NOT WITH_DSO)
144145
endif(WITH_GPU)
145146

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ RUN /bin/bash -c 'if [[ -n ${UBUNTU_MIRROR} ]]; then sed -i 's#http://archive.ub
1010
ARG WITH_GPU
1111
ARG WITH_AVX
1212
ARG WITH_DOC
13-
ARG WITH_STYLE_CHECK
1413

1514
ENV WOBOQ OFF
16-
ENV WITH_GPU=${WITH_GPU:-OFF}
15+
ENV WITH_GPU=${WITH_GPU:-ON}
1716
ENV WITH_AVX=${WITH_AVX:-ON}
1817
ENV WITH_DOC=${WITH_DOC:-OFF}
19-
ENV WITH_STYLE_CHECK=${WITH_STYLE_CHECK:-OFF}
2018

2119
ENV HOME /root
2220
# Add bash enhancements

cmake/configure.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if(NOT WITH_TIMER)
2828
add_definitions(-DPADDLE_DISABLE_TIMER)
2929
endif(NOT WITH_TIMER)
3030

31+
if(USE_EIGEN_FOR_BLAS)
32+
add_definitions(-DPADDLE_USE_EIGEN_FOR_BLAS)
33+
endif(USE_EIGEN_FOR_BLAS)
34+
3135
if(NOT WITH_PROFILER)
3236
add_definitions(-DPADDLE_DISABLE_PROFILER)
3337
endif(NOT WITH_PROFILER)

cmake/cudnn.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if(NOT WITH_GPU)
22
return()
33
endif()
44

5-
set(CUDNN_ROOT "" CACHE PATH "CUDNN ROOT")
5+
set(CUDNN_ROOT "/usr" CACHE PATH "CUDNN ROOT")
66
find_path(CUDNN_INCLUDE_DIR cudnn.h
77
PATHS ${CUDNN_ROOT} ${CUDNN_ROOT}/include
88
$ENV{CUDNN_ROOT} $ENV{CUDNN_ROOT}/include ${CUDA_TOOLKIT_INCLUDE}

doc/api/v2/config/layer.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ seq_concat
257257
.. autoclass:: paddle.v2.layer.seq_concat
258258
:noindex:
259259

260+
seq_slice
261+
---------
262+
.. autoclass:: paddle.v2.layer.seq_slice
263+
:noindex:
264+
260265
kmax_sequence_score
261266
-------------------
262267
.. autoclass:: paddle.v2.layer.kmax_sequence_score
@@ -362,6 +367,11 @@ trans
362367
.. autoclass:: paddle.v2.layer.trans
363368
:noindex:
364369

370+
scale_shift
371+
-----------
372+
.. autoclass:: paddle.v2.layer.scale_shift
373+
:noindex:
374+
365375
Sampling Layers
366376
===============
367377

doc/design/cluster_train/README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ The life cycle of a single task is illustrated below:
5454
<img src="src/paddle-task-states.png"/>
5555

5656
1. When a new pass of training starts, all tasks will be placed in the todo queue.
57-
1. The master server will dispatch few tasks to each trainer at a time, puts them in the pending queue and waits for completion.
58-
1. The trainer will work on its tasks and tell the master server once a task is completed. The master server will dispatch a new task to that trainer.
59-
1. If a task timeout. the master server will move it back to the todo queue. The timeout count will increase by one. If the timeout count is above a threshold, the task is likely to cause a trainer to crash, so it will be discarded.
57+
1. Upon trainer requests for new task, the master server will dispatch a task from todo queue to it, put the task in the pending queue and wait for completion.
58+
1. The trainer will work on its task and tell the master server once the task is completed and ask for new task. The master server will dispatch a new task to that trainer.
59+
1. If a task fails for any reason in trainer, or takes longer than a specific period of time, the master server will move the task back to the todo queue. The timeout count for that task will increase by one. If the timeout count is above a threshold, the task is likely to cause a trainer to crash, then it will be discarded.
6060
1. The master server will move completed task to the done queue. When the todo queue is empty, the master server will start a new pass by moving all tasks in the done queue to todo queue and reset the timeout counter of all tasks to zero.
6161

6262
### Trainer Process
6363

6464
The trainer process will:
6565

66-
- Receive tasks from the master.
67-
- Work on the tasks: calculate and upload gradient to parameter servers, and update local model by downloading new parameters from parameter servers.
66+
- Request tasks from the master.
67+
- Work on the tasks
68+
- Upload gradient to parameter servers, and update local model by downloading new parameters from parameter servers.
6869

6970
### Parameter Server Process
7071

@@ -119,22 +120,20 @@ When the master is started by the Kubernetes, it executes the following steps at
119120

120121
1. Grabs a unique *master* lock in etcd, which prevents concurrent master instantiations.
121122
1. Recovers the task queues from etcd if they already exist, otherwise, the master will create them.
122-
1. Watches the trainer prefix keys `/trainer/` on etcd to find the live trainers.
123-
1. Starts dispatching the tasks to the trainers, and updates task queue using an etcd transaction to ensure lock is held during the update.
123+
1. Write its ip address to */master/addr* so that trainers can discover it.
124+
1. Listens to trainers' request of task, dispatch one upon request, and updates task queue using an etcd transaction to ensure lock is held during the update.
124125

125126
When the master server process is dead for any reason, Kubernetes will restart it. It will be online again with all states recovered from etcd in few minutes.
126127

127128
### Trainer Process
128129

129130
When the trainer is started by the Kubernetes, it executes the following steps at startup:
130131

131-
1. Watches the available parameter server prefix keys `/ps/` on etcd and waits until the count of parameter servers reaches the desired count.
132-
1. Generates a unique ID, and sets key `/trainer/<unique ID>` with its contact address as value. The key will be deleted when the lease expires, so the master will be aware of the trainer being online and offline.
133-
1. Waits for tasks from the master to start training.
132+
1. Watches the available parameter server prefix keys `/ps/` on etcd and waits until the count of parameter servers reaches the desired count */ps_desired*.
133+
1. Finds and watches */master/addr* to get master's address.
134+
1. Requests for tasks from the master to start training.
134135

135-
If trainer's etcd lease expires, it will try set key `/trainer/<unique ID>` again so that the master server can discover the trainer again.
136-
137-
When a trainer fails, Kuberentes would try to restart it. The recovered trainer would fetch tasks from the TODO queue and go on training.
136+
When a trainer fails, Kuberentes would try to restart it. The recovered trainer would fetch tasks from master and go on training.
138137

139138
### Parameter Server Process
140139

509 Bytes
Binary file not shown.
-5.78 KB
Loading

doc/howto/dev/build_cn.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# 编译PaddlePaddle和运行单元测试
2+
3+
## 需要的软硬件
4+
5+
为了开发PaddlePaddle,我们需要
6+
7+
1. 一台电脑,可以装的是 Linux, BSD, Windows 或者 MacOS 操作系统,以及
8+
1. Docker。
9+
10+
不需要依赖其他任何软件了。即便是 Python 和 GCC 都不需要,因为我们会把所有编译工具都安装进一个 Docker image 里。
11+
12+
## 总体流程
13+
14+
1. 获取源码
15+
16+
```bash
17+
git clone https://github.com/paddlepaddle/paddle
18+
```
19+
20+
2. 安装开发工具到 Docker image 里
21+
22+
```bash
23+
cd paddle; docker build -t paddle:dev .
24+
```
25+
26+
请注意这个命令结尾处的 `.`;它表示 `docker build` 应该读取当前目录下的 [`Dockerfile`文件](https://github.com/PaddlePaddle/Paddle/blob/develop/Dockerfile),按照其内容创建一个名为 `paddle:dev` 的 Docker image,并且把各种开发工具安装进去。
27+
28+
3. 编译
29+
30+
以下命令启动一个 Docker container 来执行 `paddle:dev` 这个 Docker image,同时把当前目录(源码树根目录)映射为 container 里的 `/paddle` 目录,并且运行 `Dockerfile` 描述的默认入口程序 [`build.sh`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build.sh)。这个脚本调用 `cmake``make` 来编译 `/paddle` 里的源码,结果输出到 `/paddle/build`,也就是本地的源码树根目录里的 `build` 子目录。
31+
32+
```bash
33+
docker run --rm -v $PWD:/paddle paddle:dev
34+
```
35+
36+
上述命令编译出一个 CUDA-enabled 版本。如果我们只需要编译一个只支持 CPU 的版本,可以用
37+
38+
```bash
39+
docker run --rm -e WITH_GPU=OFF -v $PWD:/paddle paddle:dev
40+
```
41+
42+
4. 运行单元测试
43+
44+
用本机的第一个 GPU 来运行包括 GPU 单元测试在内的所有单元测试:
45+
46+
```bash
47+
NV_GPU=0 nvidia-docker run --rm -v $PWD:/paddle paddle:dev bash -c "cd /paddle/build; ctest"
48+
```
49+
50+
如果编译的时候我们用了 `WITH_GPU=OFF` 选项,那么编译过程只会产生 CPU-based 单元测试,那么我们也就不需要 nvidia-docker 来运行单元测试了。我们只需要:
51+
52+
```bash
53+
docker run --rm -v $PWD:/paddle paddle:dev bash -c "cd /paddle/build; ctest"
54+
```
55+
56+
有时候我们只想运行一个特定的单元测试,比如 `memory_test`,我们可以
57+
58+
```bash
59+
nvidia-docker run --rm -v $PWD:/paddle paddle:dev bash -c "cd /paddle/build; ctest -V -R memory_test"
60+
```
61+
62+
5. 清理
63+
64+
有时候我们会希望清理掉已经下载的第三方依赖以及已经编译的二进制文件。此时只需要:
65+
66+
```bash
67+
rm -rf build
68+
```
69+
70+
## 为什么要 Docker 呀?
71+
72+
- 什么是 Docker?
73+
74+
如果您没有听说 Docker,可以把它想象为一个类似 virtualenv 的系统,但是虚拟的不仅仅是 Python 的运行环境。
75+
76+
- Docker 还是虚拟机?
77+
78+
有人用虚拟机来类比 Docker。需要强调的是:Docker 不会虚拟任何硬件,Docker container 里运行的编译工具实际上都是在本机的 CPU 和操作系统上直接运行的,性能和把编译工具安装在本机运行一样。
79+
80+
- 为什么用 Docker?
81+
82+
把工具和配置都安装在一个 Docker image 里可以标准化编译环境。这样如果遇到问题,其他人可以复现问题以便帮助。
83+
84+
另外,对于习惯使用Windows和MacOS的开发者来说,使用Docker就不用配置交叉编译环境了。
85+
86+
- 我可以选择不用Docker吗?
87+
88+
当然可以。大家可以用把开发工具安装进入 Docker image 一样的方式,把这些工具安装到本机。这篇文档介绍基于 Docker 的开发流程,是因为这个流程比其他方法都更简便。
89+
90+
- 学习 Docker 有多难?
91+
92+
理解 Docker 并不难,大概花十分钟看一下[这篇文章](https://zhuanlan.zhihu.com/p/19902938)。这可以帮您省掉花一小时安装和配置各种开发工具,以及切换机器时需要新安装的辛苦。别忘了 PaddlePaddle 更新可能导致需要新的开发工具。更别提简化问题复现带来的好处了。
93+
94+
- 我可以用 IDE 吗?
95+
96+
当然可以,因为源码就在本机上。IDE 默认调用 make 之类的程序来编译源码,我们只需要配置 IDE 来调用 Docker 命令编译源码即可。
97+
98+
很多 PaddlePaddle 开发者使用 Emacs。他们在自己的 `~/.emacs` 配置文件里加两行
99+
100+
```emacs
101+
(global-set-key "\C-cc" 'compile)
102+
(setq compile-command
103+
"docker run --rm -it -v $(git rev-parse --show-toplevel):/paddle paddle:dev")
104+
```
105+
106+
就可以按 `Ctrl-C``c` 键来启动编译了。
107+
108+
- 可以并行编译吗?
109+
110+
是的。我们的 Docker image 运行一个 [Bash 脚本](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/docker/build.sh)。这个脚本调用 `make -j$(nproc)` 来启动和 CPU 核一样多的进程来并行编译。
111+
112+
## 可能碰到的问题
113+
114+
- Docker 需要 sudo
115+
116+
如果用自己的电脑开发,自然也就有管理员权限(sudo)了。如果用公用的电脑开发,需要请管理员安装和配置好 Docker。此外,PaddlePaddle 项目在努力开始支持其他不需要 sudo 的集装箱技术,比如 rkt。
117+
118+
- 在 Windows/MacOS 上编译很慢
119+
120+
Docker 在 Windows 和 MacOS 都可以运行。不过实际上是运行在一个 Linux 虚拟机上。可能需要注意给这个虚拟机多分配一些 CPU 和内存,以保证编译高效。具体做法请参考[这个issue](https://github.com/PaddlePaddle/Paddle/issues/627)
121+
122+
- 磁盘不够
123+
124+
本文中的例子里,`docker run` 命令里都用了 `--rm` 参数,这样保证运行结束之后的 containers 不会保留在磁盘上。可以用 `docker ps -a` 命令看到停止后但是没有删除的 containers。`docker build` 命令有时候会产生一些中间结果,是没有名字的 images,也会占用磁盘。可以参考[这篇文章](https://zaiste.net/posts/removing_docker_containers/)来清理这些内容。

0 commit comments

Comments
 (0)