Skip to content

Commit daa5011

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into feature/polish_reshape_op
2 parents 5298790 + f605f64 commit daa5011

Some content is hidden

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

45 files changed

+1051
-332
lines changed

benchmark/fluid/mnist.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ def run_benchmark(model, args):
139139

140140
# inference program
141141
inference_program = fluid.default_main_program().clone()
142-
with fluid.program_guard(inference_program):
143-
inference_program = fluid.io.get_inference_program(
144-
target_vars=[batch_acc, batch_size_tensor])
145142

146143
# Optimization
147144
opt = fluid.optimizer.AdamOptimizer(
@@ -161,7 +158,7 @@ def run_benchmark(model, args):
161158
train_reader = paddle.batch(
162159
paddle.dataset.mnist.train(), batch_size=args.batch_size)
163160

164-
accuracy = fluid.average.WeightedAverage()
161+
accuracy = fluid.metrics.Accuracy()
165162
iters, num_samples, start_time = 0, 0, time.time()
166163
for pass_id in range(args.pass_num):
167164
accuracy.reset()
@@ -184,7 +181,7 @@ def run_benchmark(model, args):
184181
"label": y_data},
185182
fetch_list=[avg_cost, batch_acc, batch_size_tensor]
186183
) # The accuracy is the accumulation of batches, but not the current batch.
187-
accuracy.add(value=outs[1], weight=outs[2])
184+
accuracy.update(value=outs[1], weight=outs[2])
188185
iters += 1
189186
num_samples += len(y_data)
190187
loss = np.array(outs[0])

cmake/external/nccl.cmake

Lines changed: 0 additions & 67 deletions
This file was deleted.

doc/v2/dev/write_docs_cn.rst

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,55 @@ PaddlePaddle.org工具可以配合Docker使用,需要在系统里先安装好D
6565
不使用PaddlePaddle.org工具
6666
--------------------------
6767

68-
使用Docker构建PaddlePaddle的文档,需要在系统里先安装好Docker工具包。Docker安装请参考 `Docker的官网 <https://docs.docker.com/>`_ 。安装好Docker之后可以使用源码目录下的脚本构建文档,即
68+
使用Docker构建PaddlePaddle的文档,需要在系统里先安装好Docker工具包。Docker安装请参考 `Docker的官网 <https://docs.docker.com/>`_ 。该方法与 `从源码编译PaddlePaddle <http://paddlepaddle.org/docs/develop/documentation/zh/build_and_install/build_from_source_cn.html>`_ 相似,通过从源码中构建可用于编译PaddlePaddle文档的Docker镜像并运行,在进入Docker容器后使用源码中的脚本构建PaddlePaddle文档,具体步骤如下:
6969

70-
[TBD]
70+
.. code-block:: bash
71+
72+
git clone https://github.com/PaddlePaddle/Paddle.git
73+
cd Paddle
74+
75+
# 从源码中构建可用于编译PaddlePaddle文档的Docker镜像
76+
docker build -t paddle:dev .
77+
docker run -it -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=OFF" -e "WITH_DOC=ON" paddle:dev /bin/bash
78+
79+
# 进入Docker容器后使用build.sh脚本构建PaddlePaddle文档
80+
bash -x /paddle/paddle/scripts/docker/build.sh
81+
82+
注:上述命令把当前目录(源码根目录)映射为 container 里的 :code:`/paddle` 目录。
83+
84+
编译完成后,会产生 ``doc/v2`` 和 ``doc/fluid`` 两个目录,在这两个目录下分别都生成 ``cn/html/`` 、 ``en/html`` 、 ``api/en/html`` 共三个子目录,分别进入这些目录下,执行以下命令:
85+
86+
.. code-block:: bash
87+
88+
python -m SimpleHTTPServer 8088
89+
90+
在浏览器中输入 http://localhost:8088 就可以看到编译生成的 ``v2`` 和 ``fluid`` 两种版本的中/英文的文档页面和英文的API页面。
7191

7292
如果不想使用Docker,也可以使用以下命令直接构建PaddlePaddle文档,即
7393

