未验证 提交 61811e9d 编写于 作者: Y Yang Yang(Tony) 提交者: GitHub

fix parallel op test (#8249)

* Fix parallel.do with batch norm

* Change log level

* CopyShare AllPlaces

* disable nccl test

* bring back parallel_do test
上级 3647ed64
...@@ -248,17 +248,19 @@ class ParallelDoGradOp : public framework::OperatorBase { ...@@ -248,17 +248,19 @@ class ParallelDoGradOp : public framework::OperatorBase {
const std::vector<framework::Scope *> &sub_scopes, const std::vector<framework::Scope *> &sub_scopes,
const platform::PlaceList &places) const { const platform::PlaceList &places) const {
for (auto &s : Outputs(framework::GradVarName(kParameters))) { for (auto &s : Outputs(framework::GradVarName(kParameters))) {
VLOG(3) << "Accumulating " << s;
if (s == framework::kEmptyVarName) continue;
std::string tmp_name; std::string tmp_name;
auto *tmp = sub_scopes[0]->Var(&tmp_name); auto *tmp = sub_scopes[0]->Var(&tmp_name);
for (size_t i = 1; i < sub_scopes.size(); ++i) { for (size_t i = 1; i < sub_scopes.size(); ++i) {
CopyOrShare(*sub_scopes[i]->FindVar(s), places[0], tmp); CopyOrShare(*sub_scopes[i]->FindVar(s), places[0], tmp);
WaitOnPlace(places[0]); WaitOnPlaces(places);
auto sum_op = framework::OpRegistry::CreateOp( auto sum_op = framework::OpRegistry::CreateOp(
"sum", {{"X", {s, tmp_name}}}, {{"Out", {s}}}, "sum", {{"X", {s, tmp_name}}}, {{"Out", {s}}},
framework::AttributeMap{}); framework::AttributeMap{});
VLOG(3) << sum_op->DebugStringEx(sub_scopes[0]); VLOG(10) << sum_op->DebugStringEx(sub_scopes[0]);
sum_op->Run(*sub_scopes[0], places[0]); sum_op->Run(*sub_scopes[0], places[0]);
WaitOnPlace(places[0]); WaitOnPlace(places[0]);
} }
...@@ -334,16 +336,9 @@ class ParallelDoGradOpDescMaker : public framework::SingleGradOpDescMaker { ...@@ -334,16 +336,9 @@ class ParallelDoGradOpDescMaker : public framework::SingleGradOpDescMaker {
class ParallelDoGradOpShapeInference : public framework::InferShapeBase { class ParallelDoGradOpShapeInference : public framework::InferShapeBase {
public: public:
void operator()(framework::InferShapeContext *ctx) const override { void operator()(framework::InferShapeContext *ctx) const override {
std::vector<std::string> input{kParameters, kInputs};
std::vector<std::string> output{kOutputs};
PADDLE_ENFORCE(ctx->HasInputs(kParameters)); PADDLE_ENFORCE(ctx->HasInputs(kParameters));
PADDLE_ENFORCE(ctx->HasOutputs(framework::GradVarName(kParameters)));
PADDLE_ENFORCE(ctx->HasInputs(kInputs)); PADDLE_ENFORCE(ctx->HasInputs(kInputs));
PADDLE_ENFORCE(ctx->HasInputs(kOutputs));
for (auto &s : output) {
PADDLE_ENFORCE(ctx->HasInputs(s));
}
ctx->SetOutputsDim(framework::GradVarName(kParameters), ctx->SetOutputsDim(framework::GradVarName(kParameters),
ctx->GetInputsDim(kParameters)); ctx->GetInputsDim(kParameters));
...@@ -360,10 +355,14 @@ class ParallelDoGradOpShapeInference : public framework::InferShapeBase { ...@@ -360,10 +355,14 @@ class ParallelDoGradOpShapeInference : public framework::InferShapeBase {
ctx->SetDims({ig_name}, {i_dims[i]}); ctx->SetDims({ig_name}, {i_dims[i]});
} }
if (ctx->HasInputs(kParameters)) { auto p_dims = ctx->GetInputsDim(kParameters);
PADDLE_ENFORCE(ctx->HasOutputs(framework::GradVarName(kParameters))); auto pg_names = ctx->Outputs(framework::GradVarName(kParameters));
ctx->SetOutputsDim(framework::GradVarName(kParameters), for (size_t i = 0; i < pg_names.size(); ++i) {
ctx->GetInputsDim(kParameters)); auto &pg_name = pg_names[i];
if (pg_name == framework::kEmptyVarName) {
continue;
}
ctx->SetDims({pg_name}, {p_dims[i]});
} }
} }
}; };
......
...@@ -277,21 +277,20 @@ class ParallelDo(object): ...@@ -277,21 +277,20 @@ class ParallelDo(object):
parent_block = self.parent_block() parent_block = self.parent_block()
local_inputs = set() local_inputs = set()
params = list()
for op in current_block.ops:
for oname in op.output_names:
for out_var_name in op.output(oname):
local_inputs.add(out_var_name)
for var in self.inputs: for var in self.inputs:
local_inputs.add(var.name) local_inputs.add(var.name)
params = list()
for op in current_block.ops: for op in current_block.ops:
for iname in op.input_names: for iname in op.input_names:
for in_var_name in op.input(iname): for in_var_name in op.input(iname):
if in_var_name not in local_inputs: if in_var_name not in local_inputs:
params.append(in_var_name) params.append(in_var_name)
for oname in op.output_names:
for out_var_name in op.output(oname):
local_inputs.add(out_var_name)
params = list(set(params)) params = list(set(params))
return [parent_block.var(name) for name in params] return [parent_block.var(name) for name in params]
......
...@@ -67,6 +67,7 @@ def conv_net(img, label): ...@@ -67,6 +67,7 @@ def conv_net(img, label):
pool_size=2, pool_size=2,
pool_stride=2, pool_stride=2,
act="relu") act="relu")
conv_pool_1 = fluid.layers.batch_norm(conv_pool_1)
conv_pool_2 = fluid.nets.simple_img_conv_pool( conv_pool_2 = fluid.nets.simple_img_conv_pool(
input=conv_pool_1, input=conv_pool_1,
filter_size=5, filter_size=5,
......
...@@ -158,6 +158,4 @@ for use_cuda in (False, True): ...@@ -158,6 +158,4 @@ for use_cuda in (False, True):
inject_test_method(use_cuda, is_sparse, parallel) inject_test_method(use_cuda, is_sparse, parallel)
if __name__ == '__main__': if __name__ == '__main__':
# FIXME(tonyyang-svail):
# This test always fail on MultiGPU CI
unittest.main() unittest.main()
...@@ -198,7 +198,4 @@ class ParallelOpTestMultipleInput(BaseParallelForTest): ...@@ -198,7 +198,4 @@ class ParallelOpTestMultipleInput(BaseParallelForTest):
if __name__ == '__main__': if __name__ == '__main__':
# FIXME(tonyyang-svail):
# This test always fail on MultiGPU CI
exit(0)
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册