7494
.. code-block:: bash
7595
76-
mkdir paddle
77-
cd paddle
7896
git clone https://github.com/PaddlePaddle/Paddle.git
97+
cd Paddle
7998
mkdir -p build
8099
cd build
81100
cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_GPU=OFF -DWITH_MKL=OFF -DWITH_DOC=ON
82101
83102
# 如果只需要构建使用文档,则执行以下命令
84-
make -j $processors gen_proto_py
85-
make -j $processors paddle_docs paddle_docs_cn
103+
make -j $processors paddle_docs
86104
87105
# 如果只需要构建API,则执行以下命令
88-
make -j $processors gen_proto_py framework_py_proto
89-
make -j $processors copy_paddle_pybind
90-
make -j $processors paddle_api_docs
106+
make -j $processors paddle_apis
91107
92108
其中$processors代表启动和CPU核一样多的进程来并行编译,可以根据本机的CPU核数设置相应的值。
93109

94-
编译完成后,进入 ``doc/v2`` 目录,如果选择构建文档则会在该目录下生成 ``cn/html/`` 、 ``en/html`` 两个子目录,选择构建API则会生成 ``api/en/html`` 目录,分别进入这些目录下,执行以下命令:
110+
编译完成后,同样会产生 ``doc/v2`` 和 ``doc/fluid`` 两个目录,如果选择构建文档则会在这两个目录下分别都生成 ``cn/html/`` 、 ``en/html`` 两个子目录,选择构建API则会在这两个目录下分别生成 ``api/en/html`` 目录,分别进入这些子目录下,执行以下命令:
95111

96112
.. code-block:: bash
97113
98114
python -m SimpleHTTPServer 8088
99115
100-
在浏览器中输入 http://localhost:8088 就可以看到编译生成的中/英文的文档页面和英文的API页面,下图为生成的英文文档首页示例。注意,示例中由于使用了sphinx的原始主题,所以页面的风格与官网并不一致,但这并不影响开发者进行调试。
116+
在浏览器中输入 http://localhost:8088 就可以看到编译生成的 ``v2`` 和 ``fluid`` 两种版本的中/英文的文档页面和英文的API页面。下图为生成的 ``v2`` 英文文档首页示例。注意,示例中由于使用了sphinx的原始主题,所以页面的风格与官网并不一致,但这并不影响开发者进行调试。
101117

102118
.. image:: src/doc_en.png
103119
:align: center

doc/v2/dev/write_docs_en.rst

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,56 @@ Please `click here <https://github.com/PaddlePaddle/PaddlePaddle.org/blob/develo
6868
Manually Building the Documentation
6969
-------------------------------------
7070

71-
Build PaddlePaddle's documentation with Docker,you need to install Docker first. Please refer to `Docker's official website <https://docs.docker.com/>`_ on how to install Docker. After Docker is installed, you could use the scripts in the source directory to build the documentation.
71+
Build PaddlePaddle's documentation with Docker,you need to install Docker first. Please refer to `Docker's official website <https://docs.docker.com/>`_ on how to install Docker. This method is quite similar to ` Build From Sources <http://paddlepaddle.org/docs/develop/documentation/en/build_and_install/build_from_source_en.html>`_ , by constructing, from source code, a docker image that can be used to build PaddlePaddle documentation. Enter the Docker container and use the script ``build.sh`` in the source directory to build the PaddlePaddle documentation. The specific steps are as follows:
7272

73-
[TBD]
73+
.. code-block:: bash
74+
75+
git clone https://github.com/PaddlePaddle/Paddle.git
76+
cd Paddle
77+
78+
# Construct a docker image from source code
79+
docker build -t paddle:dev .
80+
docker run -it -v $PWD:/paddle -e "WITH_GPU=OFF" -e "WITH_TESTING=OFF" -e "WITH_DOC=ON" paddle:dev /bin/bash
81+
82+
# Use build.sh to build PaddlePaddle documentation
83+
bash -x /paddle/paddle/scripts/docker/build.sh
84+
85+
Note: The above commands maps the current directory (source root directory) to the :code:`/paddle` directory in the container.
86+
87+
After compiling, there should be two generated directories: ``doc/v2`` and ``doc/fluid``, where three subdirectories ``cn/html/``, ``en/html`` and ``api/en/html`` are generated. Please enter these directories respectively and execute the following commands:
88+
89+
.. code-block:: bash
90+
91+
python -m SimpleHTTPServer 8088
92+
93+
Use a web browser and navigate to http://localhost:8000, you could see the compiled ``v2`` 's and ``fluid`` 's Chinese/English documents page and English APIs page.
7494

7595
If you do not wish to use Docker, you can also use the following commands to directly build the PaddlePaddle documentation.
7696

7797
.. code-block:: bash
7898
79-
mkdir paddle
80-
cd paddle
99+
81100
git clone https://github.com/PaddlePaddle/Paddle.git
101+
cd Paddle
82102
mkdir -p build
83103
cd build
84104
cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_GPU=OFF -DWITH_MKL=OFF -DWITH_DOC=ON
85105
86106
# If you only need to build documents, use the following commands
87-
make -j $processors gen_proto_py
88-
make -j $processors paddle_docs paddle_docs_cn
107+
make -j $processors paddle_docs
89108
90109
# If you only need to build APIs, use the following commands
91-
make -j $processors gen_proto_py framework_py_proto
92-
make -j $processors copy_paddle_pybind
93-
make -j $processors paddle_api_docs
110+
make -j $processors paddle_apis
94111
95112
$processors indicates that as many processes as the CPU cores are started to compile in parallel. It should be set according to the number of CPU cores of your machine.
96113

97-
After the compilation is complete, enter the ``doc/v2`` directory. If you chose to build documents, it will generate ``cn/html/`` and ``en/html`` subdirectories under this directory. If you chose to build APIs,it will generate``api/en/html`` subdirectory. Please enter these directories respectively and execute the following commands:
114+
After compiling, there also should be two generated directories: ``doc/v2`` and ``doc/fluid`` . If you chose to build documents, two subdirectories ``cn/html/`` and ``en/html`` will be generated in both two directories. If you chose to build APIs,a subdirectory ``api/en/html`` will be generated. Please enter these directories respectively and execute the following commands:
98115

99116
.. code-block:: bash
100117
101118
python -m SimpleHTTPServer 8088
102119
103-
Use a web browser and navigate to http://localhost:8000, you could see the compiled Chinese/English documents page and the English APIs page. The following figure is an example of the built English documents home page. Note that due to the sphinx's original theme used in the example, the style of the page is not consistent with the official website, but this does not affect the developer's debugging.
120+
Use a web browser and navigate to http://localhost:8000, you could see the compiled ``v2`` 's and ``fluid`` 's Chinese/English documents page and English APIs page. The following figure is an example of the built ``v2`` 's English documents home page. Note that due to the sphinx's original theme used in the example, the style of the page is not consistent with the official website, but this does not affect the developer's debugging.
104121

105122
.. image:: src/doc_en.png
106123
:align: center

paddle/fluid/framework/details/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cc_library(fetch_op_handle SRCS fetch_op_handle.cc DEPS op_handle_base scope lod
55
nv_library(nccl_all_reduce_op_handle SRCS nccl_all_reduce_op_handle.cc DEPS op_handle_base scope lod_tensor ddim memory
66
dynload_cuda)
77
cc_library(computation_op_handle SRCS computation_op_handle.cc DEPS framework_proto scope place operator op_registry)
8+
cc_library(send_op_handle SRCS send_op_handle.cc DEPS framework_proto scope place operator op_registry)
89

910
cc_library(ssa_graph SRCS ssa_graph.cc DEPS var_handle op_handle_base)
1011
cc_library(ssa_graph_builder SRCS ssa_graph_builder.cc DEPS ssa_graph)
@@ -15,7 +16,7 @@ else()
1516
set(multi_devices_graph_builder_deps)
1617
endif()
1718
cc_library(multi_devices_graph_builder SRCS multi_devices_graph_builder.cc DEPS ssa_graph_builder computation_op_handle
18-
scale_loss_grad_op_handle ${multi_devices_graph_builder_deps})
19+
scale_loss_grad_op_handle send_op_handle ${multi_devices_graph_builder_deps})
1920
cc_library(ssa_graph_executor SRCS ssa_graph_executor.cc DEPS ssa_graph framework_proto)
2021
cc_library(threaded_ssa_graph_executor SRCS threaded_ssa_graph_executor.cc DEPS fetch_op_handle ssa_graph_executor scope
2122
simple_threadpool device_context)

paddle/fluid/framework/details/multi_devices_graph_builder.cc

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "paddle/fluid/framework/details/multi_devices_graph_builder.h"
1616
#include "paddle/fluid/framework/details/computation_op_handle.h"
1717
#include "paddle/fluid/framework/details/scale_loss_grad_op_handle.h"
18+
#include "paddle/fluid/framework/details/send_op_handle.h"
1819
#include "paddle/fluid/framework/scope.h"
1920

2021
#ifdef PADDLE_WITH_CUDA
@@ -54,6 +55,27 @@ MultiDevSSAGraphBuilder::MultiDevSSAGraphBuilder(
5455
}
5556
}
5657

58+
void MultiDevSSAGraphBuilder::CreateOpHandleIOs(SSAGraph *result, OpDesc *op,
59+
const platform::Place &p,
60+
const size_t &i) const {
61+
auto *op_handle = result->ops_.back().get();
62+
op_handle->dev_ctxes_[p] = const_cast<platform::DeviceContext *>(
63+
platform::DeviceContextPool::Instance().Get(p));
64+
65+
auto var_names = op->InputArgumentNames();
66+
67+
for (auto &each_var_name : var_names) {
68+
VarHandle *var = CreateOrGetLatestVarHandle(result, each_var_name, p, i);
69+
op_handle->AddInput(var);
70+
}
71+
72+
var_names = op->OutputArgumentNames();
73+
74+
for (auto &each_var_name : var_names) {
75+
CreateOpOutput(result, op_handle, each_var_name, p, i);
76+
}
77+
}
78+
5779
std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
5880
const ProgramDesc &program) const {
5981
auto graph = new SSAGraph();
@@ -76,27 +98,28 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
7698
}
7799
}
78100

101+
// append send op if program is distributed trainer main program.
102+
// always use the first device
103+
if (!is_forwarding && op->Type() == "send") {
104+
auto &p = places_[0];
105+
auto *s = local_scopes_[0];
106+
// FIXME(wuyi): send op always copy from GPU 0
107+
result.ops_.emplace_back(new SendOpHandle(*op, s, p));
108+
// Create inputs for output on original place and no ssa output
109+
// is created for send op.
110+
CreateOpHandleIOs(&result, op, p, 0);
111+
continue;
112+
}
113+
79114
for (size_t i = 0; i < places_.size(); ++i) {
80115
auto &p = places_[i];
81116
auto *s = local_scopes_[i];
82117

83118
result.ops_.emplace_back(new ComputationOpHandle(*op, s, p));
84119
auto *op_handle = result.ops_.back().get();
85-
op_handle->dev_ctxes_[p] = const_cast<platform::DeviceContext *>(
86-
platform::DeviceContextPool::Instance().Get(p));
120+
CreateOpHandleIOs(&result, op, p, i);
87121

88-
auto var_names = op->InputArgumentNames();
89-
90-
for (auto &each_var_name : var_names) {
91-
VarHandle *var =
92-
CreateOrGetLatestVarHandle(&result, each_var_name, p, i);
93-
op_handle->AddInput(var);
94-
}
95-
var_names = op->OutputArgumentNames();
96-
97-
for (auto &each_var_name : var_names) {
98-
CreateOpOutput(&result, op_handle, each_var_name, p, i);
99-
}
122+
auto var_names = op->OutputArgumentNames();
100123

101124
if (is_forwarding) {
102125
if (var_names.size() == 1 && var_names[0] == loss_var_name_) {

paddle/fluid/framework/details/multi_devices_graph_builder.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#pragma once
1616

17+
#include <string>
18+
#include <vector>
19+
1720
#include "paddle/fluid/framework/details/ssa_graph_builder.h"
1821

1922
namespace paddle {
@@ -41,6 +44,10 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
4144

4245
std::unique_ptr<SSAGraph> Build(const ProgramDesc &program) const override;
4346

47+
private:
48+
void CreateOpHandleIOs(SSAGraph *result, OpDesc *op, const platform::Place &p,
49+
const size_t &i) const;
50+
4451
private:
4552
std::string loss_var_name_;
4653
const std::vector<platform::Place> &places_;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/fluid/framework/details/send_op_handle.h"
16+
17+
namespace paddle {
18+
namespace framework {
19+
namespace details {
20+
21+
SendOpHandle::SendOpHandle(const framework::OpDesc &op_desc,
22+
const Scope *local_scope,
23+
const platform::Place &place)
24+
: op_(framework::OpRegistry::CreateOp(op_desc)),
25+
local_scope_(local_scope),
26+
place_(place) {}
27+
28+
void SendOpHandle::RunImpl() {
29+
// Wait input done
30+
for (auto *in : inputs_) {
31+
auto &p = static_cast<VarHandle *>(in)->place_;
32+
if (in->DebugString() == "dummy") { // HACK
33+
continue;
34+
}
35+
in->generated_op_->Wait(dev_ctxes_[p]);
36+
}
37+
op_->Run(*local_scope_, place_);
38+
}
39+
40+
std::string SendOpHandle::Name() const { return "send"; }
41+
} // namespace details
42+
} // namespace framework
43+
} // namespace paddle

0 commit comments

Comments
 (0)